/** * Returns a transformed bag backed by the given collection. * <p> * Each object is passed through the transformer as it is added to the * Collection. It is important not to use the original collection after invoking this * method, as it is a backdoor for adding untransformed objects. * * @param collection the collection to predicate, must not be null * @param transformer the transformer for the collection, must not be null * @return a transformed collection backed by the given collection * @throws IllegalArgumentException if the Collection or Transformer is null */ public static Collection transformedCollection(Collection collection, Transformer transformer) { return TransformedCollection.decorate(collection, transformer); }
/** * Factory method to create a transforming collection. * <p> * If there are any elements already in the collection being decorated, they * are NOT transformed. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ public static Collection decorate(Collection coll, Transformer transformer) { return new TransformedCollection(coll, transformer); }
public boolean addAll(Collection coll) { coll = transform(coll); return getCollection().addAll(coll); }
/** * Transforms a collection. * <p> * The transformer itself may throw an exception if necessary. * * @param coll the collection to transform * @return a transformed object */ protected Collection transform(Collection coll) { List list = new ArrayList(coll.size()); for (Iterator it = coll.iterator(); it.hasNext(); ) { list.add(transform(it.next())); } return list; }
/** * Transforms a collection. * <p> * The transformer itself may throw an exception if necessary. * * @param coll the collection to transform * @return a transformed object */ protected Collection transform(Collection coll) { List list = new ArrayList(coll.size()); for (Iterator it = coll.iterator(); it.hasNext(); ) { list.add(transform(it.next())); } return list; }
public boolean add(Object object) { object = transform(object); return getCollection().add(object); }
/** * Returns a transformed bag backed by the given collection. * <p> * Each object is passed through the transformer as it is added to the * Collection. It is important not to use the original collection after invoking this * method, as it is a backdoor for adding untransformed objects. * * @param collection the collection to predicate, must not be null * @param transformer the transformer for the collection, must not be null * @return a transformed collection backed by the given collection * @throws IllegalArgumentException if the Collection or Transformer is null */ public static Collection transformedCollection(Collection collection, Transformer transformer) { return TransformedCollection.decorate(collection, transformer); }
/** * Factory method to create a transforming collection. * <p> * If there are any elements already in the collection being decorated, they * are NOT transformed. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ public static Collection decorate(Collection coll, Transformer transformer) { return new TransformedCollection(coll, transformer); }
/** * Transforms a collection. * <p> * The transformer itself may throw an exception if necessary. * * @param coll the collection to transform * @return a transformed object */ protected Collection transform(Collection coll) { List list = new ArrayList(coll.size()); for (Iterator it = coll.iterator(); it.hasNext(); ) { list.add(transform(it.next())); } return list; }
public boolean add(Object object) { object = transform(object); return getCollection().add(object); }
public Collection makeCollection() { return TransformedCollection.decorate(new ArrayList(), NOOP_TRANSFORMER); }
/** * Factory method to create a transforming collection. * <p> * If there are any elements already in the collection being decorated, they * are NOT transformed. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ public static Collection decorate(Collection coll, Transformer transformer) { return new TransformedCollection(coll, transformer); }
/** * Transforms a collection. * <p> * The transformer itself may throw an exception if necessary. * * @param coll the collection to transform * @return a transformed object */ protected Collection transform(Collection coll) { List list = new ArrayList(coll.size()); for (Iterator it = coll.iterator(); it.hasNext(); ) { list.add(transform(it.next())); } return list; }
public boolean addAll(Collection coll) { coll = transform(coll); return getCollection().addAll(coll); }
public Collection makeFullCollection() { List list = new ArrayList(); list.addAll(Arrays.asList(getFullElements())); return TransformedCollection.decorate(list, NOOP_TRANSFORMER); }
/** * Factory method to create a transforming collection. * <p> * If there are any elements already in the collection being decorated, they * are NOT transformed. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ public static Collection decorate(Collection coll, Transformer transformer) { return new TransformedCollection(coll, transformer); }
/** * Transforms a collection. * <p> * The transformer itself may throw an exception if necessary. * * @param coll the collection to transform * @return a transformed object */ protected Collection transform(Collection coll) { List list = new ArrayList(coll.size()); for (Iterator it = coll.iterator(); it.hasNext(); ) { list.add(transform(it.next())); } return list; }
public boolean add(Object object) { object = transform(object); return getCollection().add(object); }
public void testTransformedCollection() { Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, coll.size()); Object[] els = getFullElements(); for (int i = 0; i < els.length; i++) { coll.add(els[i]); assertEquals(i + 1, coll.size()); assertEquals(true, coll.contains(new Integer((String) els[i]))); assertEquals(false, coll.contains(els[i])); } assertEquals(true, coll.remove(new Integer((String) els[0]))); }
/** * Factory method to create a transforming collection. * <p> * If there are any elements already in the collection being decorated, they * are NOT transformed. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ public static Collection decorate(Collection coll, Transformer transformer) { return new TransformedCollection(coll, transformer); }