Class UnmodifiableSortedBag

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable, java.util.Collection, Bag, SortedBag, Unmodifiable

    @Deprecated(since="2021-04-30")
    public final class UnmodifiableSortedBag
    extends AbstractSortedBagDecorator
    implements Unmodifiable, java.io.Serializable
    Deprecated.
    Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.
    Decorates another SortedBag to ensure it can't be altered.

    This class is Serializable from Commons Collections 3.1.

    Since:
    Commons Collections 3.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object object)
      Deprecated.
      (Violation) Adds one copy the specified object to the Bag.
      boolean add​(java.lang.Object object, int count)
      Deprecated.
      Adds nCopies copies of the specified object to the Bag.
      boolean addAll​(java.util.Collection coll)
      Deprecated.
       
      void clear()
      Deprecated.
       
      static SortedBag decorate​(SortedBag bag)
      Deprecated.
      Factory method to create an unmodifiable bag.
      java.util.Iterator iterator()
      Deprecated.
      Returns an Iterator over the entire set of members, including copies due to cardinality.
      boolean remove​(java.lang.Object object)
      Deprecated.
      (Violation) Removes all occurrences of the given object from the bag.
      boolean remove​(java.lang.Object object, int count)
      Deprecated.
      Removes nCopies copies of the specified object from the Bag.
      boolean removeAll​(java.util.Collection coll)
      Deprecated.
      (Violation) Remove all elements represented in the given collection, respecting cardinality.
      boolean retainAll​(java.util.Collection coll)
      Deprecated.
      (Violation) Remove any members of the bag that are not in the given collection, respecting cardinality.
      java.util.Set uniqueSet()
      Deprecated.
      Returns a Set of unique elements in the Bag.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        contains, equals, hashCode, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Method Detail

      • decorate

        public static SortedBag decorate​(SortedBag bag)
        Deprecated.
        Factory method to create an unmodifiable bag.

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

        Parameters:
        bag - the bag to decorate, must not be null
        Returns:
        an unmodifiable SortedBag
        Throws:
        java.lang.IllegalArgumentException - if bag is null
      • iterator

        public java.util.Iterator iterator()
        Deprecated.
        Description copied from interface: Bag
        Returns an Iterator over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.
        Specified by:
        iterator in interface Bag
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Overrides:
        iterator in class AbstractCollectionDecorator
        Returns:
        iterator over all elements in the Bag
      • add

        public boolean add​(java.lang.Object object)
        Deprecated.
        Description copied from interface: Bag
        (Violation) Adds one copy the specified object to the Bag.

        If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object). Otherwise add it to the Bag.uniqueSet() and report its count as 1.

        Since this method always increases the size of the bag, according to the Collection.add(Object) contract, it should always return true. Since it sometimes returns false, this method violates the contract.

        Specified by:
        add in interface Bag
        Specified by:
        add in interface java.util.Collection
        Overrides:
        add in class AbstractCollectionDecorator
        Parameters:
        object - the object to add
        Returns:
        true if the object was not already in the uniqueSet
      • addAll

        public boolean addAll​(java.util.Collection coll)
        Deprecated.
        Specified by:
        addAll in interface java.util.Collection
        Overrides:
        addAll in class AbstractCollectionDecorator
      • remove

        public boolean remove​(java.lang.Object object)
        Deprecated.
        Description copied from interface: Bag
        (Violation) Removes all occurrences of the given object from the bag.

        This will also remove the object from the Bag.uniqueSet().

        According to the Collection.remove(Object) method, this method should only remove the first occurrence of the given object, not all occurrences.

        Specified by:
        remove in interface Bag
        Specified by:
        remove in interface java.util.Collection
        Overrides:
        remove in class AbstractCollectionDecorator
        Returns:
        true if this call changed the collection
      • removeAll

        public boolean removeAll​(java.util.Collection coll)
        Deprecated.
        Description copied from interface: Bag
        (Violation) Remove all elements represented in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object, the bag will have n fewer copies, assuming the bag had at least n copies to begin with.

        The Collection.removeAll(Collection) method specifies that cardinality should not be respected; this method should remove all occurrences of every object contained in the given collection.

        Specified by:
        removeAll in interface Bag
        Specified by:
        removeAll in interface java.util.Collection
        Overrides:
        removeAll in class AbstractCollectionDecorator
        Parameters:
        coll - the collection to remove
        Returns:
        true if this call changed the collection
      • retainAll

        public boolean retainAll​(java.util.Collection coll)
        Deprecated.
        Description copied from interface: Bag
        (Violation) Remove any members of the bag that are not in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object and the bag has m > n copies, then delete m - n copies from the bag. In addition, if e is an object in the bag but !coll.contains(e), then remove e and any of its copies.

        The Collection.retainAll(Collection) method specifies that cardinality should not be respected; this method should keep all occurrences of every object contained in the given collection.

        Specified by:
        retainAll in interface Bag
        Specified by:
        retainAll in interface java.util.Collection
        Overrides:
        retainAll in class AbstractCollectionDecorator
        Parameters:
        coll - the collection to retain
        Returns:
        true if this call changed the collection
      • add

        public boolean add​(java.lang.Object object,
                           int count)
        Deprecated.
        Description copied from interface: Bag
        Adds nCopies copies of the specified object to the Bag.

        If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object). Otherwise add it to the Bag.uniqueSet() and report its count as nCopies.

        Specified by:
        add in interface Bag
        Overrides:
        add in class AbstractBagDecorator
        Parameters:
        object - the object to add
        count - the number of copies to add
        Returns:
        true if the object was not already in the uniqueSet
      • remove

        public boolean remove​(java.lang.Object object,
                              int count)
        Deprecated.
        Description copied from interface: Bag
        Removes nCopies copies of the specified object from the Bag.

        If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.

        Specified by:
        remove in interface Bag
        Overrides:
        remove in class AbstractBagDecorator
        Parameters:
        object - the object to remove
        count - the number of copies to remove
        Returns:
        true if this call changed the collection
      • uniqueSet

        public java.util.Set uniqueSet()
        Deprecated.
        Description copied from interface: Bag
        Returns a Set of unique elements in the Bag.

        Uniqueness constraints are the same as those in Set.

        Specified by:
        uniqueSet in interface Bag
        Overrides:
        uniqueSet in class AbstractBagDecorator
        Returns:
        the Set of unique Bag elements