public final class PriorityQueue<T> extends java.lang.Object implements java.io.Serializable, Ordered<T>
Modifier and Type | Method and Description |
---|---|
<R> PriorityQueue<R> |
collect(PartialFunction<? super T,? extends R> partialFunction)
Collects all elements that are in the domain of the given
partialFunction by mapping the elements to type R . |
static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,PriorityQueue<T>> |
collector()
Returns a
Collector which may be used in conjunction with
Stream.collect(Collector) to obtain a PriorityQueue<T> . |
java.util.Comparator<T> |
comparator()
Returns the comparator which defines the order of the elements contained in this collection.
|
Tuple2<T,PriorityQueue<T>> |
dequeue()
Removes an element from this Queue.
|
Option<Tuple2<T,Q>> |
dequeueOption()
Removes an element from this Queue.
|
PriorityQueue<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
PriorityQueue<T> |
distinctBy(java.util.Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> PriorityQueue<T> |
distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
PriorityQueue<T> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
PriorityQueue<T> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
PriorityQueue<T> |
dropUntil(java.util.function.Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
PriorityQueue<T> |
dropWhile(java.util.function.Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
static <T extends java.lang.Comparable<? super T>> |
empty()
Returns the empty PriorityQueue.
|
static <T> PriorityQueue<T> |
empty(java.util.Comparator<? super T> comparator) |
Q |
enqueue(T... elements)
Enqueues the given elements.
|
PriorityQueue<T> |
enqueue(T element)
Enqueues a new element.
|
PriorityQueue<T> |
enqueueAll(java.lang.Iterable<? extends T> elements)
Enqueues the given elements.
|
boolean |
equals(java.lang.Object o)
In Vavr there are four basic classes of collections:
Seq (sequential elements)
Set (distinct elements)
Map (indexed elements)
Multimap (indexed collections)
Two collection instances of these classes are equal if and only if both collections
belong to the same basic collection class (Seq, Set, Map or Multimap)
contain the same elements
have the same element order, if the collections are of type Seq
Two Map/Multimap elements, resp.
|
static <T> PriorityQueue<T> |
fill(int size,
java.util.function.Supplier<? extends T> supplier)
|
PriorityQueue<T> |
filter(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
<U> PriorityQueue<U> |
flatMap(java.util.Comparator<U> comparator,
java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper) |
<U> PriorityQueue<U> |
flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
<U> U |
foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> accumulator)
Accumulates the elements of this
PriorityQueue by successively calling the given function f from the right,
starting with a value zero of type B. |
<C> Map<C,? extends PriorityQueue<T>> |
groupBy(java.util.function.Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends PriorityQueue<T>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
boolean |
hasDefiniteSize()
Checks if this
PriorityQueue is known to have a finite size. |
int |
hashCode()
Returns the hash code of this collection.
|
T |
head()
Returns the first element of a non-empty
PriorityQueue . |
PriorityQueue<T> |
init()
Dual of tail(), returning all elements except the last.
|
Option<Q> |
initOption()
Dual of tailOption(), returning all elements except the last as
Option . |
boolean |
isAsync()
A
PriorityQueue is computed synchronously. |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
boolean |
isLazy()
A
PriorityQueue is computed eagerly. |
boolean |
isOrdered()
Checks if this Traversable is ordered
|
boolean |
isTraversableAgain()
Checks if this
PriorityQueue can be repeatedly traversed. |
int |
length()
Computes the number of elements of this
PriorityQueue . |
<U> PriorityQueue<U> |
map(java.util.Comparator<U> comparator,
java.util.function.Function<? super T,? extends U> mapper) |
<U> PriorityQueue<U> |
map(java.util.function.Function<? super T,? extends U> mapper)
Maps the elements of this
Traversable to elements of a new type preserving their order, if any. |
PriorityQueue<T> |
merge(PriorityQueue<T> target) |
static <T> PriorityQueue<T> |
narrow(PriorityQueue<? extends T> queue)
Narrows a widened
PriorityQueue<? extends T> to PriorityQueue<T>
by performing a type-safe cast. |
static <T> PriorityQueue<T> |
of(java.util.Comparator<? super T> comparator,
T... elements) |
static <T> PriorityQueue<T> |
of(java.util.Comparator<? super T> comparator,
T element) |
static <T extends java.lang.Comparable<? super T>> |
of(T... elements) |
static <T extends java.lang.Comparable<? super T>> |
of(T element) |
static <T> PriorityQueue<T> |
ofAll(java.util.Comparator<? super T> comparator,
java.lang.Iterable<? extends T> elements) |
static <T> PriorityQueue<T> |
ofAll(java.util.Comparator<? super T> comparator,
java.util.stream.Stream<? extends T> javaStream) |
static <T extends java.lang.Comparable<? super T>> |
ofAll(java.lang.Iterable<? extends T> elements) |
static <T extends java.lang.Comparable<? super T>> |
ofAll(java.util.stream.Stream<? extends T> javaStream) |
PriorityQueue<T> |
orElse(java.lang.Iterable<? extends T> other)
Returns this
PriorityQueue if it is nonempty,
otherwise PriorityQueue created from iterable, using existing comparator. |
PriorityQueue<T> |
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns this
PriorityQueue if it is nonempty,
otherwise PriorityQueue created from result of evaluating supplier, using existing comparator. |
Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> |
partition(java.util.function.Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct tarversables
according to a predicate. |
T |
peek()
Returns the first element without modifying it.
|
Q |
peek(java.util.function.Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
Option<T> |
peekOption()
Returns the first element without modifying the Queue.
|
Q |
removeAll(java.lang.Iterable<? extends T> elements) |
Q |
removeAll(java.util.function.Predicate<? super T> predicate) |
PriorityQueue<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
PriorityQueue<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Q |
retainAll(java.lang.Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
PriorityQueue<T> |
scan(T zero,
java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> PriorityQueue<U> |
scanLeft(U zero,
java.util.function.BiFunction<? super U,? super T,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
<U> PriorityQueue<U> |
scanRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
Iterator<? extends PriorityQueue<T>> |
slideBy(java.util.function.Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable . |
Iterator<? extends PriorityQueue<T>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int) . |
Iterator<? extends PriorityQueue<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> |
span(java.util.function.Predicate<? super T> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
java.lang.String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
static <T> PriorityQueue<T> |
tabulate(int size,
java.util.function.Function<? super java.lang.Integer,? extends T> function)
Returns a
PriorityQueue containing size values of a given Function function
over a range of integer values from 0 to size - 1 . |
PriorityQueue<T> |
tail()
Drops the first element of a non-empty
PriorityQueue . |
Option<Q> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
PriorityQueue<T> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
PriorityQueue<T> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
PriorityQueue<T> |
takeUntil(java.util.function.Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
Q |
takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
List<T> |
toList()
Converts this to a
List . |
java.lang.String |
toString()
Clarifies that values have a proper toString() method implemented.
|
<T1,T2> Tuple2<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>> |
unzip(java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
<T1,T2,T3> Tuple3<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>,? extends PriorityQueue<T3>> |
unzip3(java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
<U> PriorityQueue<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> PriorityQueue<Tuple2<T,U>> |
zipAll(java.lang.Iterable<? extends U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
<U,R> PriorityQueue<R> |
zipWith(java.lang.Iterable<? extends U> that,
java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
PriorityQueue<Tuple2<T,java.lang.Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
<U> PriorityQueue<U> |
zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, get, headOption, isDistinct, isSequential, isSingleValued, iterator, last, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
fold, reduce, reduceOption
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, narrow, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, 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, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
public <R> PriorityQueue<R> collect(PartialFunction<? super T,? extends R> partialFunction)
Traversable
partialFunction
by mapping the elements to type R
.
More specifically, for each of this elements in iteration order first it is checked
partialFunction.isDefinedAt(element)
If the elements makes it through that filter, the mapped instance is added to the result collection
R newElement = partialFunction.apply(element)
Note:If this Traversable
is ordered (i.e. extends Ordered
,
the caller of collect
has to ensure that the elements are comparable (i.e. extend Comparable
).collect
in interface Traversable<T>
R
- The new element typepartialFunction
- A function that is not necessarily defined of all elements of this traversable.Traversable
instance containing elements of type R
public PriorityQueue<T> enqueue(T element)
element
- The new elementPriorityQueue
instance, containing the new elementpublic PriorityQueue<T> enqueueAll(java.lang.Iterable<? extends T> elements)
elements
- An PriorityQueue
of elements, may be emptyPriorityQueue
instance, containing the new elementsjava.lang.NullPointerException
- if elements is nullpublic T head()
PriorityQueue
.head
in interface Traversable<T>
PriorityQueue
.java.util.NoSuchElementException
- if this is emptypublic PriorityQueue<T> tail()
PriorityQueue
.tail
in interface Traversable<T>
java.lang.UnsupportedOperationException
- if this is emptypublic Tuple2<T,PriorityQueue<T>> dequeue()
public PriorityQueue<T> merge(PriorityQueue<T> target)
public boolean isAsync()
PriorityQueue
is computed synchronously.public boolean isEmpty()
Traversable
public boolean isLazy()
PriorityQueue
is computed eagerly.public boolean isOrdered()
Traversable
isOrdered
in interface Traversable<T>
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> empty()
T
- Component typepublic static <T> PriorityQueue<T> empty(java.util.Comparator<? super T> comparator)
public static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,PriorityQueue<T>> collector()
Collector
which may be used in conjunction with
Stream.collect(Collector)
to obtain a PriorityQueue<T>
.T
- Component type of the PriorityQueue
.PriorityQueue<T>
Collector.public static <T> PriorityQueue<T> narrow(PriorityQueue<? extends T> queue)
PriorityQueue<? extends T>
to PriorityQueue<T>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.T
- Component type of the PriorityQueue
.queue
- An PriorityQueue
.PriorityQueue
instance as narrowed type PriorityQueue<T>
.public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of(T element)
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of(T... elements)
public static <T> PriorityQueue<T> of(java.util.Comparator<? super T> comparator, T element)
public static <T> PriorityQueue<T> of(java.util.Comparator<? super T> comparator, T... elements)
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll(java.lang.Iterable<? extends T> elements)
public static <T> PriorityQueue<T> ofAll(java.util.Comparator<? super T> comparator, java.lang.Iterable<? extends T> elements)
public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll(java.util.stream.Stream<? extends T> javaStream)
public static <T> PriorityQueue<T> ofAll(java.util.Comparator<? super T> comparator, java.util.stream.Stream<? extends T> javaStream)
@GwtIncompatible public static <T> PriorityQueue<T> tabulate(int size, java.util.function.Function<? super java.lang.Integer,? extends T> function)
PriorityQueue
containing size
values of a given Function function
over a range of integer values from 0
to size - 1
.T
- Component type of the PriorityQueue
size
- The number of elements in the PriorityQueue
function
- The Function computing element valuesPriorityQueue
consisting of elements function(0),function(1), ..., function(size - 1)
java.lang.NullPointerException
- if function
is null@GwtIncompatible public static <T> PriorityQueue<T> fill(int size, java.util.function.Supplier<? extends T> supplier)
T
- Component type of the PriorityQueue
size
- The number of elements in the PriorityQueue
supplier
- The Supplier computing element valuesPriorityQueue
of size size
, where each element contains the result supplied by supplier
.java.lang.NullPointerException
- if supplier
is nullpublic PriorityQueue<T> distinct()
Traversable
equals
.distinct
in interface Traversable<T>
Traversable
containing this elements without duplicatespublic PriorityQueue<T> distinctBy(java.util.Comparator<? super T> comparator)
Traversable
comparator
.distinctBy
in interface Traversable<T>
comparator
- A comparatorTraversable
containing this elements without duplicatespublic <U> PriorityQueue<T> distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Traversable
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy
in interface Traversable<T>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatespublic PriorityQueue<T> drop(int n)
Traversable
drop
in interface Traversable<T>
n
- The number of elements to drop.public PriorityQueue<T> dropRight(int n)
Traversable
dropRight
in interface Traversable<T>
n
- The number of elements to drop.public PriorityQueue<T> dropUntil(java.util.function.Predicate<? super T> predicate)
Traversable
dropUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.public PriorityQueue<T> dropWhile(java.util.function.Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropUntil(predicate.negate())
.
It is intended to be used with method references, which cannot be negated directly.
dropWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.public PriorityQueue<T> filter(java.util.function.Predicate<? super T> predicate)
Traversable
filter
in interface Traversable<T>
predicate
- A predicatepublic <U> PriorityQueue<U> flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Traversable
flatMap
in interface Traversable<T>
U
- The resulting component type.mapper
- A mapperpublic <U> PriorityQueue<U> flatMap(java.util.Comparator<U> comparator, java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
public <U> U foldRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> accumulator)
PriorityQueue
by successively calling the given function f
from the right,
starting with a value zero
of type B.
Example: PriorityQueue.of("a", "b", "c").foldRight("", (x, xs) -> x + xs) = "abc"
foldRight
in interface Foldable<T>
foldRight
in interface Traversable<T>
U
- the type of the folded valuezero
- Value to start the accumulation with.accumulator
- The accumulator function.java.lang.NullPointerException
- if f
is nullpublic <C> Map<C,? extends PriorityQueue<T>> groupBy(java.util.function.Function<? super T,? extends C> classifier)
Traversable
groupBy
in interface Traversable<T>
C
- classified class typeclassifier
- A function which classifies elements into classesTraversable.arrangeBy(Function)
public Iterator<? extends PriorityQueue<T>> grouped(int size)
Traversable
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].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]]
Please note that grouped(int)
is a special case of Traversable.sliding(int, int), i.e.
grouped(size)
is the same as sliding(size, size)
.grouped
in interface Traversable<T>
size
- a positive block sizepublic boolean hasDefiniteSize()
PriorityQueue
is known to have a finite size.
This method should be implemented by classes only, i.e. not by interfaces.
hasDefiniteSize
in interface Traversable<T>
PriorityQueue
is known to have a finite size, false otherwise.public PriorityQueue<T> init()
init
in interface Traversable<T>
java.lang.UnsupportedOperationException
- if this is emptypublic boolean isTraversableAgain()
PriorityQueue
can be repeatedly traversed.
This method should be implemented by classes only, i.e. not by interfaces.
isTraversableAgain
in interface Traversable<T>
PriorityQueue
is known to be traversable repeatedly, false otherwise.public int length()
PriorityQueue
.
Same as Traversable.size()
.
length
in interface Traversable<T>
public <U> PriorityQueue<U> map(java.util.function.Function<? super T,? extends U> mapper)
Traversable
Traversable
to elements of a new type preserving their order, if any.public <U> PriorityQueue<U> map(java.util.Comparator<U> comparator, java.util.function.Function<? super T,? extends U> mapper)
public PriorityQueue<T> orElse(java.lang.Iterable<? extends T> other)
PriorityQueue
if it is nonempty,
otherwise PriorityQueue
created from iterable, using existing comparator.orElse
in interface Traversable<T>
other
- An alternative Traversable
PriorityQueue
if it is nonempty,
otherwise PriorityQueue
created from iterable, using existing comparator.public PriorityQueue<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
PriorityQueue
if it is nonempty,
otherwise PriorityQueue
created from result of evaluating supplier, using existing comparator.orElse
in interface Traversable<T>
supplier
- An alternative Traversable
PriorityQueue
if it is nonempty,
otherwise PriorityQueue
created from result of evaluating supplier, using existing comparator.public Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> partition(java.util.function.Predicate<? super T> predicate)
Traversable
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.partition
in interface Traversable<T>
predicate
- A predicate which classifies an element if it is in the first or the second traversable.Traversable
contains all elements that satisfy the given predicate
, the second Traversable
contains all elements that don't. The original order of elements is preserved.public PriorityQueue<T> replace(T currentElement, T newElement)
Traversable
replace
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public PriorityQueue<T> replaceAll(T currentElement, T newElement)
Traversable
replaceAll
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public PriorityQueue<T> scan(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Traversable
scan
in interface Traversable<T>
zero
- neutral element for the operator opoperation
- the associative operator for the scanpublic <U> PriorityQueue<U> scanLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> operation)
Traversable
scanLeft
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementpublic <U> PriorityQueue<U> scanRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> operation)
Traversable
scanRight
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementpublic Iterator<? extends PriorityQueue<T>> slideBy(java.util.function.Function<? super T,?> classifier)
Traversable
Traversable
.
Each window contains elements with the same class, as determined by classifier
. Two consecutive
values in this Traversable
will be in the same window only if classifier
returns equal
values for them. Otherwise, the values will constitute the last element of the previous window and the
first element of the next window.
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]]
slideBy
in interface Traversable<T>
classifier
- A function which classifies elements into classespublic Iterator<? extends PriorityQueue<T>> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.sliding
in interface Traversable<T>
size
- a positive window sizepublic Iterator<? extends PriorityQueue<T>> sliding(int size, int step)
Traversable
size
and step
size over this Traversable
.
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]]
sliding
in interface Traversable<T>
size
- a positive window sizestep
- a positive step sizepublic Tuple2<? extends PriorityQueue<T>,? extends PriorityQueue<T>> span(java.util.function.Predicate<? super T> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Traversable<T>
predicate
- A predicate.Tuple
containing the longest prefix of elements that satisfy p and the remainder.public PriorityQueue<T> take(int n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n)))
but does not throw if n < 0
or
n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
take
in interface Traversable<T>
n
- The number of elements to take.public PriorityQueue<T> takeRight(int n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not
throw if n < 0
or n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
takeRight
in interface Traversable<T>
n
- The number of elements to take.public PriorityQueue<T> takeUntil(java.util.function.Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
takeUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.public <T1,T2> Tuple2<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>> unzip(java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Traversable
unzip
in interface Traversable<T>
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipperunzipper
- a function which converts elements of this to pairspublic <T1,T2,T3> Tuple3<? extends PriorityQueue<T1>,? extends PriorityQueue<T2>,? extends PriorityQueue<T3>> unzip3(java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversable
unzip3
in interface Traversable<T>
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipperunzipper
- a function which converts elements of this to pairspublic <U> PriorityQueue<Tuple2<T,U>> zip(java.lang.Iterable<? extends U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.public <U,R> PriorityQueue<R> zipWith(java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith
in interface Traversable<T>
U
- The type of the second parameter of the mapper.R
- The type of the mapped elements.that
- The Iterable providing the second parameter of the mapper.mapper
- a mapper.that
iterable.public <U> PriorityQueue<Tuple2<T,U>> zipAll(java.lang.Iterable<? extends U> that, T thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.public PriorityQueue<Tuple2<T,java.lang.Integer>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<T>
public <U> PriorityQueue<U> zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex
in interface Traversable<T>
U
- The type of the mapped elements.mapper
- a mapper.that
iterable.public java.lang.String stringPrefix()
Value
stringPrefix
in interface Value<T>
public boolean equals(java.lang.Object o)
Traversable
Notes:
public int hashCode()
Traversable
int hash = 1;
for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.
int hash = 1;
for (T t : this) { hash += Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.
public final class Hashed<K> {
private final K key;
private final Lazy<Integer> hashCode;
public Hashed(K key) {
this.key = key;
this.hashCode = Lazy.of(() -> Objects.hashCode(key));
}
public K key() {
return key;
}
@Override
public boolean equals(Object o) {
if (o == key) {
return true;
} else if (key != null && o instanceof Hashed) {
final Hashed that = (Hashed) o;
return key.equals(that.key);
} else {
return false;
}
}
@Override
public int hashCode() {
return hashCode.get();
}
@Override
public String toString() {
return "Hashed(" + (key == null ? "null" : key.toString()) + ")";
}
}
public java.util.Comparator<T> comparator()
Ordered
comparator
in interface Ordered<T>
public Option<Tuple2<T,Q>> dequeueOption()
None
if this Queue is empty, otherwise Some
Tuple
containing the first element and the remaining elements of this Queuepublic Q enqueue(T... elements)
elements
- Elements, may be emptyQueue
instance, containing the new elementsjava.lang.NullPointerException
- if elements is nullpublic T peek()
java.util.NoSuchElementException
- if this Queue is emptypublic Option<T> peekOption()
None
if this Queue is empty, otherwise a Some
containing the first elementpublic Option<Q> initOption()
Option
.initOption
in interface Traversable<T>
Some(Q)
or None
if this is empty.public Option<Q> tailOption()
Traversable
Option
.tailOption
in interface Traversable<T>
Some(traversable)
or None
if this is empty.public Q retainAll(java.lang.Iterable<? extends T> elements)
Traversable
retainAll
in interface Traversable<T>
elements
- Elements to be kept.public Q removeAll(java.lang.Iterable<? extends T> elements)
public Q removeAll(java.util.function.Predicate<? super T> predicate)
public Q takeWhile(java.util.function.Predicate<? super T> predicate)
Traversable
takeWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for the contained elements.public Q peek(java.util.function.Consumer<? super T> action)
Value
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.peek
in interface Traversable<T>
peek
in interface Value<T>
action
- The action that will be performed on the element(s).public java.lang.String toString()
Value
See Object.toString().
Copyright © 2017. All Rights Reserved.