Class SortedBag.ViewBag

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>
    Enclosing class:
    SortedBag<E>

    protected class SortedBag.ViewBag
    extends SortedBag<E>
    A range-limited view of the SortedBag. This view is backed by the SortedBag, so any modifications made to it are visible to the underlying bag, and vice-versa.
    • Field Detail

      • f_oFrom

        protected final Object f_oFrom
        The (inclusive) lower bound of this view.
      • f_oTo

        protected final Object f_oTo
        The (exclusive) upper bound of this view.
    • Constructor Detail

      • ViewBag

        public ViewBag​(E from,
                       E to)
        Construct a view of the SortedBag, constrained to the range [from, to).
        Parameters:
        from - the "from" element (inclusive), or null
        to - the "to" element (exclusive), or null
    • Method Detail

      • subBag

        public SortedBag<E> subBag​(E fromElement,
                                   E toElement)
        Returns a view of the portion of this bag whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned bag is empty.) The returned bag is backed by this bag, so changes in the returned bag are reflected in this bag, and vice-versa. The returned bag supports all optional bag operations that this bag supports.

        The returned bag will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Overrides:
        subBag in class SortedBag<E>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned bag
        toElement - high endpoint (exclusive) of the returned bag
        Returns:
        a view of the portion of this bag whose elements range from fromElement, inclusive, to toElement, exclusive
      • headBag

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

        The returned bag will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Overrides:
        headBag in class SortedBag<E>
        Parameters:
        toElement - high endpoint (exclusive) of the returned bag
        Returns:
        a view of the portion of this bag whose elements are strictly less than toElement
      • tailBag

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

        The returned bag will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Overrides:
        tailBag in class SortedBag<E>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned bag
        Returns:
        a view of the portion of this bag whose elements are greater than or equal to fromElement
      • checkRange

        protected void checkRange​(Object o)
        Check that the specified object is within the range of this view.
        Parameters:
        o - the object to check