commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Egge (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-243) Generic versions of Predicated, Syncronized and Unmodifiable classes
Date Tue, 30 Oct 2007 11:36:50 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12538740
] 

Brian Egge commented on COLLECTIONS-243:
----------------------------------------

The Transformer<I, O> interface makes since as a single item.  I can create a transformer
to convert Strings to Integers.  These have nothing in common, and the Transformer<String,
Integer> seems to make sense.  Where this doesn't seem to work so great is when you have
a chain, or a collection of transformers.  

If you want to go from Double to String to BigDecimal, you could do this with two transformers.
 However, a class which contains a list of Transformer<I, O>, expecting the output of
one to feed into the input of the next will not work, with anything but <Object, Object>.

So, WRT ChainedTransformer, I'd be happy to leave it ungenerified.

Another problem with Transformer I ran into is with classes like TransformedBag.  This class
implements Bag, and you must specify if the Bag is to add <I> or <O> types.  Perhaps,
it's best not to specify either.  With the TransformedBag, you want you getters to return
the <O> type, but your adders to use the <I> type.  This breaks the Bag interface,
if you try to specify a type for the Bag.  It probably simply shouldn't try to specify a type
for a Bag.  If you have a Bag<String>, then you expect to add & remove Strings.
 With a transformed Bag, you can add one type and get another type out - clearly defeating
what you are trying to achieve with type safe generics.



> Generic versions of Predicated, Syncronized and Unmodifiable classes
> --------------------------------------------------------------------
>
>                 Key: COLLECTIONS-243
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-243
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Bag, Collection, List, Set
>    Affects Versions: Generics
>         Environment: OS X
>            Reporter: Edwin Tellman
>            Priority: Minor
>             Fix For: Generics
>
>         Attachments: collections_06_03_11.patch
>
>
> I added generics to some more classes and fixed some compilation problems.
> The generic version of Transformer required the input and output types to be identical.
 This seemed to me to reduce the usefulness of transformed collections, as transforming one
type into another seems like it would be a fairly common operation.  I'm not sure how to fix
this, however, as it also doesn't seem feasible to have a generic TransformedCollection with
different input and output types that implements Collection<E>.  Anyway, this patch
de-generifies TransformedCollection, which also fixes some compilation problems.  Please disregard
this change if you disagree and have a better solution.
> The modified collection classes are:
> Bags: PredicatedSortedBag, AbstractBagDecorator, SynchronizedBag, UnmodifiableSortedBag,
SynchronizedSortedBag, PredicatedBag
> Lists: PredicatedList, SynchronizedList
> Sets: PredicatedSortedSet, SynchronizedSortedSet, PredicatedSet, UnmodifiableSortedSet,
SynchronizedSet
> Miscellaneous: PredicatedBuffer

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message