Class TreeMultiSet<T>

    • Constructor Detail

      • TreeMultiSet

        public TreeMultiSet()
        Creates a new, empty MultiSet.
      • TreeMultiSet

        public TreeMultiSet​(Comparator<? super T> comp)
        Creates a new, empty MultiSet.
      • TreeMultiSet

        public TreeMultiSet​(MultiSet<? extends T> other)
        Copy constructor.
        Parameters:
        other - another MultiSet instance.
      • TreeMultiSet

        public TreeMultiSet​(Set<? extends T> sSet)
        Creates a multi set with the elements of sSet and all elements with multiplicity 1.
        Parameters:
        sSet - some instance of a sorted set.
    • Method Detail

      • comparator

        public Comparator<? super T> comparator()
        Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.
        Specified by:
        comparator in interface SortedMultiSet<T>
        Returns:
        the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.
      • first

        public T first()
        Returns the first (lowest) element currently in this set.
        Specified by:
        first in interface SortedMultiSet<T>
        Returns:
        the first (lowest) element currently in this set
        Throws:
        NoSuchElementException - if this set is empty.
      • last

        public T last()
        Returns the last (highest) element currently in this set.
        Specified by:
        last in interface SortedMultiSet<T>
        Returns:
        the last (highest) element currently in this set.
        Throws:
        NoSuchElementException - if this set is empty.
      • headSet

        public SortedMultiSet<T> headSet​(T toElement)
        Returns a view of the portion of this multi-set whose elements are strictly less than toElement. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.

        The returned multi-set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        headSet in interface SortedMultiSet<T>
        Parameters:
        toElement - high endpoint (exclusive) of the returned multi-set.
        Returns:
        a view of the portion of this multi-set whose elements are strictly less than toElement.
        Throws:
        ClassCastException - if toElement is not compatible with this multi-set's comparator (or, if the set has no comparator, if toElement does not implement Comparable). Implementations may, but are not required to, throw this exception if toElement cannot be compared to elements currently in this multi-set.
        NullPointerException - if toElement is null and this multi-set does not permit null elements.
        IllegalArgumentException - if this multi-set itself has a restricted range, and toElement lies outside the bounds of the range.
      • tailSet

        public SortedMultiSet<T> tailSet​(T fromElement)
        Returns a view of the portion of this multi-set whose elements are greater than or equal to fromElement. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.

        The returned multi-set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        tailSet in interface SortedMultiSet<T>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned multi-set.
        Returns:
        a view of the portion of this multi-set whose elements are greater than or equal to fromElement.
        Throws:
        ClassCastException - if fromElement is not compatible with this multi-set's comparator (or, if the set has no comparator, if fromElement does not implement Comparable). Implementations may, but are not required to, throw this exception if fromElement cannot be compared to elements currently in this multi-set.
        NullPointerException - if fromElement is null and this multi-set does not permit null elements.
        IllegalArgumentException - if this multi-set itself has a restricted range, and fromElement lies outside the bounds of the range.
      • subSet

        public SortedMultiSet<T> subSet​(T fromElement,
                                        T toElement)
        Returns a view of the portion of this multi-set whose elements range from fromElement inclusively to toElement exclusively. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.

        The returned multi-set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        subSet in interface SortedMultiSet<T>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned multi-set.
        toElement - high endpoint (exclusive) of the returned multi-set.
        Returns:
        a view of the portion of this multi-set from fromElement inclusively to toElement exclusively.
        Throws:
        ClassCastException - **** maybe original documentation wrong. **** if fromElement and toElement cannot be compared to one another using this set's comparator (or, if the set has no comparator, using natural ordering). or if fromElement is not compatible with this multi-set's comparator (or, if the set has no comparator, if fromElement does not implement Comparable). Implementations may, but are not required to, throw this exception if fromElement or toElement cannot be compared to elements currently in this multi-set.
        NullPointerException - if fromElement or toElement is null and this multi-set does not permit null elements.
        IllegalArgumentException - if fromElement is greater than toElement or if this multi-set itself has a restricted range, and fromElement or toElement lies outside the bounds of the range.
      • getSet

        public SortedSet<T> getSet()
        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<T>
        Specified by:
        getSet in interface SortedMultiSet<T>
        Returns:
        the Set containing exactly the objects with strictly positive multiplicity in this MultiSet.