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>,Iterable<T>
- Direct Known Subclasses:
PriorityQueue,Queue
abstract class AbstractQueue<T,Q extends AbstractQueue<T,Q>>
extends Object
implements Traversable<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondequeue()Removes an element from this Queue.Removes an element from this Queue.Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.abstract QReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.abstract QEnqueues a new element.Enqueues the given elements.abstract QenqueueAll(Iterable<? extends T> elements) Enqueues the given elements.abstract Qinit()Dual of tail(), returning all elements except the last.Dual of tailOption(), returning all elements except the last asOption.peek()Returns the first element without modifying it.Performs the givenactionon the first element if this is an eager implementation.Returns the first element without modifying the Queue.Returns a new traversable containing only the elements that do not satisfy the given predicate.Removes all occurrences of the specified elements from this Queue.Deprecated.Retains only the elements from this Traversable that are contained in the givenelements.abstract Qtail()Drops the first element of a non-empty Traversable.Returns a newTraversablewithout its first element as anOption.abstract QTakes elements from thisTraversableuntil the given predicate holds for an element.Takes elements from thisTraversablewhile the given predicate holds.toString()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, waitMethods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOptionMethods 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, zipWithIndexMethods 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
-
Constructor Details
-
AbstractQueue
AbstractQueue()
-
-
Method Details
-
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
Removes an element from this Queue.- Returns:
Noneif this Queue is empty, otherwiseSomeTuplecontaining the first element and the remaining elements of this Queue
-
enqueue
Enqueues a new element.- Parameters:
element- The new element- Returns:
- a new
Queueinstance, containing the new element
-
enqueue
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:
NullPointerException- if elements is null
-
enqueueAll
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:
NullPointerException- if elements is null
-
peek
Returns the first element without modifying it.- Returns:
- the first element
- Throws:
NoSuchElementException- if this Queue is empty
-
peekOption
Returns the first element without modifying the Queue.- Returns:
Noneif this Queue is empty, otherwise aSomecontaining the first element
-
dropUntil
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
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
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:
UnsupportedOperationException- if this is empty
-
initOption
Dual of tailOption(), returning all elements except the last asOption.- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(Q)orNoneif this is empty.
-
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:
UnsupportedOperationException- if this is empty
-
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
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
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:
NullPointerException- ifelementsis null
-
removeAll
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:
NullPointerException- ifpredicateis null
-
reject
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
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
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
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
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
reject(Predicate)instead