Class CollectionsExt.AbstractImmutableMultiSet<C extends MultiSet<E>,​E>

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E obj)
      Adds obj to this MultiSet.
      boolean addAll​(MultiSet<? extends E> mvs)
      Adds mvs elementwise to this multi set taking multiplicities into account and returns whether this caused a change of the underlying set. **** strange implementation; also: change
      boolean addAll​(Set<? extends E> set)
      Adds set elementwise to this multi set increasing multiplicities and returns whether this caused a change of the underlying set. **** strange implementation; also: change
      int addWithMult​(E obj)
      Adds obj to this MultiSet and returns the new multiplicity of this object.
      int addWithMult​(E obj, int addMult)
      Increases the multiplicity of obj in this MultiSet by the specified value addMult and returns the new multiplicity of this object.
      Set<CollectionsExt.Modification> allowedModifications()  
      void clear()
      Removes all of the elements from this MultiSet.
      boolean contains​(Object obj)
      Returns true if this MultiSet contains the specified element.
      boolean containsAll​(Collection<?> coll)
      Returns true if this MultiSet contains all of the elements in the specified collection with strictly positive multiplicity.
      boolean equals​(Object obj)
      Returns true if and only if obj is also a MultiSet and contains the same elements with the same multiplicities as this one.
      Map<E,​MultiSet.Multiplicity> getMap()
      Returns a view of the underlying map of this MultiSet as a map mapping each entry to its multiplicity.
      int getMaxMult()
      Returns the maximal multiplicity of an element in this set.
      int getMultiplicity​(Object obj)
      Returns the multiplicity with which the given object occurs within this set.
      MultiSet.Multiplicity getMultiplicityObj​(Object obj)
      Returns the multiplicity object of the given object in this set or null.
      Object getObjWithMaxMult()
      Returns one of the elements in this multiple set with maximal multiplicity.
      Set<E> getSet()
      Returns a view of the underlying set of this MultiSet.
      Set<Map.Entry<E,​MultiSet.Multiplicity>> getSetWithMults()
      Returns a Set view of the mapping from the element of this MultiSet to the according multiplicities.
      int hashCode()  
      boolean isEmpty()
      Returns whether this multiple set contains no element.
      MultiSetIterator<E> iterator()
      Returns an iterator over the elements in this collection which emits each element exactly once, without regarding its multiplicity.
      boolean remove​(Object obj)
      Removes all instances of the specified element from this MultiSet, if it is present with nontrivial multiplicity.
      boolean removeAll​(Collection<?> coll)
      Removes all this MultiSet's elements that are also contained in the specified collection.
      int removeWithMult​(Object obj)
      Decrements the multiplicity of obj in this MultiSet if it is present and returns the old multiplicity of obj; If this is 0 returns without altering this MultiSet.
      int removeWithMult​(Object obj, int removeMult)
      Decreases the multiplicity of obj in this MultiSet by the specified value removeMult if possible and returns the old multiplicity of obj.
      boolean retainAll​(Collection<?> coll)
      Retains only the elements in this MultiSet that are contained in the specified collection.
      int setMultiplicity​(E obj, int newMult)
      Sets the multiplicity of obj to the value specified by mult.
      int size()
      Returns the number of pairwise different elements in this MultiSet.
      int sizeWithMult()
      Returns the number of elements in this MultiSet counted with multiplicities.
      Object[] toArray()
      Returns an array containing all of the elements in this MultiSet exactly once, ignoring its multiplicity.
      E[] toArray​(E[] arr)
      Returns an array containing all of the elements in this MultiSet; the runtime type of the returned array is that of the specified array.
      String toString()  
      abstract C unrestricted()
      Returns the underlying multiset without the restrictions imposed by this CollectionsExt.ImmutableCollection.
    • Constructor Detail

      • AbstractImmutableMultiSet

        private AbstractImmutableMultiSet()
    • Method Detail

      • size

        public int size()
        Description copied from interface: MultiSet
        Returns the number of pairwise different elements in this MultiSet. If this MultiSet contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        size in interface MultiSet<C extends MultiSet<E>>
        Returns:
        the number of elements in this MultiSet each multiple element counted as a single one.
        See Also:
        MultiSet.sizeWithMult()
      • sizeWithMult

        public int sizeWithMult()
        Description copied from interface: MultiSet
        Returns the number of elements in this MultiSet counted with multiplicities. If this MultiSet contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        sizeWithMult in interface MultiSet<C extends MultiSet<E>>
        Returns:
        the number of elements in this MultiSet counted with multiplicities, provided this does not exceed Integer.MAX_VALUE; otherwise just Integer.MAX_VALUE.
        See Also:
        MultiSet.size()
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: MultiSet
        Returns whether this multiple set contains no element.
        Specified by:
        isEmpty in interface MultiSet<C extends MultiSet<E>>
        Returns:
        whether this multiple set contains no element.
      • getObjWithMaxMult

        public Object getObjWithMaxMult()
        Description copied from interface: MultiSet
        Returns one of the elements in this multiple set with maximal multiplicity. The return value is null if and only if this set is empty.
        Specified by:
        getObjWithMaxMult in interface MultiSet<C extends MultiSet<E>>
        Returns:
        a Object o != null with maximal multiplicity or null if this multiple set is empty.
        See Also:
        MultiSet.isEmpty()
      • getMaxMult

        public int getMaxMult()
        Description copied from interface: MultiSet
        Returns the maximal multiplicity of an element in this set. In particular for empty sets returns 0.
        Specified by:
        getMaxMult in interface MultiSet<C extends MultiSet<E>>
        Returns:
        a non-negative int value which is the maximal mutliplicity of an element in this set. In particular this is 0 if and only if this set is empty.
      • contains

        public boolean contains​(Object obj)
        Description copied from interface: MultiSet
        Returns true if this MultiSet contains the specified element. More formally, returns true if and only if this MultiSet contains at least one element e such that (o==null ? e==null : o.equals(e)).
        Specified by:
        contains in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - element (not null) whose presence in this MultiSet is to be tested.
        Returns:
        true if this MultiSet contains the specified element.
      • toArray

        public Object[] toArray()
        Description copied from interface: MultiSet
        Returns an array containing all of the elements in this MultiSet exactly once, ignoring its multiplicity.

        The returned array will be "safe" in that no references to it are maintained by this MultiSet. (In other words, this method must allocate a new array even if this MultiSet is backed by an array). The caller is thus free to modify the returned array.

        Specified by:
        toArray in interface MultiSet<C extends MultiSet<E>>
        Returns:
        an array containing all of the elements in this collection
        See Also:
        MultiSet.iterator()
      • toArray

        public E[] toArray​(E[] arr)
        Description copied from interface: MultiSet
        Returns an array containing all of the elements in this MultiSet; the runtime type of the returned array is that of the specified array. If the MultiSet fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this MultiSet.

        If this MultiSet fits in the specified array with room to spare (i.e., the array has more elements than this MultiSet), the elementin the array immediately following the end of the MultiSet is set to null. This is useful in determining the length of this MultiSet because this MultiSet does not contain any null elements.

        Suppose l is a List known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:

             String[] x = (String[]) v.toArray(new String[0]);
         

        Note that toArray(new Object[0]) is identical in function to toArray().

        Specified by:
        toArray in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        arr - the array into which the elements of this MultiSet are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing each elements of this MultiSet exactly once.
      • getMultiplicityObj

        public MultiSet.Multiplicity getMultiplicityObj​(Object obj)
        Description copied from interface: MultiSet
        Returns the multiplicity object of the given object in this set or null.
        Specified by:
        getMultiplicityObj in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - an Object and not null.
        Returns:
        If obj is an instance which is in this set, a multiplicity object wrapping the multiplicity is returned. If obj is an instance which is not in this set, null is returned.
        See Also:
        MultiSet.getMultiplicity(Object)
      • iterator

        public MultiSetIterator<E> iterator()
        Description copied from interface: MultiSet
        Returns an iterator over the elements in this collection which emits each element exactly once, without regarding its multiplicity. For certain implementations, the iterator returned does not allow modifications of the underlying (multi-)set.
        Specified by:
        iterator in interface Iterable<C extends MultiSet<E>>
        Specified by:
        iterator in interface MultiSet<C extends MultiSet<E>>
        Returns:
        an Iterator over the elements in this collection considering each element exactly once ignoring its multiplicity.
      • addWithMult

        public int addWithMult​(E obj)
        Description copied from interface: MultiSet
        Adds obj to this MultiSet and returns the new multiplicity of this object. In other words, increments the multiplicity of obj by one. This is a special case of MultiSet.addWithMult(Object obj, int addMult) with addMult==1.
        Specified by:
        addWithMult in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - a Object. Note that this object may not be null.
        Returns:
        a strictly positive int value: the new multiplicity of obj.
      • addWithMult

        public int addWithMult​(E obj,
                               int addMult)
        Description copied from interface: MultiSet
        Increases the multiplicity of obj in this MultiSet by the specified value addMult and returns the new multiplicity of this object. This generalizes MultiSet.addWithMult(Object obj) with addMult==1.
        Specified by:
        addWithMult in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - an Object instance.
        addMult - a non-negative integer specifying the multiplicity with which obj is to be added.
        Returns:
        a non-negative int value: the new multiplicity of obj.
      • add

        public boolean add​(E obj)
        Description copied from interface: MultiSet
        Adds obj to this MultiSet. In other words, increments the multiplicity of obj by one. Returns true if this MultiSet interpreted as a set changed as a result of the call. (Returns false if this MultiSet already contains the specified element (with nontrivial multiplicity).
        Specified by:
        add in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - element the multiplicity of which in this MultiSet is to be increased by one. Note that this may not be null.
        Returns:
        true if and only if the multiplicity of the specified element was 0 before the call of this method.
      • removeWithMult

        public int removeWithMult​(Object obj)
        Description copied from interface: MultiSet
        Decrements the multiplicity of obj in this MultiSet if it is present and returns the old multiplicity of obj; If this is 0 returns without altering this MultiSet.
        Specified by:
        removeWithMult in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - a Object. Note that this object may not be null.
        Returns:
        a non-negative int value: the old multiplicity of obj before a potential modification of this MultiSet.
      • removeWithMult

        public int removeWithMult​(Object obj,
                                  int removeMult)
        Description copied from interface: MultiSet
        Decreases the multiplicity of obj in this MultiSet by the specified value removeMult if possible and returns the old multiplicity of obj.
        Specified by:
        removeWithMult in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - an Object instance.
        removeMult - a non-negative integer specifying the multiplicity with which obj is to be removed.
        Returns:
        a non-negative int value: the old multiplicity of obj before a potential modification of this MultiSet.
      • remove

        public boolean remove​(Object obj)
        Description copied from interface: MultiSet
        Removes all instances of the specified element from this MultiSet, if it is present with nontrivial multiplicity. More formally, immediately after having (successively) invoked s.remove(o), the condition s.contains(o) == false is satisfied. Returns true if this MultiSet contained the specified element (or equivalently, if (the underlying set of) this MultiSet changed as a result of the call).
        Specified by:
        remove in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - element the multiplicity of which in this MultiSet is to be increased by one.
        Returns:
        true if and only if this MultiSet changed as a result of the call.
      • setMultiplicity

        public int setMultiplicity​(E obj,
                                   int newMult)
        Description copied from interface: MultiSet
        Sets the multiplicity of obj to the value specified by mult.
        Specified by:
        setMultiplicity in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        obj - an Object instance.
        newMult - a non-negative int value.
        Returns:
        the old multiplicity of obj as a non-negative int value.
        See Also:
        MultiSet.getMultiplicity(Object)
      • containsAll

        public boolean containsAll​(Collection<?> coll)
        Description copied from interface: MultiSet
        Returns true if this MultiSet contains all of the elements in the specified collection with strictly positive multiplicity.
        Specified by:
        containsAll in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        coll - collection to be checked for containment in this MultiSet.
        Returns:
        true if this MultiSet contains all of the elements in the specified collection.
        See Also:
        MultiSet.contains(Object)
      • addAll

        public boolean addAll​(MultiSet<? extends E> mvs)
        Description copied from interface: MultiSet
        Adds mvs elementwise to this multi set taking multiplicities into account and returns whether this caused a change of the underlying set. **** strange implementation; also: change
        Specified by:
        addAll in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        mvs - a MultiSet object.
        Returns:
        returns whether adding changed this MultiSet interpreted as a set.
      • addAll

        public boolean addAll​(Set<? extends E> set)
        Description copied from interface: MultiSet
        Adds set elementwise to this multi set increasing multiplicities and returns whether this caused a change of the underlying set. **** strange implementation; also: change
        Specified by:
        addAll in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        set - a Set object.
        Returns:
        returns whether adding changed this MultiSet interpreted as a set.
      • removeAll

        public boolean removeAll​(Collection<?> coll)
        Description copied from interface: MultiSet
        Removes all this MultiSet's elements that are also contained in the specified collection. After this call returns, this MultiSet will contain no elements in common with the specified collection.
        Specified by:
        removeAll in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        coll - elements to be removed from this MultiSet.
        Returns:
        true if this MultiSet changed as a result of the call.
        See Also:
        MultiSet.remove(Object), MultiSet.contains(Object)
      • retainAll

        public boolean retainAll​(Collection<?> coll)
        Description copied from interface: MultiSet
        Retains only the elements in this MultiSet that are contained in the specified collection. In other words, removes from this MultiSet all of its elements that are not contained in the specified collection.
        Specified by:
        retainAll in interface MultiSet<C extends MultiSet<E>>
        Parameters:
        coll - elements to be retained in this MultiSet.
        Returns:
        true if this MultiSet changed as a result of the call.
        See Also:
        MultiSet.remove(Object), MultiSet.contains(Object)
      • clear

        public void clear()
        Description copied from interface: MultiSet
        Removes all of the elements from this MultiSet. This MultiSet will be empty after this method returns.
        Specified by:
        clear in interface MultiSet<C extends MultiSet<E>>
      • getSet

        public Set<E> getSet()
        Description copied from interface: MultiSet
        Returns a view of the underlying set of this MultiSet. For certain implementations, this set is immutable to prevent implicit modification of this MultiSet.
        Specified by:
        getSet in interface MultiSet<C extends MultiSet<E>>
        Returns:
        the Set containing exactly the objects with strictly positive multiplicity in this MultiSet.
      • equals

        public boolean equals​(Object obj)
        Description copied from interface: MultiSet
        Returns true if and only if obj is also a MultiSet and contains the same elements with the same multiplicities as this one.
        Specified by:
        equals in interface MultiSet<C extends MultiSet<E>>
        Overrides:
        equals in class Object
        Parameters:
        obj - an Object, possibly null.
        Returns:
        a true if and only if obj is also a MultiSet and contains the same elements with the same multiplicities as this one.