Class PriorityQueue<T>
- java.lang.Object
-
- io.vavr.collection.AbstractQueue<T,PriorityQueue<T>>
-
- io.vavr.collection.PriorityQueue<T>
-
- Type Parameters:
T- Component type
- All Implemented Interfaces:
Foldable<T>,Ordered<T>,Traversable<T>,Value<T>,java.io.Serializable,java.lang.Iterable<T>
public final class PriorityQueue<T> extends AbstractQueue<T,PriorityQueue<T>> implements java.io.Serializable, Ordered<T>
A PriorityQueue.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparator<? super T>comparatorprivate Seq<PriorityQueueBase.Node<T>>forestprivate static longserialVersionUIDprivate intsize
-
Constructor Summary
Constructors Modifier Constructor Description privatePriorityQueue(java.util.Comparator<? super T> comparator, Seq<PriorityQueueBase.Node<T>> forest, int size)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> PriorityQueue<R>collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)Applies aPartialFunctionto all elements that are defined for it and collects the results.static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,PriorityQueue<T>>collector()Returns aCollectorwhich may be used in conjunction withStream.collect(Collector)to obtain aPriorityQueue<T>.java.util.Comparator<T>comparator()Returns the comparator that governs the ordering of elements in this collection.Tuple2<T,PriorityQueue<T>>dequeue()Removes an element from this Queue.PriorityQueue<T>distinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.PriorityQueue<T>distinctBy(@NonNull java.util.Comparator<? super T> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> PriorityQueue<T>distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.PriorityQueue<T>drop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.PriorityQueue<T>dropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.PriorityQueue<T>dropWhile(@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.static <T extends java.lang.Comparable<? super T>>
PriorityQueue<T>empty()Returns the empty PriorityQueue.static <T> PriorityQueue<T>empty(java.util.Comparator<? super T> comparator)Returns an empty PriorityQueue with the given comparator.PriorityQueue<T>enqueue(T element)Enqueues a new element.PriorityQueue<T>enqueueAll(java.lang.Iterable<? extends T> elements)Enqueues the given elements.booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.static <T> PriorityQueue<T>fill(int size, @NonNull java.util.function.Supplier<? extends T> supplier)static <T> PriorityQueue<T>fill(int size, T element)PriorityQueue<T>filter(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.<U> PriorityQueue<U>flatMap(@NonNull java.util.Comparator<U> comparator, @NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function and flattened with the given comparator.<U> PriorityQueue<U>flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.<U> UfoldRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> accumulator)Accumulates the elements of thisPriorityQueueby successively calling the given functionffrom the right, starting with a valuezeroof type B.<C> Map<C,? extends PriorityQueue<T>>groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.Iterator<? extends PriorityQueue<T>>grouped(int size)Splits thisTraversableinto consecutive blocks of the given size.booleanhasDefiniteSize()Checks if thisPriorityQueueis known to have a finite size.inthashCode()Returns the hash code of this collection.Thead()Returns the first element of a non-emptyPriorityQueue.PriorityQueue<T>init()Dual of tail(), returning all elements except the last.booleanisAsync()APriorityQueueis computed synchronously.booleanisEmpty()Checks if this Traversable contains no elements.booleanisLazy()APriorityQueueis computed eagerly.booleanisOrdered()Indicates whether this Traversable is ordered according to its natural or specified order.booleanisTraversableAgain()Checks if thisPriorityQueuecan be repeatedly traversed.Tlast()Returns the last element of this Traversable.intlength()Computes the number of elements of thisPriorityQueue.<U> PriorityQueue<U>map(@NonNull java.util.Comparator<U> comparator, @NonNull java.util.function.Function<? super T,? extends U> mapper)Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function with the given comparator.<U> PriorityQueue<U>map(@NonNull java.util.function.Function<? super T,? extends U> mapper)Transforms the elements of this Traversable to a new type, preserving order if defined.<U> PriorityQueue<U>mapTo(U value)Maps the underlying value to another fixed value.PriorityQueue<java.lang.Void>mapToVoid()Maps the underlying value to VoidPriorityQueue<T>merge(PriorityQueue<T> target)Merges this PriorityQueue with another PriorityQueue.static <T> PriorityQueue<T>narrow(PriorityQueue<? extends T> queue)Narrows aPriorityQueue<? extends T>toPriorityQueue<T>via a type-safe cast.static <T> PriorityQueue<T>of(@NonNull java.util.Comparator<? super T> comparator, T @NonNull ... elements)Creates a PriorityQueue of the given elements with the given comparator.static <T> PriorityQueue<T>of(java.util.Comparator<? super T> comparator, T element)Returns a singletonPriorityQueue, i.e.static <T extends java.lang.Comparable<? super T>>
PriorityQueue<T>of(T element)Returns a singletonPriorityQueue, i.e.static <T extends java.lang.Comparable<? super T>>
PriorityQueue<T>of(T... elements)Creates a PriorityQueue of the given elements.static <T extends java.lang.Comparable<? super T>>
PriorityQueue<T>ofAll(@NonNull java.lang.Iterable<? extends T> elements)Creates a PriorityQueue of the given elements.static <T> PriorityQueue<T>ofAll(@NonNull java.util.Comparator<? super T> comparator, @NonNull java.lang.Iterable<? extends T> elements)Creates a PriorityQueue of the given elements with the given comparator.static <T> PriorityQueue<T>ofAll(java.util.Comparator<? super T> comparator, java.util.stream.Stream<? extends T> javaStream)Creates a PriorityQueue from aStreamwith the given comparator.static <T extends java.lang.Comparable<? super T>>
PriorityQueue<T>ofAll(java.util.stream.Stream<? extends T> javaStream)Creates a PriorityQueue from aStream.PriorityQueue<T>orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)Returns thisPriorityQueueif it is nonempty, otherwisePriorityQueuecreated from result of evaluating supplier, using existing comparator.PriorityQueue<T>orElse(java.lang.Iterable<? extends T> other)Returns thisPriorityQueueif it is nonempty, otherwisePriorityQueuecreated from iterable, using existing comparator.Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>>partition(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto two partitions according to a predicate.PriorityQueue<T>replace(@NonNull T currentElement, @NonNull T newElement)Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.PriorityQueue<T>replaceAll(@NonNull T currentElement, @NonNull T newElement)Replaces all occurrences ofcurrentElementwithnewElement.PriorityQueue<T>scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)Computes a prefix scan of the elements of this Traversable.<U> PriorityQueue<U>scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)Produces a collection containing cumulative results of applying the operator from left to right.<U> PriorityQueue<U>scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)Produces a collection containing cumulative results of applying the operator from right to left.Iterator<? extends PriorityQueue<T>>slideBy(@NonNull java.util.function.Function<? super T,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<? extends PriorityQueue<T>>sliding(int size)Slides a window of a givensizeover thisTraversablewith a step size of 1.Iterator<? extends PriorityQueue<T>>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>>span(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.java.lang.StringstringPrefix()Returns the name of this Value type, which is used by toString().static <T> PriorityQueue<T>tabulate(int size, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> function)Returns aPriorityQueuecontainingsizevalues of a given Functionfunctionover a range of integer values from0tosize - 1.PriorityQueue<T>tail()Drops the first element of a non-emptyPriorityQueue.PriorityQueue<T>take(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.PriorityQueue<T>takeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.PriorityQueue<T>takeUntil(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.List<T>toList()Converts this to aList.<T1,T2>
Tuple2<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>>unzip(@NonNull java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)Unzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.<T1,T2,T3>
Tuple3<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>,? extends PriorityQueue<T3>>unzip3(@NonNull java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)Unzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.private PriorityQueue<T>with(Seq<PriorityQueueBase.Node<T>> forest, int size)<U> PriorityQueue<Tuple2<T,U>>zip(@NonNull java.lang.Iterable<? extends U> that)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable.<U> PriorityQueue<Tuple2<T,U>>zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.<U,R>
PriorityQueue<R>zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)Returns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function.PriorityQueue<Tuple2<T,java.lang.Integer>>zipWithIndex()Zips thisTraversablewith its indices, starting at 0.<U> PriorityQueue<U>zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)Zips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.-
Methods inherited from class io.vavr.collection.AbstractQueue
dequeueOption, dropUntil, enqueue, initOption, peek, peek, peekOption, reject, removeAll, removeAll, retainAll, tailOption, takeWhile, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isDistinct, isSequential, isSingleValued, iterator, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, 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, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
comparator
private final java.util.Comparator<? super T> comparator
-
forest
private final Seq<PriorityQueueBase.Node<T>> forest
-
size
private final int size
-
-
Constructor Detail
-
PriorityQueue
private PriorityQueue(java.util.Comparator<? super T> comparator, Seq<PriorityQueueBase.Node<T>> forest, int size)
-
-
Method Detail
-
with
private PriorityQueue<T> with(Seq<PriorityQueueBase.Node<T>> forest, int size)
-
collect
public <R> PriorityQueue<R> collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)
Description copied from interface:TraversableApplies aPartialFunctionto all elements that are defined for it and collects the results.For each element in iteration order, the function is first tested:
IfpartialFunction.isDefinedAt(element)true, the element is mapped to typeR:R newElement = partialFunction.apply(element)Note: If this
Traversableis ordered (i.e., extendsOrdered), the caller must ensure that the resulting elements are comparable (i.e., implementComparable).- Specified by:
collectin interfaceTraversable<T>- Type Parameters:
R- the type of elements in the resultingTraversable- Parameters:
partialFunction- a function that may not be defined for all elements of this traversable- Returns:
- a new
Traversablecontaining the results of applying the partial function
-
enqueue
public PriorityQueue<T> enqueue(T element)
Enqueues a new element.- Specified by:
enqueuein classAbstractQueue<T,PriorityQueue<T>>- Parameters:
element- The new element- Returns:
- a new
PriorityQueueinstance, containing the new element
-
enqueueAll
public PriorityQueue<T> 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.- Specified by:
enqueueAllin classAbstractQueue<T,PriorityQueue<T>>- Parameters:
elements- AnPriorityQueueof elements, may be empty- Returns:
- a new
PriorityQueueinstance, containing the new elements - Throws:
java.lang.NullPointerException- if elements is null
-
head
public T head()
Returns the first element of a non-emptyPriorityQueue.- Specified by:
headin interfaceTraversable<T>- Returns:
- The first element of this
PriorityQueue. - Throws:
java.util.NoSuchElementException- if this is empty
-
tail
public PriorityQueue<T> tail()
Drops the first element of a non-emptyPriorityQueue.- Specified by:
tailin interfaceTraversable<T>- Specified by:
tailin classAbstractQueue<T,PriorityQueue<T>>- Returns:
- A new instance of PriorityQueue containing all elements except the first.
- Throws:
java.lang.UnsupportedOperationException- if this is empty
-
dequeue
public Tuple2<T,PriorityQueue<T>> dequeue()
Description copied from class:AbstractQueueRemoves an element from this Queue.- Overrides:
dequeuein classAbstractQueue<T,PriorityQueue<T>>- Returns:
- a tuple containing the first element and the remaining elements of this Queue
-
merge
public PriorityQueue<T> merge(PriorityQueue<T> target)
Merges this PriorityQueue with another PriorityQueue. Both queues must use the same comparator.- Parameters:
target- A PriorityQueue- Returns:
- A new PriorityQueue containing elements from both queues in priority order.
-
isAsync
public boolean isAsync()
APriorityQueueis computed synchronously.
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableChecks if this Traversable contains no elements.
-
isLazy
public boolean isLazy()
APriorityQueueis computed eagerly.
-
isOrdered
public boolean isOrdered()
Description copied from interface:TraversableIndicates whether this Traversable is ordered according to its natural or specified order.- Specified by:
isOrderedin interfaceTraversable<T>- Returns:
trueif this Traversable is ordered,falseotherwise
-
empty
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> empty()
Returns the empty PriorityQueue.- Type Parameters:
T- Component type- Returns:
- The empty PriorityQueue.
-
empty
public static <T> PriorityQueue<T> empty(java.util.Comparator<? super T> comparator)
Returns an empty PriorityQueue with the given comparator.- Type Parameters:
T- Component type- Parameters:
comparator- The comparator used to order the elements- Returns:
- The empty PriorityQueue.
-
collector
public static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,PriorityQueue<T>> collector()
Returns aCollectorwhich may be used in conjunction withStream.collect(Collector)to obtain aPriorityQueue<T>.- Type Parameters:
T- Component type of thePriorityQueue.- Returns:
- A
PriorityQueue<T>Collector.
-
narrow
public static <T> PriorityQueue<T> narrow(PriorityQueue<? extends T> queue)
Narrows aPriorityQueue<? extends T>toPriorityQueue<T>via a type-safe cast. Safe here because the queue is immutable and no elements can be added that would violate the type (covariance)- Type Parameters:
T- the target element type- Parameters:
queue- the queue to narrow- Returns:
- the same queue viewed as
PriorityQueue<T>
-
of
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of(T element)
Returns a singletonPriorityQueue, i.e. aPriorityQueueof one element.- Type Parameters:
T- Component type- Parameters:
element- The element- Returns:
- A new PriorityQueue instance containing the given element
-
of
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of(T... elements)
Creates a PriorityQueue of the given elements.- Type Parameters:
T- Component type- Parameters:
elements- Zero or more elements.- Returns:
- A PriorityQueue containing the given elements.
- Throws:
java.lang.NullPointerException- if elements is null
-
of
public static <T> PriorityQueue<T> of(java.util.Comparator<? super T> comparator, T element)
Returns a singletonPriorityQueue, i.e. aPriorityQueueof one element with the given comparator.- Type Parameters:
T- Component type- Parameters:
comparator- The comparator used to order the elementselement- The element- Returns:
- A new PriorityQueue instance containing the given element
-
of
public static <T> PriorityQueue<T> of(@NonNull java.util.Comparator<? super T> comparator, T @NonNull ... elements)
Creates a PriorityQueue of the given elements with the given comparator.- Type Parameters:
T- Component type- Parameters:
comparator- The comparator used to order the elementselements- Zero or more elements.- Returns:
- A PriorityQueue containing the given elements.
- Throws:
java.lang.NullPointerException- if comparator or elements is null
-
ofAll
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll(@NonNull java.lang.Iterable<? extends T> elements)
Creates a PriorityQueue of the given elements.- Type Parameters:
T- Component type- Parameters:
elements- An Iterable of elements.- Returns:
- A PriorityQueue containing the given elements in priority order.
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static <T> PriorityQueue<T> ofAll(@NonNull java.util.Comparator<? super T> comparator, @NonNull java.lang.Iterable<? extends T> elements)
Creates a PriorityQueue of the given elements with the given comparator.- Type Parameters:
T- Component type- Parameters:
comparator- The comparator used to order the elementselements- An Iterable of elements.- Returns:
- A PriorityQueue containing the given elements in priority order.
- Throws:
java.lang.NullPointerException- if comparator or elements is null
-
ofAll
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll(java.util.stream.Stream<? extends T> javaStream)
Creates a PriorityQueue from aStream.- Type Parameters:
T- Component type of the Stream.- Parameters:
javaStream- AStream- Returns:
- A PriorityQueue containing the given elements in priority order.
-
ofAll
public static <T> PriorityQueue<T> ofAll(java.util.Comparator<? super T> comparator, java.util.stream.Stream<? extends T> javaStream)
Creates a PriorityQueue from aStreamwith the given comparator.- Type Parameters:
T- Component type of the Stream.- Parameters:
comparator- The comparator used to order the elementsjavaStream- AStream- Returns:
- A PriorityQueue containing the given elements in priority order.
-
tabulate
@GwtIncompatible public static <T> PriorityQueue<T> tabulate(int size, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> function)
Returns aPriorityQueuecontainingsizevalues of a given Functionfunctionover a range of integer values from0tosize - 1.- Type Parameters:
T- Component type of thePriorityQueue- Parameters:
size- The number of elements in thePriorityQueuefunction- The Function computing element values- Returns:
- A
PriorityQueueconsisting of elementsfunction(0),function(1), ..., function(size - 1) - Throws:
java.lang.NullPointerException- iffunctionis null
-
fill
@GwtIncompatible public static <T> PriorityQueue<T> fill(int size, @NonNull java.util.function.Supplier<? extends T> supplier)
- Type Parameters:
T- Component type of thePriorityQueue- Parameters:
size- The number of elements in thePriorityQueuesupplier- The Supplier computing element values- Returns:
- A
PriorityQueueof sizesize, where each element contains the result supplied bysupplier. - Throws:
java.lang.NullPointerException- ifsupplieris null
-
fill
@GwtIncompatible public static <T> PriorityQueue<T> fill(int size, T element)
- Type Parameters:
T- Component type of thePriorityQueue- Parameters:
size- The number of elements in thePriorityQueueelement- The element- Returns:
- A
PriorityQueueof sizesize, where each element is the givenelement.
-
distinct
public PriorityQueue<T> distinct()
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.- Specified by:
distinctin interfaceTraversable<T>- Returns:
- a new
Traversablewithout duplicate elements
-
distinctBy
public PriorityQueue<T> distinctBy(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceTraversable<T>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
public <U> PriorityQueue<T> distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceTraversable<T>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
drop
public PriorityQueue<T> drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropin interfaceTraversable<T>- Parameters:
n- the number of elements to drop- Returns:
- a new instance excluding the first
nelements
-
dropRight
public PriorityQueue<T> dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropRightin interfaceTraversable<T>- Parameters:
n- the number of elements to drop from the end- Returns:
- a new instance excluding the last
nelements
-
dropWhile
public PriorityQueue<T> 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>- Specified by:
dropWhilein classAbstractQueue<T,PriorityQueue<T>>- Parameters:
predicate- a condition tested on each element- Returns:
- a new instance starting from the first element not matching the predicate
-
filter
public PriorityQueue<T> filter(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.- Specified by:
filterin interfaceTraversable<T>- Parameters:
predicate- the condition to test elements- Returns:
- a traversable with elements matching the predicate
-
flatMap
public <U> PriorityQueue<U> flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Description copied from interface:TraversableTransforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.- Specified by:
flatMapin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resulting Traversable- Parameters:
mapper- a function mapping elements to iterables- Returns:
- a new Traversable containing all elements produced by applying
mapperand flattening
-
flatMap
public <U> PriorityQueue<U> flatMap(@NonNull java.util.Comparator<U> comparator, @NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function and flattened with the given comparator.- Type Parameters:
U- The result type- Parameters:
comparator- The comparator used to order the elementsmapper- A function which maps elements of this PriorityQueue to Iterables of type U- Returns:
- A new PriorityQueue
- Throws:
java.lang.NullPointerException- if comparator or mapper is null
-
foldRight
public <U> U foldRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> accumulator)Accumulates the elements of thisPriorityQueueby successively calling the given functionffrom the right, starting with a valuezeroof type B.Example:
PriorityQueue.of("a", "b", "c").foldRight("", (x, xs) -> x + xs) = "abc"- Specified by:
foldRightin interfaceFoldable<T>- Specified by:
foldRightin interfaceTraversable<T>- Type Parameters:
U- the type of the accumulated result- Parameters:
zero- Value to start the accumulation with.accumulator- The accumulator function.- Returns:
- an accumulated version of this.
- Throws:
java.lang.NullPointerException- iffis null
-
groupBy
public <C> Map<C,? extends PriorityQueue<T>> groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceTraversable<T>- Type Parameters:
C- The type of the group keys- Parameters:
classifier- A function that assigns each element to a group- Returns:
- A map where each key corresponds to a group of elements
- See Also:
Traversable.arrangeBy(Function)
-
grouped
public Iterator<? extends PriorityQueue<T>> grouped(int size)
Description copied from interface:TraversableSplits thisTraversableinto consecutive blocks of the given size.Let
lengthbe the number of elements in thisTraversable:- If empty, the resulting
Iteratoris empty. - If
size <= length, the resultingIteratorcontainslength / sizeblocks of sizesizeand possibly a final smaller block of sizelength % size. - If
size > length, the resultingIteratorcontains a single block of sizelength.
Examples:
[].grouped(1) = [] [].grouped(0) throws [].grouped(-1) throws [1,2,3,4].grouped(2) = [[1,2],[3,4]] [1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]] [1,2,3,4].grouped(5) = [[1,2,3,4]]Note:
grouped(size)is equivalent tosliding(size, size).- Specified by:
groupedin interfaceTraversable<T>- Parameters:
size- the block size; must be positive- Returns:
- an
Iteratorover blocks of elements
- If empty, the resulting
-
hasDefiniteSize
public boolean hasDefiniteSize()
Checks if thisPriorityQueueis known to have a finite size.This method should be implemented by classes only, i.e. not by interfaces.
- Specified by:
hasDefiniteSizein interfaceTraversable<T>- Returns:
- true, if this
PriorityQueueis known to have a finite size, false otherwise.
-
init
public PriorityQueue<T> init()
Dual of tail(), returning all elements except the last.- Specified by:
initin interfaceTraversable<T>- Specified by:
initin classAbstractQueue<T,PriorityQueue<T>>- Returns:
- a new instance containing all elements except the last.
- Throws:
java.lang.UnsupportedOperationException- if this is empty
-
isTraversableAgain
public boolean isTraversableAgain()
Checks if thisPriorityQueuecan be repeatedly traversed.This method should be implemented by classes only, i.e. not by interfaces.
- Specified by:
isTraversableAgainin interfaceTraversable<T>- Returns:
- true, if this
PriorityQueueis known to be traversable repeatedly, false otherwise.
-
last
public T last()
Description copied from interface:TraversableReturns the last element of this Traversable.- Specified by:
lastin interfaceTraversable<T>- Returns:
- the last element
-
length
public int length()
Computes the number of elements of thisPriorityQueue.Same as
Traversable.size().- Specified by:
lengthin interfaceTraversable<T>- Returns:
- the number of elements
-
map
public <U> PriorityQueue<U> map(@NonNull java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined.
-
mapTo
public <U> PriorityQueue<U> mapTo(U value)
Description copied from interface:ValueMaps the underlying value to another fixed value.
-
mapToVoid
public PriorityQueue<java.lang.Void> mapToVoid()
Description copied from interface:ValueMaps the underlying value to Void
-
map
public <U> PriorityQueue<U> map(@NonNull java.util.Comparator<U> comparator, @NonNull java.util.function.Function<? super T,? extends U> mapper)
Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function with the given comparator.- Type Parameters:
U- The result type- Parameters:
comparator- The comparator used to order the elementsmapper- A function which maps elements of this PriorityQueue to elements of type U- Returns:
- A new PriorityQueue
- Throws:
java.lang.NullPointerException- if comparator or mapper is null
-
orElse
public PriorityQueue<T> orElse(java.lang.Iterable<? extends T> other)
Returns thisPriorityQueueif it is nonempty, otherwisePriorityQueuecreated from iterable, using existing comparator.- Specified by:
orElsein interfaceTraversable<T>- Parameters:
other- An alternativeTraversable- Returns:
- this
PriorityQueueif it is nonempty, otherwisePriorityQueuecreated from iterable, using existing comparator.
-
orElse
public PriorityQueue<T> orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns thisPriorityQueueif it is nonempty, otherwisePriorityQueuecreated from result of evaluating supplier, using existing comparator.- Specified by:
orElsein interfaceTraversable<T>- Parameters:
supplier- An alternativeTraversable- Returns:
- this
PriorityQueueif it is nonempty, otherwisePriorityQueuecreated from result of evaluating supplier, using existing comparator.
-
partition
public Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> partition(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto two partitions according to a predicate.The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.
- Specified by:
partitionin interfaceTraversable<T>- Parameters:
predicate- a predicate used to classify elements- Returns:
- a
Tuple2containing the two resultingTraversableinstances
-
replace
public PriorityQueue<T> replace(@NonNull T currentElement, @NonNull T newElement)
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.- Specified by:
replacein interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with the first occurrence of
currentElementreplaced bynewElement
-
replaceAll
public PriorityQueue<T> replaceAll(@NonNull T currentElement, @NonNull T newElement)
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with all occurrences of
currentElementreplaced bynewElement
-
scan
public PriorityQueue<T> scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.- Specified by:
scanin interfaceTraversable<T>- Parameters:
zero- the neutral element for the operatoroperation- an associative binary operator- Returns:
- a new Traversable containing the prefix scan of the elements
-
scanLeft
public <U> PriorityQueue<U> scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from left to right.Will not terminate for infinite collections. The results may vary across runs unless the collection is ordered.
- Specified by:
scanLeftin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to the intermediate result and each element- Returns:
- a new Traversable containing the cumulative results
-
scanRight
public <U> PriorityQueue<U> scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from right to left.The head of the resulting collection is the last cumulative result. Will not terminate for infinite collections. Results may vary across runs unless the collection is ordered.
- Specified by:
scanRightin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to each element and the intermediate result- Returns:
- a new Traversable containing the cumulative results
-
slideBy
public Iterator<? extends PriorityQueue<T>> slideBy(@NonNull java.util.function.Function<? super T,?> classifier)
Description copied from interface:TraversablePartitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Each window contains elements with the same class, as determined by
classifier. Two consecutive elements belong to the same window only ifclassifierreturns equal values for both. Otherwise, the current window ends and a new window begins with the next element.Examples:
[].slideBy(Function.identity()) = [] [1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]] [1,2,3,10,12,5,7,20,29].slideBy(x -> x / 10) = [[1,2,3],[10,12],[5,7],[20,29]]- Specified by:
slideByin interfaceTraversable<T>- Parameters:
classifier- A function classifying elements into groups- Returns:
- An
Iteratorof windows (grouped elements)
-
sliding
public Iterator<? extends PriorityQueue<T>> sliding(int size)
Description copied from interface:TraversableSlides a window of a givensizeover thisTraversablewith a step size of 1.This is equivalent to calling
Traversable.sliding(int, int)with a step size of 1.- Specified by:
slidingin interfaceTraversable<T>- Parameters:
size- a positive window size- Returns:
- An
Iteratorof windows, each containing up tosizeelements
-
sliding
public Iterator<? extends PriorityQueue<T>> sliding(int size, int step)
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover thisTraversable.Examples:
[].sliding(1, 1) = [] [1,2,3,4,5].sliding(2, 3) = [[1,2],[4,5]] [1,2,3,4,5].sliding(2, 4) = [[1,2],[5]] [1,2,3,4,5].sliding(2, 5) = [[1,2]] [1,2,3,4].sliding(5, 3) = [[1,2,3,4],[4]]- Specified by:
slidingin interfaceTraversable<T>- Parameters:
size- a positive window sizestep- a positive step size- Returns:
- an
Iteratorof windows with the given size and step
-
span
public Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> span(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.- Specified by:
spanin interfaceTraversable<T>- Parameters:
predicate- a predicate used to determine the prefix- Returns:
- a
Tuplecontaining the prefix and remainder
-
take
public PriorityQueue<T> take(int n)
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takein interfaceTraversable<T>- Parameters:
n- the number of elements to take- Returns:
- a new
Traversablecontaining the firstnelements
-
takeRight
public PriorityQueue<T> takeRight(int n)
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takeRightin interfaceTraversable<T>- Parameters:
n- the number of elements to take from the end- Returns:
- a new
Traversablecontaining the lastnelements
-
takeUntil
public PriorityQueue<T> 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>- Specified by:
takeUntilin classAbstractQueue<T,PriorityQueue<T>>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements before the first one that satisfies the predicate
-
unzip
public <T1,T2> Tuple2<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>> unzip(@NonNull java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.- Specified by:
unzipin interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting pairsT2- type of the second element in the resulting pairs- Parameters:
unzipper- a function that maps elements of thisTraversableto pairs- Returns:
- a
Tuple2containing twoTraversablecollections with the split elements
-
unzip3
public <T1,T2,T3> Tuple3<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>,? extends PriorityQueue<T3>> unzip3(@NonNull java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.- Specified by:
unzip3in interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting triplesT2- type of the second element in the resulting triplesT3- type of the third element in the resulting triples- Parameters:
unzipper- a function that maps elements of thisTraversableto triples- Returns:
- a
Tuple3containing threeTraversablecollections with the split elements
-
zip
public <U> PriorityQueue<Tuple2<T,U>> zip(@NonNull java.lang.Iterable<? extends U> that)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable. Pairing stops when either collection runs out of elements; any remaining elements in the longer collection are ignored.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pair- Returns:
- a new
Traversablecontaining pairs of corresponding elements
-
zipWith
public <U,R> PriorityQueue<R> zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Description copied from interface:TraversableReturns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function. Pairing stops when either collection runs out of elements.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipWithin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second parameter of the mapperR- the type of elements in the resultingTraversable- Parameters:
that- anIterableproviding the second parameter of the mappermapper- a function that combines elements from this andthatinto a new element- Returns:
- a new
Traversablecontaining mapped elements
-
zipAll
public <U> PriorityQueue<Tuple2<T,U>> zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.The length of the resulting
Traversableis the maximum of the lengths of thisTraversableandthat.If this
Traversableis shorter thanthat,thisElemis used as a filler. Conversely, ifthatis shorter,thatElemis used.- Specified by:
zipAllin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pairthisElem- the element used to fill missing values if thisTraversableis shorter thanthatthatElem- the element used to fill missing values ifthatis shorter than thisTraversable- Returns:
- a new
Traversablecontaining pairs of elements, including fillers as needed
-
zipWithIndex
public PriorityQueue<Tuple2<T,java.lang.Integer>> zipWithIndex()
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceTraversable<T>- Returns:
- a new
Traversablecontaining each element paired with its index
-
zipWithIndex
public <U> PriorityQueue<U> zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Description copied from interface:TraversableZips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.- Specified by:
zipWithIndexin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resultingTraversable- Parameters:
mapper- a function mapping an element and its index to a new element- Returns:
- a new
Traversablecontaining the mapped elements
-
stringPrefix
public java.lang.String stringPrefix()
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin interfaceValue<T>- Returns:
- This type name.
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; }
-
comparator
public java.util.Comparator<T> comparator()
Description copied from interface:OrderedReturns the comparator that governs the ordering of elements in this collection. The returned comparator must be consistent with the collection's iteration order.- Specified by:
comparatorin interfaceOrdered<T>- Returns:
- the comparator defining the element order
-
-