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>

public abstract class Bag<E> extends AbstractCollection<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 Details

    • Bag

      protected Bag()
      Creates a new instance.
  • Method Details

    • equals

      public boolean equals(Object other)
      Compares this bag with the given object for equality. This method performs comparisons only with instances of Bag, and returns false for all other kinds of collection. We do not compare with arbitrary collection implementations.

      Rational: Collection.equals(Object) contract explicitly forbids comparisons with List and Set. The rational explained in Collection javadoc applies also to other kind of Collection implementations: we cannot enforce Collection.equals(Object) to be symmetric in such cases.

      Specified by:
      equals in interface Collection<E>
      Overrides:
      equals in class Object
      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 than Set.
      Specified by:
      hashCode in interface Collection<E>
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value.