Package io.vavr.collection
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>,java.lang.Iterable<T>
- Direct Known Subclasses:
PriorityQueue,Queue
abstract class AbstractQueue<T,Q extends AbstractQueue<T,Q>> extends java.lang.Object implements Traversable<T>
-
-
Constructor Summary
Constructors Constructor Description AbstractQueue()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Tuple2<T,Q>dequeue()Removes an element from this Queue.Option<Tuple2<T,Q>>dequeueOption()Removes an element from this Queue.QdropUntil(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.abstract QdropWhile(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.abstract Qenqueue(T element)Enqueues a new element.Qenqueue(T @NonNull ... elements)Enqueues the given elements.abstract QenqueueAll(java.lang.Iterable<? extends T> elements)Enqueues the given elements.abstract Qinit()Dual of tail(), returning all elements except the last.Option<Q>initOption()Dual of tailOption(), returning all elements except the last asOption.Tpeek()Returns the first element without modifying it.Qpeek(@NonNull java.util.function.Consumer<? super T> action)Performs the givenactionon the first element if this is an eager implementation.Option<T>peekOption()Returns the first element without modifying the Queue.Qreject(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.QremoveAll(@NonNull java.lang.Iterable<? extends T> elements)Removes all occurrences of the specified elements from this Queue.QremoveAll(@NonNull java.util.function.Predicate<? super T> predicate)Deprecated.Usereject(Predicate)insteadQretainAll(@NonNull java.lang.Iterable<? extends T> elements)Retains only the elements from this Traversable that are contained in the givenelements.abstract Qtail()Drops the first element of a non-empty Traversable.Option<Q>tailOption()Returns a newTraversablewithout its first element as anOption.abstract QtakeUntil(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.QtakeWhile(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversablewhile the given predicate holds.java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, collect, containsAll, count, distinct, distinctBy, distinctBy, drop, dropRight, equals, existsUnique, filter, find, findLast, flatMap, foldLeft, foldRight, forEachWithIndex, get, groupBy, grouped, hasDefiniteSize, hashCode, head, headOption, isDistinct, isEmpty, isOrdered, isSequential, isSingleValued, isTraversableAgain, iterator, last, lastOption, length, map, mapTo, mapToVoid, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, orElse, orElse, partition, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, replace, replaceAll, scan, scanLeft, scanRight, single, singleOption, size, slideBy, sliding, sliding, span, spliterator, sum, take, takeRight, unzip, unzip3, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, isAsync, isLazy, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
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:
Noneif this Queue is empty, otherwiseSomeTuplecontaining 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
Queueinstance, 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
Queueinstance, 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
Queueinstance, 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:
Noneif this Queue is empty, otherwise aSomecontaining the first element
-
dropUntil
public Q dropUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.- Specified by:
dropUntilin interfaceTraversable<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:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.- Specified by:
dropWhilein interfaceTraversable<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:
initin interfaceTraversable<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 asOption.- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(Q)orNoneif this is empty.
-
tail
public abstract Q tail()
Drops the first element of a non-empty Traversable.- Specified by:
tailin interfaceTraversable<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:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
retainAll
public Q retainAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.- Specified by:
retainAllin interfaceTraversable<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- ifelementsis null
-
removeAll
@Deprecated public Q removeAll(@NonNull java.util.function.Predicate<? super T> predicate)
Deprecated.Usereject(Predicate)insteadRemoves 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- ifpredicateis null
-
reject
public Q reject(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).- Specified by:
rejectin interfaceTraversable<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:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining 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:TraversableTakes elements from thisTraversableuntil 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:
takeUntilin interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining 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:ValuePerforms the givenactionon the first element if this is an eager implementation. Performs the givenactionon all elements (the first immediately, successive deferred), if this is a lazy implementation.
-
toString
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
-