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(java.util.function.Predicate<? super T> predicate)Drops elements until the predicate holds for the current element.abstract QdropWhile(java.util.function.Predicate<? super T> predicate)Drops elements while the predicate holds for the current element.abstract Qenqueue(T element)Enqueues a new element.Qenqueue(T... 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(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(java.util.function.Predicate<? super T> predicate)Returns a new traversable consisting of all elements which do not satisfy the given predicate.QremoveAll(java.lang.Iterable<? extends T> elements)QremoveAll(java.util.function.Predicate<? super T> predicate)Deprecated.QretainAll(java.lang.Iterable<? extends T> elements)Keeps all occurrences of the given elements from this.abstract Qtail()Drops the first element of a non-empty Traversable.Option<Q>tailOption()Drops the first element of a non-empty Traversable and returns anOption.abstract QtakeUntil(java.util.function.Predicate<? super T> predicate)Takes elements until the predicate holds for the current element.QtakeWhile(java.util.function.Predicate<? super T> predicate)Takes elements while the predicate holds for the current element.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, 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... 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(java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableDrops elements until the predicate holds for the current element.- Specified by:
dropUntilin interfaceTraversable<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(java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableDrops 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:
dropWhilein interfaceTraversable<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:
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:TraversableDrops the first element of a non-empty Traversable and returns anOption.- Specified by:
tailOptionin interfaceTraversable<T>- Returns:
Some(traversable)orNoneif this is empty.
-
retainAll
public Q retainAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:TraversableKeeps all occurrences of the given elements from this.- Specified by:
retainAllin interfaceTraversable<T>- Parameters:
elements- Elements to be kept.- Returns:
- a Traversable containing all occurrences of the given elements.
-
removeAll
@Deprecated public Q removeAll(java.util.function.Predicate<? super T> predicate)
Deprecated.
-
reject
public Q reject(java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns 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:
rejectin interfaceTraversable<T>- Parameters:
predicate- A predicate- Returns:
- a new traversable
-
takeWhile
public Q takeWhile(java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes elements while the predicate holds for the current element.- Specified by:
takeWhilein interfaceTraversable<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(java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes 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:
takeUntilin interfaceTraversable<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(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().
-
-