From c2d22264b029c47fb14d39cc9c4c397401e304d1 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Sat, 23 Jun 2012 15:35:49 +0000 Subject: [PATCH] [COLLECTIONS-231] return specific type rather than base type in factory methods, javadoc cleanup. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1353148 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/bag/AbstractBagDecorator.java | 15 +++++++++- .../collections/bag/AbstractMapBag.java | 2 +- .../bag/AbstractSortedBagDecorator.java | 2 +- .../commons/collections/bag/HashBag.java | 2 +- .../collections/bag/PredicatedBag.java | 28 +++++++++++++----- .../collections/bag/PredicatedSortedBag.java | 28 ++++++++++++------ .../collections/bag/SynchronizedBag.java | 22 +++++++++++--- .../bag/SynchronizedSortedBag.java | 17 +++++++++-- .../collections/bag/TransformedBag.java | 27 +++++++++++++---- .../collections/bag/TransformedSortedBag.java | 29 ++++++++++++++----- .../collections/bag/UnmodifiableBag.java | 7 +++-- .../bag/UnmodifiableSortedBag.java | 7 +++-- 12 files changed, 139 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/apache/commons/collections/bag/AbstractBagDecorator.java b/src/main/java/org/apache/commons/collections/bag/AbstractBagDecorator.java index ea3d57232..eaff36921 100644 --- a/src/main/java/org/apache/commons/collections/bag/AbstractBagDecorator.java +++ b/src/main/java/org/apache/commons/collections/bag/AbstractBagDecorator.java @@ -24,7 +24,7 @@ import org.apache.commons.collections.collection.AbstractCollectionDecorator; /** * Decorates another Bag to provide additional behaviour. *

- * Methods are forwarded directly to the decorated bag. + * Methods are forwarded directly to the decorated bag.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -66,18 +66,31 @@ public abstract class AbstractBagDecorator } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public int getCount(Object object) { return decorated().getCount(object); } + /** + * {@inheritDoc} + */ public boolean add(E object, int count) { return decorated().add(object, count); } + /** + * {@inheritDoc} + */ public boolean remove(Object object, int count) { return decorated().remove(object, count); } + /** + * {@inheritDoc} + */ public Set uniqueSet() { return decorated().uniqueSet(); } diff --git a/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java b/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java index c81a279c9..12460728f 100644 --- a/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java +++ b/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java @@ -35,7 +35,7 @@ import org.apache.commons.collections.set.UnmodifiableSet; *

* Subclasses specify a Map implementation to use as the internal storage. The * map will be used to map bag elements to a number; the number represents the - * number of occurrences of that element in the bag. + * number of occurrences of that element in the bag.

