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, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
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 returnsfalse
for all other kinds of collection. We do not compare with arbitrary collection implementations.Rational:
Collection.equals(Object)
contract explicitly forbids comparisons withList
andSet
. The rational explained inCollection
javadoc applies also to other kind ofCollection
implementations: we cannot enforceCollection.equals(Object)
to be symmetric in such cases.- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
- Parameters:
other
- the other object to compare with this bag.- Returns:
true
if 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:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
- Returns:
- a hash code value.
-