diff --git a/src/java/org/apache/commons/collections/BagUtils.java b/src/java/org/apache/commons/collections/BagUtils.java index 4642cbea8..a390e46df 100644 --- a/src/java/org/apache/commons/collections/BagUtils.java +++ b/src/java/org/apache/commons/collections/BagUtils.java @@ -140,6 +140,9 @@ public class BagUtils { * Each object is passed through the transformer as it is added to the * Bag. It is important not to use the original bag after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified bag will not be transformed. + * If you want that behaviour, see {@link TransformedBag#decorateTransform}. * * @param bag the bag to predicate, must not be null * @param transformer the transformer for the bag, must not be null @@ -231,6 +234,9 @@ public class BagUtils { * Each object is passed through the transformer as it is added to the * Bag. It is important not to use the original bag after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified bag will not be transformed. + * If you want that behaviour, see {@link TransformedSortedBag#decorateTransform}. * * @param bag the bag to predicate, must not be null * @param transformer the transformer for the bag, must not be null diff --git a/src/java/org/apache/commons/collections/BufferUtils.java b/src/java/org/apache/commons/collections/BufferUtils.java index eb8b157ff..4fab01709 100644 --- a/src/java/org/apache/commons/collections/BufferUtils.java +++ b/src/java/org/apache/commons/collections/BufferUtils.java @@ -188,6 +188,9 @@ public class BufferUtils { * Each object is passed through the transformer as it is added to the * Buffer. It is important not to use the original buffer after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified buffer will not be transformed. + * If you want that behaviour, see {@link TransformedBuffer#decorateTransform}. * * @param buffer the buffer to predicate, must not be null * @param transformer the transformer for the buffer, must not be null diff --git a/src/java/org/apache/commons/collections/CollectionUtils.java b/src/java/org/apache/commons/collections/CollectionUtils.java index efe88e679..7d9af5780 100644 --- a/src/java/org/apache/commons/collections/CollectionUtils.java +++ b/src/java/org/apache/commons/collections/CollectionUtils.java @@ -1201,6 +1201,9 @@ public class CollectionUtils { * 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. + *

+ * Existing entries in the specified collection will not be transformed. + * If you want that behaviour, see {@link TransformedCollection#decorateTransform}. * * @param collection the collection to predicate, must not be null * @param transformer the transformer for the collection, must not be null diff --git a/src/java/org/apache/commons/collections/ListUtils.java b/src/java/org/apache/commons/collections/ListUtils.java index e721600f9..8cfec1380 100644 --- a/src/java/org/apache/commons/collections/ListUtils.java +++ b/src/java/org/apache/commons/collections/ListUtils.java @@ -350,6 +350,9 @@ public class ListUtils { * Each object is passed through the transformer as it is added to the * List. It is important not to use the original list after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified list will not be transformed. + * If you want that behaviour, see {@link TransformedList#decorateTransform}. * * @param list the list to predicate, must not be null * @param transformer the transformer for the list, must not be null diff --git a/src/java/org/apache/commons/collections/SetUtils.java b/src/java/org/apache/commons/collections/SetUtils.java index 93a3e5bd5..5270321e7 100644 --- a/src/java/org/apache/commons/collections/SetUtils.java +++ b/src/java/org/apache/commons/collections/SetUtils.java @@ -212,6 +212,9 @@ public class SetUtils { * Each object is passed through the transformer as it is added to the * Set. It is important not to use the original set after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified set will not be transformed. + * If you want that behaviour, see {@link TransformedSet#decorateTransform}. * * @param set the set to transform, must not be null * @param transformer the transformer for the set, must not be null @@ -313,6 +316,9 @@ public class SetUtils { * Each object is passed through the transformer as it is added to the * Set. It is important not to use the original set after invoking this * method, as it is a backdoor for adding untransformed objects. + *

+ * Existing entries in the specified set will not be transformed. + * If you want that behaviour, see {@link TransformedSortedSet#decorateTransform}. * * @param set the set to transform, must not be null * @param transformer the transformer for the set, must not be null diff --git a/src/java/org/apache/commons/collections/bag/TransformedBag.java b/src/java/org/apache/commons/collections/bag/TransformedBag.java index b5600d826..962b8c1f1 100644 --- a/src/java/org/apache/commons/collections/bag/TransformedBag.java +++ b/src/java/org/apache/commons/collections/bag/TransformedBag.java @@ -17,6 +17,7 @@ package org.apache.commons.collections.bag; import java.util.Set; +import java.util.Collection; import org.apache.commons.collections.Bag; import org.apache.commons.collections.Transformer; @@ -49,6 +50,7 @@ public class TransformedBag *

* If there are any elements already in the bag being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param bag the bag to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -59,6 +61,32 @@ public class TransformedBag return new TransformedBag(bag, transformer); } + /** + * Factory method to create a transforming bag that will transform + * existing contents of the specified bag. + *

+ * If there are any elements already in the bag being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param bag the bag to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed Bag + * @throws IllegalArgumentException if bag or transformer is null + * @since Commons Collections 3.3 + */ + public static Bag decorateTransform(Bag bag, Transformer transformer) { + TransformedBag decorated = new TransformedBag(bag, transformer); + if (transformer != null && bag != null && bag.size() > 0) { + Object[] values = bag.toArray(); + bag.clear(); + for(int i=0; i * If there are any elements already in the bag being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param bag the bag to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -57,6 +58,32 @@ public class TransformedSortedBag return new TransformedSortedBag(bag, transformer); } + /** + * Factory method to create a transforming sorted bag that will transform + * existing contents of the specified sorted bag. + *

+ * If there are any elements already in the bag being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param bag the bag to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed SortedBag + * @throws IllegalArgumentException if bag or transformer is null + * @since Commons Collections 3.3 + */ + public static SortedBag decorateTransform(SortedBag bag, Transformer transformer) { + TransformedSortedBag decorated = new TransformedSortedBag(bag, transformer); + if (transformer != null && bag != null && bag.size() > 0) { + Object[] values = bag.toArray(); + bag.clear(); + for(int i=0; i * If there are any elements already in the buffer being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param buffer the buffer to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -55,6 +56,32 @@ public class TransformedBuffer extends TransformedCollection implements Buffer { return new TransformedBuffer(buffer, transformer); } + /** + * Factory method to create a transforming buffer that will transform + * existing contents of the specified buffer. + *

+ * If there are any elements already in the buffer being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param buffer the buffer to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed Buffer + * @throws IllegalArgumentException if buffer or transformer is null + * @since Commons Collections 3.3 + */ + public static Buffer decorateTransform(Buffer buffer, Transformer transformer) { + TransformedBuffer decorated = new TransformedBuffer(buffer, transformer); + if (transformer != null && buffer != null && buffer.size() > 0) { + Object[] values = buffer.toArray(); + buffer.clear(); + for(int i=0; i * If there are any elements already in the collection being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param coll the collection to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -61,6 +62,32 @@ public class TransformedCollection extends AbstractSerializableCollectionDecorat return new TransformedCollection(coll, transformer); } + /** + * Factory method to create a transforming collection that will transform + * existing contents of the specified collection. + *

+ * If there are any elements already in the collection being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param collection 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 + * @since Commons Collections 3.3 + */ + public static Collection decorateTransform(Collection collection, Transformer transformer) { + TransformedCollection decorated = new TransformedCollection(collection, transformer); + if (transformer != null && collection != null && collection.size() > 0) { + Object[] values = collection.toArray(); + collection.clear(); + for(int i=0; i * If there are any elements already in the list being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param list the list to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -58,6 +59,32 @@ public class TransformedList extends TransformedCollection implements List { return new TransformedList(list, transformer); } + /** + * Factory method to create a transforming list that will transform + * existing contents of the specified list. + *

+ * If there are any elements already in the list being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param list the list to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed List + * @throws IllegalArgumentException if list or transformer is null + * @since Commons Collections 3.3 + */ + public static List decorateTransform(List list, Transformer transformer) { + TransformedList decorated = new TransformedList(list, transformer); + if (transformer != null && list != null && list.size() > 0) { + Object[] values = list.toArray(); + list.clear(); + for(int i=0; i * If there are any elements already in the set being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param set the set to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -55,6 +56,32 @@ public class TransformedSet extends TransformedCollection implements Set { return new TransformedSet(set, transformer); } + /** + * Factory method to create a transforming set that will transform + * existing contents of the specified set. + *

+ * If there are any elements already in the set being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param set the set to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed Set + * @throws IllegalArgumentException if set or transformer is null + * @since Commons Collections 3.3 + */ + public static Set decorateTransform(Set set, Transformer transformer) { + TransformedSet decorated = new TransformedSet(set, transformer); + if (transformer != null && set != null && set.size() > 0) { + Object[] values = set.toArray(); + set.clear(); + for(int i=0; i * If there are any elements already in the set being decorated, they * are NOT transformed. + * Constrast this with {@link #decorateTransform}. * * @param set the set to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -55,6 +56,32 @@ public class TransformedSortedSet extends TransformedSet implements SortedSet { return new TransformedSortedSet(set, transformer); } + /** + * Factory method to create a transforming sorted set that will transform + * existing contents of the specified sorted set. + *

+ * If there are any elements already in the set being decorated, they + * will be transformed by this method. + * Constrast this with {@link #decorate}. + * + * @param set the set to decorate, must not be null + * @param transformer the transformer to use for conversion, must not be null + * @return a new transformed SortedSet + * @throws IllegalArgumentException if set or transformer is null + * @since Commons Collections 3.3 + */ + public static SortedSet decorateTransform(SortedSet set, Transformer transformer) { + TransformedSortedSet decorated = new TransformedSortedSet(set, transformer); + if (transformer != null && set != null && set.size() > 0) { + Object[] values = set.toArray(); + set.clear(); + for(int i=0; i