Package org.apache.sis.internal.util
Class Bag<E>
java.lang.Object
java.util.AbstractCollection<E>
org.apache.sis.internal.util.Bag<E>
- Type Parameters:
E- type of elements in this bag.
- All Implemented Interfaces:
Iterable<E>,Collection<E>
A collection in which elements order does not matter (as in
Set)
but in which duplicated elements are allowed (as in List).
The "bag" word is used in ISO specifications for such kind of collection.
This base class is suitable to collection returned by Map.values();
it is not necessarily a good fit for all other subtypes of AbstractCollection.
This abstract class implements the equals(Object) and hashCode() methods.
Subclasses need to override at least AbstractCollection.size() and AbstractCollection.iterator().
- Since:
- 1.0
- Version:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream
-
Constructor Details
-
Bag
protected Bag()Creates a new instance.
-
-
Method Details
-
equals
Compares this bag with the given object for equality. This method performs comparisons only with instances ofBag, and returnsfalsefor all other kinds of collection. We do not compare with arbitrary collection implementations.Rational:
Collection.equals(Object)contract explicitly forbids comparisons withListandSet. The rational explained inCollectionjavadoc applies also to other kind ofCollectionimplementations: we cannot enforceCollection.equals(Object)to be symmetric in such cases.- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject- Parameters:
other- the other object to compare with this bag.- Returns:
trueif the two bags are equal.
-
hashCode
public int hashCode()Returns a hash code value for this bag, ignoring element order. This method computes hash code in the same way thanSet.- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject- Returns:
- a hash code value.
-