Class AbstractQueue<T,​Q extends AbstractQueue<T,​Q>>

    • Constructor Detail

      • AbstractQueue

        AbstractQueue()
    • Method Detail

      • dequeue

        public Tuple2<T,​Q> dequeue()
        Removes an element from this Queue.
        Returns:
        a tuple containing the first element and the remaining elements of this Queue
        Throws:
        java.util.NoSuchElementException - if this Queue is empty
      • dequeueOption

        public Option<Tuple2<T,​Q>> dequeueOption()
        Removes an element from this Queue.
        Returns:
        None if this Queue is empty, otherwise Some Tuple containing the first element and the remaining elements of this Queue
      • enqueue

        public abstract Q enqueue​(T element)
        Enqueues a new element.
        Parameters:
        element - The new element
        Returns:
        a new Queue instance, containing the new element
      • enqueue

        public Q enqueue​(T @NonNull ... elements)
        Enqueues the given elements. A queue has FIFO order, i.e. the first of the given elements is the first which will be retrieved.
        Parameters:
        elements - Elements, may be empty
        Returns:
        a new Queue instance, containing the new elements
        Throws:
        java.lang.NullPointerException - if elements is null
      • enqueueAll

        public abstract Q enqueueAll​(java.lang.Iterable<? extends T> elements)
        Enqueues the given elements. A queue has FIFO order, i.e. the first of the given elements is the first which will be retrieved.
        Parameters:
        elements - An Iterable of elements, may be empty
        Returns:
        a new Queue instance, containing the new elements
        Throws:
        java.lang.NullPointerException - if elements is null
      • peek

        public T peek()
        Returns the first element without modifying it.
        Returns:
        the first element
        Throws:
        java.util.NoSuchElementException - if this Queue is empty
      • peekOption

        public Option<T> peekOption()
        Returns the first element without modifying the Queue.
        Returns:
        None if this Queue is empty, otherwise a Some containing the first element
      • dropUntil

        public Q dropUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new Traversable starting from the first element that satisfies the given predicate, dropping all preceding elements.
        Specified by:
        dropUntil in interface Traversable<T>
        Parameters:
        predicate - a condition tested on each element
        Returns:
        a new instance starting from the first element matching the predicate
      • dropWhile

        public abstract Q dropWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new Traversable starting from the first element that does not satisfy the given predicate, dropping all preceding elements.

        This is equivalent to dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.

        Specified by:
        dropWhile in interface Traversable<T>
        Parameters:
        predicate - a condition tested on each element
        Returns:
        a new instance starting from the first element not matching the predicate
      • init

        public abstract Q init()
        Dual of tail(), returning all elements except the last.
        Specified by:
        init in interface Traversable<T>
        Returns:
        a new instance containing all elements except the last.
        Throws:
        java.lang.UnsupportedOperationException - if this is empty
      • initOption

        public Option<Q> initOption()
        Dual of tailOption(), returning all elements except the last as Option.
        Specified by:
        initOption in interface Traversable<T>
        Returns:
        Some(Q) or None if this is empty.
      • tail

        public abstract Q tail()
        Drops the first element of a non-empty Traversable.
        Specified by:
        tail in interface Traversable<T>
        Returns:
        A new instance of Traversable containing all elements except the first.
        Throws:
        java.lang.UnsupportedOperationException - if this is empty
      • tailOption

        public Option<Q> tailOption()
        Description copied from interface: Traversable
        Returns a new Traversable without its first element as an Option.
        Specified by:
        tailOption in interface Traversable<T>
        Returns:
        Some(traversable) if non-empty, otherwise None
      • retainAll

        public Q retainAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Traversable
        Retains only the elements from this Traversable that are contained in the given elements.
        Specified by:
        retainAll in interface Traversable<T>
        Parameters:
        elements - the elements to keep
        Returns:
        a new Traversable containing only the elements present in elements, in their original order
      • removeAll

        public Q removeAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Removes all occurrences of the specified elements from this Queue.
        Parameters:
        elements - the elements to be removed
        Returns:
        a new Queue with all occurrences of the specified elements removed
        Throws:
        java.lang.NullPointerException - if elements is null
      • removeAll

        @Deprecated
        public Q removeAll​(@NonNull java.util.function.Predicate<? super T> predicate)
        Deprecated.
        Use reject(Predicate) instead
        Removes all elements from this Queue that satisfy the given predicate.
        Parameters:
        predicate - the predicate used to test elements
        Returns:
        a new Queue with all elements that satisfy the predicate removed
        Throws:
        java.lang.NullPointerException - if predicate is null
      • reject

        public Q reject​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new traversable containing only the elements that do not satisfy the given predicate.

        This is equivalent to filter(predicate.negate()).

        Specified by:
        reject in interface Traversable<T>
        Parameters:
        predicate - the condition to test elements
        Returns:
        a traversable with elements not matching the predicate
      • takeWhile

        public Q takeWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Takes elements from this Traversable while the given predicate holds.
        Specified by:
        takeWhile in interface Traversable<T>
        Parameters:
        predicate - a condition tested sequentially on the elements
        Returns:
        a new Traversable containing all elements up to (but not including) the first one that does not satisfy the predicate
      • takeUntil

        public abstract Q takeUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Takes elements from this Traversable until the given predicate holds for an element.

        Equivalent to takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.

        Specified by:
        takeUntil in interface Traversable<T>
        Parameters:
        predicate - a condition tested sequentially on the elements
        Returns:
        a new Traversable containing all elements before the first one that satisfies the predicate
      • peek

        public Q peek​(@NonNull java.util.function.Consumer<? super T> action)
        Description copied from interface: Value
        Performs the given action on the first element if this is an eager implementation. Performs the given action on all elements (the first immediately, successive deferred), if this is a lazy implementation.
        Specified by:
        peek in interface Traversable<T>
        Specified by:
        peek in interface Value<T>
        Parameters:
        action - The action that will be performed on the element(s).
        Returns:
        this instance
      • toString

        public java.lang.String toString()
        Description copied from interface: Value
        Clarifies that values have a proper toString() method implemented.

        See Object.toString().

        Specified by:
        toString in interface Value<T>
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String representation of this object