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

java.lang.Object
io.vavr.collection.AbstractQueue<T,Q>
All Implemented Interfaces:
Foldable<T>, Traversable<T>, Value<T>, Iterable<T>
Direct Known Subclasses:
PriorityQueue, Queue

abstract class AbstractQueue<T,Q extends AbstractQueue<T,Q>> extends Object implements Traversable<T>
  • Constructor Details

    • AbstractQueue

      AbstractQueue()
  • Method Details

    • 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:
      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... 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:
      NullPointerException - if elements is null
    • enqueueAll

      public abstract Q enqueueAll(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:
      NullPointerException - if elements is null
    • peek

      public T peek()
      Returns the first element without modifying it.
      Returns:
      the first element
      Throws:
      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(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Drops elements until the predicate holds for the current element.
      Specified by:
      dropUntil in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for this elements.
      Returns:
      a new instance consisting of all elements starting from the first one which does satisfy the given predicate.
    • dropWhile

      public abstract Q dropWhile(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Drops elements while the predicate holds for the current element.

      Note: This is essentially the same as dropUntil(predicate.negate()). It is intended to be used with method references, which cannot be negated directly.

      Specified by:
      dropWhile in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for this elements.
      Returns:
      a new instance consisting of all elements starting from the first one which does not satisfy the given 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:
      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:
      UnsupportedOperationException - if this is empty
    • tailOption

      public Option<Q> tailOption()
      Description copied from interface: Traversable
      Drops the first element of a non-empty Traversable and returns an Option.
      Specified by:
      tailOption in interface Traversable<T>
      Returns:
      Some(traversable) or None if this is empty.
    • retainAll

      public Q retainAll(Iterable<? extends T> elements)
      Description copied from interface: Traversable
      Keeps all occurrences of the given elements from this.
      Specified by:
      retainAll in interface Traversable<T>
      Parameters:
      elements - Elements to be kept.
      Returns:
      a Traversable containing all occurrences of the given elements.
    • removeAll

      public Q removeAll(Iterable<? extends T> elements)
    • removeAll

      @Deprecated public Q removeAll(Predicate<? super T> predicate)
      Deprecated.
    • reject

      public Q reject(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new traversable consisting of all elements which do not satisfy the given predicate.

      The default implementation is equivalent to

      filter(predicate.negate()
      Specified by:
      reject in interface Traversable<T>
      Parameters:
      predicate - A predicate
      Returns:
      a new traversable
    • takeWhile

      public Q takeWhile(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Takes elements while the predicate holds for the current element.
      Specified by:
      takeWhile in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for the contained elements.
      Returns:
      a new instance consisting of all elements before the first one which does not satisfy the given predicate.
    • takeUntil

      public abstract Q takeUntil(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Takes elements until the predicate holds for the current element.

      Note: This is essentially the same as takeWhile(predicate.negate()). It is intended to be used with method references, which cannot be negated directly.

      Specified by:
      takeUntil in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for this elements.
      Returns:
      a new instance consisting of all elements before the first one which does satisfy the given predicate.
    • peek

      public Q peek(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 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 Object
      Returns:
      A String representation of this object