* * @since Commons Collections 3.0 (previously DefaultMapBag v2.0) * @version $Revision$ diff --git a/src/main/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java b/src/main/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java index b3ac08a05..1abb55985 100644 --- a/src/main/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java +++ b/src/main/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java @@ -23,7 +23,7 @@ import org.apache.commons.collections.SortedBag; /** * Decorates another SortedBag to provide additional behaviour. *

- * Methods are forwarded directly to the decorated bag. + * Methods are forwarded directly to the decorated bag.

* * @since Commons Collections 3.0 * @version $Revision$ diff --git a/src/main/java/org/apache/commons/collections/bag/HashBag.java b/src/main/java/org/apache/commons/collections/bag/HashBag.java index c5214f8d3..7caa435ed 100644 --- a/src/main/java/org/apache/commons/collections/bag/HashBag.java +++ b/src/main/java/org/apache/commons/collections/bag/HashBag.java @@ -33,7 +33,7 @@ import org.apache.commons.collections.Bag; * count of occurrences. Extra methods on the interface allow multiple copies * of an object to be added or removed at once. It is important to read the * interface javadoc carefully as several methods violate the - * Collection interface specification. + * Collection interface specification.

* * @since Commons Collections 3.0 (previously in main package v2.0) * @version $Revision$ diff --git a/src/main/java/org/apache/commons/collections/bag/PredicatedBag.java b/src/main/java/org/apache/commons/collections/bag/PredicatedBag.java index 4c7aaa356..a1c92f3ee 100644 --- a/src/main/java/org/apache/commons/collections/bag/PredicatedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/PredicatedBag.java @@ -28,12 +28,12 @@ import org.apache.commons.collections.collection.PredicatedCollection; *

* This bag exists to provide validation for the decorated bag. * It is normally created to decorate an empty bag. - * If an object cannot be added to the bag, an IllegalArgumentException is thrown. + * If an object cannot be added to the bag, an IllegalArgumentException is thrown.

*

* One usage would be to ensure that no null entries are added to the bag. - *

Bag bag = PredicatedBag.decorate(new HashBag(), NotNullPredicate.INSTANCE);
+ *
Bag bag = PredicatedBag.decorate(new HashBag(), NotNullPredicate.INSTANCE);

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -51,16 +51,17 @@ public class PredicatedBag * Factory method to create a predicated (validating) bag. *

* If there are any elements already in the bag being decorated, they - * are validated. + * are validated.

* + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @return a new predicated Bag * @throws IllegalArgumentException if bag or predicate is null * @throws IllegalArgumentException if the bag contains invalid elements */ - public static Bag predicatedBag(Bag bag, Predicate predicate) { - return new PredicatedBag(bag, predicate); + public static PredicatedBag predicatedBag(Bag bag, Predicate predicate) { + return new PredicatedBag(bag, predicate); } //----------------------------------------------------------------------- @@ -68,7 +69,7 @@ public class PredicatedBag * Constructor that wraps (not copies). *

* If there are any elements already in the bag being decorated, they - * are validated. + * are validated.

* * @param bag the bag to decorate, must not be null * @param predicate the predicate to use for validation, must not be null @@ -90,19 +91,32 @@ public class PredicatedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public boolean add(E object, int count) { validate(object); return decorated().add(object, count); } + /** + * {@inheritDoc} + */ public boolean remove(Object object, int count) { return decorated().remove(object, count); } + /** + * {@inheritDoc} + */ public Set uniqueSet() { return decorated().uniqueSet(); } + /** + * {@inheritDoc} + */ public int getCount(Object object) { return decorated().getCount(object); } diff --git a/src/main/java/org/apache/commons/collections/bag/PredicatedSortedBag.java b/src/main/java/org/apache/commons/collections/bag/PredicatedSortedBag.java index 3a5de3112..834d7a272 100644 --- a/src/main/java/org/apache/commons/collections/bag/PredicatedSortedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/PredicatedSortedBag.java @@ -27,12 +27,12 @@ import org.apache.commons.collections.SortedBag; *

* This bag exists to provide validation for the decorated bag. * It is normally created to decorate an empty bag. - * If an object cannot be added to the bag, an IllegalArgumentException is thrown. + * If an object cannot be added to the bag, an IllegalArgumentException is thrown.

*

* One usage would be to ensure that no null entries are added to the bag. - *

SortedBag bag = PredicatedSortedBag.decorate(new TreeBag(), NotNullPredicate.INSTANCE);
+ *
SortedBag bag = PredicatedSortedBag.decorate(new TreeBag(), NotNullPredicate.INSTANCE);

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -50,24 +50,24 @@ public class PredicatedSortedBag * Factory method to create a predicated (validating) bag. *

* If there are any elements already in the bag being decorated, they - * are validated. + * are validated.

* + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @return a new predicated SortedBag * @throws IllegalArgumentException if bag or predicate is null * @throws IllegalArgumentException if the bag contains invalid elements */ - public static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate) { - return new PredicatedSortedBag(bag, predicate); + public static PredicatedSortedBag predicatedSortedBag(SortedBag bag, Predicate predicate) { + return new PredicatedSortedBag(bag, predicate); } //----------------------------------------------------------------------- /** * Constructor that wraps (not copies). - *

- * If there are any elements already in the bag being decorated, they - * are validated. + *

If there are any elements already in the bag being decorated, they + * are validated.

* * @param bag the bag to decorate, must not be null * @param predicate the predicate to use for validation, must not be null @@ -89,14 +89,24 @@ public class PredicatedSortedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public E first() { return decorated().first(); } + /** + * {@inheritDoc} + */ public E last() { return decorated().last(); } + /** + * {@inheritDoc} + */ public Comparator comparator() { return decorated().comparator(); } diff --git a/src/main/java/org/apache/commons/collections/bag/SynchronizedBag.java b/src/main/java/org/apache/commons/collections/bag/SynchronizedBag.java index 424bf2db0..a79b03a6e 100644 --- a/src/main/java/org/apache/commons/collections/bag/SynchronizedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/SynchronizedBag.java @@ -27,9 +27,9 @@ import org.apache.commons.collections.set.SynchronizedSet; * for a multi-threaded environment. *

* Methods are synchronized, then forwarded to the decorated bag. - * Iterators must be separately synchronized around the loop. + * Iterators must be separately synchronized around the loop.

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -45,12 +45,13 @@ public class SynchronizedBag /** * Factory method to create a synchronized bag. * + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @return a new synchronized Bag * @throws IllegalArgumentException if bag is null */ - public static Bag synchronizedBag(Bag bag) { - return new SynchronizedBag(bag); + public static SynchronizedBag synchronizedBag(Bag bag) { + return new SynchronizedBag(bag); } //----------------------------------------------------------------------- @@ -85,18 +86,28 @@ public class SynchronizedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public boolean add(E object, int count) { synchronized (lock) { return getBag().add(object, count); } } + /** + * {@inheritDoc} + */ public boolean remove(Object object, int count) { synchronized (lock) { return getBag().remove(object, count); } } + /** + * {@inheritDoc} + */ public Set uniqueSet() { synchronized (lock) { Set set = getBag().uniqueSet(); @@ -104,6 +115,9 @@ public class SynchronizedBag } } + /** + * {@inheritDoc} + */ public int getCount(Object object) { synchronized (lock) { return getBag().getCount(object); diff --git a/src/main/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java b/src/main/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java index 803ca7e79..4d7a508ba 100644 --- a/src/main/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java @@ -26,9 +26,9 @@ import org.apache.commons.collections.SortedBag; * for a multi-threaded environment. *

* Methods are synchronized, then forwarded to the decorated bag. - * Iterators must be separately synchronized around the loop. + * Iterators must be separately synchronized around the loop.

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -44,11 +44,12 @@ public class SynchronizedSortedBag /** * Factory method to create a synchronized sorted bag. * + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @return a new synchronized SortedBag * @throws IllegalArgumentException if bag is null */ - public static SortedBag synchronizedSortedBag(SortedBag bag) { + public static SynchronizedSortedBag synchronizedSortedBag(SortedBag bag) { return new SynchronizedSortedBag(bag); } @@ -84,18 +85,28 @@ public class SynchronizedSortedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public synchronized E first() { synchronized (lock) { return getSortedBag().first(); } } + /** + * {@inheritDoc} + */ public synchronized E last() { synchronized (lock) { return getSortedBag().last(); } } + /** + * {@inheritDoc} + */ public synchronized Comparator comparator() { synchronized (lock) { return getSortedBag().comparator(); diff --git a/src/main/java/org/apache/commons/collections/bag/TransformedBag.java b/src/main/java/org/apache/commons/collections/bag/TransformedBag.java index 5415ba569..b70cde3f4 100644 --- a/src/main/java/org/apache/commons/collections/bag/TransformedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/TransformedBag.java @@ -29,9 +29,9 @@ import org.apache.commons.collections.set.TransformedSet; * The add methods are affected by this class. * Thus objects must be removed or searched for using their transformed form. * For example, if the transformation converts Strings to Integers, you must - * use the Integer form to remove objects. + * use the Integer form to remove objects.

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -48,9 +48,9 @@ public class TransformedBag * Factory method to create a transforming bag. *

* If there are any elements already in the bag being decorated, they - * are NOT transformed. - * Contrast this with {@link #transformedBag(Bag, Transformer)}. + * are NOT transformed. Contrast this with {@link #transformedBag(Bag, Transformer)}.

* + * @param the type of the elements in the bag * @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 @@ -66,8 +66,9 @@ public class TransformedBag *

* If there are any elements already in the bag being decorated, they * will be transformed by this method. - * Contrast this with {@link #transformingBag(Bag, Transformer)}. + * Contrast this with {@link #transformingBag(Bag, Transformer)}.

* + * @param the type of the elements in the bag * @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 @@ -92,7 +93,7 @@ public class TransformedBag * Constructor that wraps (not copies). *

* If there are any elements already in the bag being decorated, they - * are NOT transformed. + * are NOT transformed.

* * @param bag the bag to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -112,19 +113,33 @@ public class TransformedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public int getCount(Object object) { return getBag().getCount(object); } + /** + * {@inheritDoc} + */ public boolean remove(Object object, int nCopies) { return getBag().remove(object, nCopies); } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public boolean add(E object, int nCopies) { return getBag().add(transform(object), nCopies); } + /** + * {@inheritDoc} + */ public Set uniqueSet() { Set set = getBag().uniqueSet(); return TransformedSet.transformingSet(set, transformer); diff --git a/src/main/java/org/apache/commons/collections/bag/TransformedSortedBag.java b/src/main/java/org/apache/commons/collections/bag/TransformedSortedBag.java index 598b31a68..ae6750784 100644 --- a/src/main/java/org/apache/commons/collections/bag/TransformedSortedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/TransformedSortedBag.java @@ -27,9 +27,9 @@ import org.apache.commons.collections.Transformer; * The add methods are affected by this class. * Thus objects must be removed or searched for using their transformed form. * For example, if the transformation converts Strings to Integers, you must - * use the Integer form to remove objects. + * use the Integer form to remove objects.

*

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -46,15 +46,16 @@ public class TransformedSortedBag * Factory method to create a transforming sorted bag. *

* If there are any elements already in the bag being decorated, they - * are NOT transformed. - * Contrast this with {@link #transformedSortedBag(SortedBag, Transformer)}. + * are NOT transformed. Contrast this with {@link #transformedSortedBag(SortedBag, Transformer)}.

* + * @param the type of the elements in the bag * @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 */ - public static SortedBag transformingSortedBag(SortedBag bag, Transformer transformer) { + public static TransformedSortedBag transformingSortedBag(SortedBag bag, + Transformer transformer) { return new TransformedSortedBag(bag, transformer); } @@ -64,15 +65,17 @@ public class TransformedSortedBag *

* If there are any elements already in the bag being decorated, they * will be transformed by this method. - * Contrast this with {@link #transformingSortedBag(SortedBag, Transformer)}. + * Contrast this with {@link #transformingSortedBag(SortedBag, Transformer)}.

* + * @param the type of the elements in the bag * @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 transformedSortedBag(SortedBag bag, Transformer transformer) { + public static TransformedSortedBag transformedSortedBag(SortedBag bag, + Transformer transformer) { TransformedSortedBag decorated = new TransformedSortedBag(bag, transformer); if (transformer != null && bag != null && bag.size() > 0) { @SuppressWarnings("unchecked") // bag is type E @@ -90,7 +93,7 @@ public class TransformedSortedBag * Constructor that wraps (not copies). *

* If there are any elements already in the bag being decorated, they - * are NOT transformed. + * are NOT transformed.

* * @param bag the bag to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null @@ -110,14 +113,24 @@ public class TransformedSortedBag } //----------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ public E first() { return getSortedBag().first(); } + /** + * {@inheritDoc} + */ public E last() { return getSortedBag().last(); } + /** + * {@inheritDoc} + */ public Comparator comparator() { return getSortedBag().comparator(); } diff --git a/src/main/java/org/apache/commons/collections/bag/UnmodifiableBag.java b/src/main/java/org/apache/commons/collections/bag/UnmodifiableBag.java index c63bbd3f5..4fa5403b4 100644 --- a/src/main/java/org/apache/commons/collections/bag/UnmodifiableBag.java +++ b/src/main/java/org/apache/commons/collections/bag/UnmodifiableBag.java @@ -32,9 +32,9 @@ import org.apache.commons.collections.set.UnmodifiableSet; /** * Decorates another Bag to ensure it can't be altered. *

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

*

- * Attempts to modify it will result in an UnsupportedOperationException. + * Attempts to modify it will result in an UnsupportedOperationException.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -50,8 +50,9 @@ public final class UnmodifiableBag /** * Factory method to create an unmodifiable bag. *

- * If the bag passed in is already unmodifiable, it is returned. + * If the bag passed in is already unmodifiable, it is returned.

* + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @return an unmodifiable Bag * @throws IllegalArgumentException if bag is null diff --git a/src/main/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java b/src/main/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java index 44878a144..5d6d64197 100644 --- a/src/main/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java @@ -32,9 +32,9 @@ import org.apache.commons.collections.set.UnmodifiableSet; /** * Decorates another SortedBag to ensure it can't be altered. *

- * This class is Serializable from Commons Collections 3.1. + * This class is Serializable from Commons Collections 3.1.

*

- * Attempts to modify it will result in an UnsupportedOperationException. + * Attempts to modify it will result in an UnsupportedOperationException.

* * @since Commons Collections 3.0 * @version $Revision$ @@ -50,8 +50,9 @@ public final class UnmodifiableSortedBag /** * Factory method to create an unmodifiable bag. *

- * If the bag passed in is already unmodifiable, it is returned. + * If the bag passed in is already unmodifiable, it is returned.

* + * @param the type of the elements in the bag * @param bag the bag to decorate, must not be null * @return an unmodifiable SortedBag * @throws IllegalArgumentException if bag is null