public final class DoubleSpliterators
extends java.lang.Object
Spliterators
Modifier and Type | Class and Description |
---|---|
static class |
DoubleSpliterators.AbstractIndexBasedSpliterator
A skeletal implementation for a spliterator backed by an index based data store.
|
static class |
DoubleSpliterators.EarlyBindingSizeIndexBasedSpliterator
A skeletal implementation for a spliterator backed by an index based data store.
|
static class |
DoubleSpliterators.EmptySpliterator
A class returning no elements and a type-specific spliterator interface.
|
static class |
DoubleSpliterators.LateBindingSizeIndexBasedSpliterator
A skeletal implementation for a spliterator backed by an index based data store.
|
Modifier and Type | Field and Description |
---|---|
static int |
COLLECTION_SPLITERATOR_CHARACTERISTICS |
static DoubleSpliterators.EmptySpliterator |
EMPTY_SPLITERATOR
An empty spliterator.
|
static int |
LIST_SPLITERATOR_CHARACTERISTICS |
static int |
SET_SPLITERATOR_CHARACTERISTICS |
static int |
SORTED_SET_SPLITERATOR_CHARACTERISTICS |
Modifier and Type | Method and Description |
---|---|
static DoubleSpliterator |
asDoubleSpliterator(java.util.Spliterator i)
Wraps a standard spliterator into a type-specific spliterator.
|
static DoubleSpliterator |
asDoubleSpliterator(java.util.Spliterator i,
DoubleComparator comparatorOverride)
Wraps a standard spliterator into a type-specific spliterator.
|
static DoubleIterator |
asIterator(DoubleSpliterator spliterator)
Wrap a type-specific
Spliterator as a type-specific Iterator |
static DoubleSpliterator |
asSpliterator(DoubleIterator iter,
long size,
int additionalCharacterisitcs)
Wrap a type-specific
Iterator of a known size as a type-specific Spliterator
The returned spliterator will report
characteristics additionalCharacterisitcs ,
and for primitive types, Spliterator.NONNULL . |
static DoubleSpliterator |
asSpliteratorFromSorted(DoubleIterator iter,
long size,
int additionalCharacterisitcs,
DoubleComparator comparator)
Wrap a type-specific, sorted
Iterator of a known size as a type-specific Spliterator
It is the caller's responsibility to ensure the iterator's order
is actually sorted according to the comparator given. |
static DoubleSpliterator |
asSpliteratorFromSortedUnknownSize(DoubleIterator iter,
int additionalCharacterisitcs,
DoubleComparator comparator)
Wrap a type-specific, sorted
Iterator of an unknown size as a type-specific Spliterator
It is the caller's responsibility to ensure the iterator's order
is actually sorted according to the comparator given. |
static DoubleSpliterator |
asSpliteratorUnknownSize(DoubleIterator iter,
int characterisitcs)
Wrap a type-specific
Iterator of an unknown size as a type-specific Spliterator
The returned spliterator will report additionalCharacterisitcs ,
and for primitive types, Spliterator.NONNULL . |
static DoubleSpliterator |
concat(DoubleSpliterator... a)
Concatenates all spliterators contained in an array.
|
static DoubleSpliterator |
concat(DoubleSpliterator[] a,
int offset,
int length)
Concatenates a sequence of spliterators contained in an array.
|
static void |
onEachMatching(DoubleSpliterator spliterator,
java.util.function.DoublePredicate predicate,
java.util.function.DoubleConsumer action)
Perform the given
action on each element that matches the given predicate . |
static DoubleSpliterator |
singleton(double element)
Returns a spliterator that iterates just over the given element.
|
static DoubleSpliterator |
singleton(double element,
DoubleComparator comparator)
Returns a spliterator that iterates just over the given element.
|
static DoubleSpliterator |
wrap(ByteSpliterator spliterator)
Returns a spliterator backed by the specified byte spliterator.
|
static DoubleSpliterator |
wrap(CharSpliterator spliterator)
Returns a spliterator backed by the specified char spliterator.
|
static DoubleSpliterator |
wrap(double[] array)
Wraps the given array into a type-specific spliterator.
|
static DoubleSpliterator |
wrap(double[] array,
int offset,
int length)
Wraps the given part of an array into a type-specific spliterator.
|
static DoubleSpliterator |
wrap(double[] array,
int offset,
int length,
int additionalCharacteristics)
Wraps the given part of an array into a type-specific spliterator.
|
static DoubleSpliterator |
wrap(FloatSpliterator spliterator)
Returns a spliterator backed by the specified float spliterator.
|
static DoubleSpliterator |
wrap(IntSpliterator spliterator)
Returns a spliterator backed by the specified integer spliterator.
|
static DoubleSpliterator |
wrap(ShortSpliterator spliterator)
Returns a spliterator backed by the specified short spliterator.
|
static DoubleSpliterator |
wrapPreSorted(double[] array,
DoubleComparator comparator)
Wraps the given sorted array into a type-specific spliterator.
|
static DoubleSpliterator |
wrapPreSorted(double[] array,
int offset,
int length,
DoubleComparator comparator)
Wraps the given part of a sorted array into a type-specific spliterator.
|
static DoubleSpliterator |
wrapPreSorted(double[] array,
int offset,
int length,
int additionalCharacteristics,
DoubleComparator comparator)
Wraps the given part of a sorted array into a type-specific spliterator.
|
public static final int COLLECTION_SPLITERATOR_CHARACTERISTICS
public static final int LIST_SPLITERATOR_CHARACTERISTICS
public static final int SET_SPLITERATOR_CHARACTERISTICS
public static final int SORTED_SET_SPLITERATOR_CHARACTERISTICS
public static final DoubleSpliterators.EmptySpliterator EMPTY_SPLITERATOR
The class of this objects represent an abstract empty spliterator that can iterate as a type-specific spliterator.
public static DoubleSpliterator singleton(double element)
element
- the only element to be returned by a type-specific spliterator.element
.public static DoubleSpliterator singleton(double element, DoubleComparator comparator)
The Spliterator.getComparator()
method will return the given comparator.
This is within spec because sequences of size 1 are trivially sorted for any
comparison function.
element
- the only element to be returned by a type-specific spliterator.comparator
- the comparator to return when Spliterator.getComparator()
is called.element
.public static DoubleSpliterator wrap(double[] array, int offset, int length)
The type-specific spliterator returned by this method will iterate
length
times, advancing over consecutive elements of the given
array starting from the one with index offset
.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, and for primitive arrays, Spliterator.NONNULL
.
array
- an array to wrap into a type-specific spliterator.offset
- the first element of the array to be returned.length
- the number of elements to return.length
elements of array
starting at position offset
.public static DoubleSpliterator wrap(double[] array)
The type-specific spliterator returned by this method will advance over all elements of the given array.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, and for primitive arrays, Spliterator.NONNULL
.
array
- an array to wrap into a type-specific spliterator.array
.public static DoubleSpliterator wrap(double[] array, int offset, int length, int additionalCharacteristics)
The type-specific spliterator returned by this method will iterate
length
times, advancing over consecutive elements of the given
array starting from the one with index offset
.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, and for primitive arrays, Spliterator.NONNULL
,
on top of any additional characteristics given in additionalCharacteristics
(for example, if
the caller knows the backing array has distinct elements, they can pass Spliterator.DISTINCT
).
array
- an array to wrap into a type-specific spliterator.offset
- the first element of the array to be returned.length
- the number of elements to return.additionalCharacteristics
- any additional characteristics to report.length
elements of array
starting at position offset
.public static DoubleSpliterator wrapPreSorted(double[] array, int offset, int length, int additionalCharacteristics, DoubleComparator comparator)
It is the caller's responsibility to ensure the array is actually sorted using the comparator given.
The type-specific spliterator returned by this method will iterate
length
times, advancing over consecutive elements of the given
array starting from the one with index offset
.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, Spliterator.SORTED
, and for primitive arrays,
Spliterator.NONNULL
,
on top of any additional characteristics given in additionalCharacteristics
(for example, if
the caller knows the backing array has distinct elements, they can pass Spliterator.DISTINCT
).
array
- an array to wrap into a type-specific spliterator.offset
- the first element of the array to be returned.length
- the number of elements to return.additionalCharacteristics
- any additional characteristics to report.comparator
- the comparator the array was sorted with (or null
for natural ordering)length
elements of array
starting at position offset
.public static DoubleSpliterator wrapPreSorted(double[] array, int offset, int length, DoubleComparator comparator)
It is the caller's responsibility to ensure the array is actually sorted using the comparator given.
The type-specific spliterator returned by this method will iterate
length
times, advancing over consecutive elements of the given
array starting from the one with index offset
.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, Spliterator.SORTED
, and for primitive arrays,
Spliterator.NONNULL
.
array
- an array to wrap into a type-specific spliterator.offset
- the first element of the array to be returned.length
- the number of elements to return.comparator
- the comparator the array was sorted with (or null
for natural ordering)length
elements of array
starting at position offset
.public static DoubleSpliterator wrapPreSorted(double[] array, DoubleComparator comparator)
It is the caller's responsibility to ensure the array is actually sorted using the comparator given.
The type-specific spliterator returned by this method will advance over all elements of the given array.
The returned spliterator will report characteristics
Spliterator.SIZED
, Spliterator.SUBSIZED
,
Spliterator.ORDERED
, Spliterator.SORTED
, and for primitive arrays,
Spliterator.NONNULL
.
array
- an array to wrap into a type-specific spliterator.comparator
- the comparator the array was sorted with (or null
for natural ordering)length
elements of array
starting at position offset
.public static DoubleSpliterator asDoubleSpliterator(java.util.Spliterator i)
This method wraps a standard spliterator into a type-specific one which will handle the
type conversions for you. Of course, any attempt to wrap a spliterator returning the
instances of the wrong class will generate a ClassCastException
. The
returned spliterator is backed by i
: changes to one of the spliterators
will affect the other, too.
If i
is already type-specific, it will returned and no new object
will be generated.
i
- a spliterator.i
.public static DoubleSpliterator asDoubleSpliterator(java.util.Spliterator i, DoubleComparator comparatorOverride)
This method wraps a standard spliterator into a type-specific one which will handle the
type conversions for you. Of course, any attempt to wrap a spliterator returning the
instances of the wrong class will generate a ClassCastException
. The
returned spliterator is backed by i
: changes to one of the spliterators
will affect the other, too.
This method will cause the returned spliterator's Spliterator.getComparator()
method
to always return comparatorOverride
, regardless of what the wrapped spliterator's
getComparator()
method returns.
NOTE:This is mostly intended for supporting default implementations in interfaces that wrap JDK spliterators, and not a general purpose method.
If i
is already type-specific, this method will throw, as such spliterators already
have a getComparator()
that returns a properly typed comparator.
i
- a spliterator.comparatorOverride
- the comparator to return when Spliterator.getComparator()
i
.public static void onEachMatching(DoubleSpliterator spliterator, java.util.function.DoublePredicate predicate, java.util.function.DoubleConsumer action)
action
on each element that matches the given predicate
.
This is equivalent to java.util.stream.StreamSupport.stream(spliterator).filter(predicate).forEach(action)
(substitute the proper primitive stream as needed), except it may perform better (but no potential for parallelism).
public static DoubleSpliterator concat(DoubleSpliterator... a)
This method returns a spliterator that will enumerate in order the elements returned by all spliterators contained in the given array.
Note: Due to there being no way to ensure the Comparator
is consistent
between each inner spliterator, the returned spliterator's Spliterator.getComparator()
will always throw IllegalStateException
, even when if the current or even all
the inner spliterators are sorted.
a
- an array of spliterators.public static DoubleSpliterator concat(DoubleSpliterator[] a, int offset, int length)
This method returns a spliterator that will enumerate in order the elements returned
by a[offset]
, then those returned
by a[offset + 1]
, and so on up to
a[offset + length - 1]
.
Note: Due to there being no way to ensure the Comparator
is consistent
between each inner spliterator, the returned spliterator's Spliterator.getComparator()
will always throw IllegalStateException
, even when if the current or even all
the inner spliterators are sorted.
a
- an array of spliterators.offset
- the index of the first spliterator to concatenate.length
- the number of spliterators to concatenate.length
elements of a
starting at offset
.public static DoubleSpliterator asSpliterator(DoubleIterator iter, long size, int additionalCharacterisitcs)
Iterator
of a known size as a type-specific Spliterator
The returned spliterator will report
characteristics
additionalCharacterisitcs
,
and for primitive types, Spliterator.NONNULL
.
It will also report Spliterator.SIZED
, Spliterator.SUBSIZED
,
unless Spliterator.CONCURRENT
is to be reported, in which case these two
are not implicitly reported.
Because Iterator
is an inherently linear API, the returned spliterator will
yield limited performance gains when run in parallel contexts, as the returned spliterator's
Spliterator.trySplit()
will have linear runtime.
iter
- the type-specific Iterator
to wrapsize
- the number of elements the iterator will returnadditionalCharacterisitcs
- any additional characteristics to reportSpliterator
that will give the same elements the iterator will return.Spliterators.spliterator(java.util.Iterator, long, int)
public static DoubleSpliterator asSpliteratorFromSorted(DoubleIterator iter, long size, int additionalCharacterisitcs, DoubleComparator comparator)
Iterator
of a known size as a type-specific Spliterator
It is the caller's responsibility to ensure the iterator's order is actually sorted according to the comparator given.
The returned spliterator will report
characteristics
additionalCharacterisitcs
,
Spliterator.ORDERED
, Spliterator.SORTED
, and for primitive types,
Spliterator.NONNULL
.
It will also report Spliterator.SIZED
, Spliterator.SUBSIZED
,
unless Spliterator.CONCURRENT
is to be reported, in which case these two
are not implicitly reported.
Because Iterator
is an inherently linear API, the returned spliterator will
yield limited performance gains when run in parallel contexts, as the returned spliterator's
Spliterator.trySplit()
will have linear runtime.
iter
- the type-specific Iterator
to wrapsize
- the number of elements the iterator will returnadditionalCharacterisitcs
- any additional characteristics to reportcomparator
- the comparator the iterator is ordered on (or null
for natural ordering)Spliterator
that will give the same elements the iterator will return.public static DoubleSpliterator asSpliteratorUnknownSize(DoubleIterator iter, int characterisitcs)
Iterator
of an unknown size as a type-specific Spliterator
The returned spliterator will report additionalCharacterisitcs
,
and for primitive types, Spliterator.NONNULL
.
Because Iterator
is an inherently linear API, the returned spliterator will
yield limited performance gains when run in parallel contexts, as the returned spliterator's
Spliterator.trySplit()
will have linear runtime.
iter
- the type-specific Iterator
to wrapcharacterisitcs
- the characteristics to reportSpliterator
that will give the same elements the iterator will return.Spliterators.spliteratorUnknownSize(java.util.Iterator, int)
public static DoubleSpliterator asSpliteratorFromSortedUnknownSize(DoubleIterator iter, int additionalCharacterisitcs, DoubleComparator comparator)
Iterator
of an unknown size as a type-specific Spliterator
It is the caller's responsibility to ensure the iterator's order is actually sorted according to the comparator given.
The returned spliterator will report
characteristics
additionalCharacterisitcs
,
Spliterator.ORDERED
, Spliterator.SORTED
, and for primitive types,
Spliterator.NONNULL
.
Because Iterator
is an inherently linear API, the returned spliterator will
yield limited performance gains when run in parallel contexts, as the returned spliterator's
Spliterator.trySplit()
will have linear runtime.
iter
- the type-specific Iterator
to wrapadditionalCharacterisitcs
- the characteristics to reportcomparator
- the comparator the iterator is ordered on (or null
for natural ordering)Spliterator
that will give the same elements the iterator will return.public static DoubleIterator asIterator(DoubleSpliterator spliterator)
Spliterator
as a type-specific Iterator
spliterator
- the type-specific Spliterator
to wrapIterator
that will return the same elements the spliterator will give.Spliterators.iterator(java.util.Spliterator)
public static DoubleSpliterator wrap(ByteSpliterator spliterator)
Note: Due to the incompatibility of primitive Comparator
types,
the returned spliterator's Spliterator.getComparator()
will always
throw IllegalStateException
, even when the underlying spliterator is
sorted.
spliterator
- a byte spliterator.public static DoubleSpliterator wrap(ShortSpliterator spliterator)
Note: Due to the incompatibility of primitive Comparator
types,
the returned spliterator's Spliterator.getComparator()
will always
throw IllegalStateException
, even when the underlying spliterator is
sorted.
spliterator
- a short spliterator.public static DoubleSpliterator wrap(CharSpliterator spliterator)
WARNING: This is not the same as converting the source to a sequence
of code points. This returned instance literally performs (int)(charValue)
casts.
Surrogate pairs will be left as separate elements instead of combined into a single element
with the code point it represents.
Note: Due to the incompatibility of primitive Comparator
types,
the returned spliterator's Spliterator.getComparator()
will always
throw IllegalStateException
, even when the underlying spliterator is
sorted.
spliterator
- a char spliterator.public static DoubleSpliterator wrap(IntSpliterator spliterator)
Note: Due to the incompatibility of primitive Comparator
types,
the returned spliterator's Spliterator.getComparator()
will always
throw IllegalStateException
, even when the underlying spliterator is
sorted.
spliterator
- an integer spliterator.public static DoubleSpliterator wrap(FloatSpliterator spliterator)
Note: Due to the incompatibility of primitive Comparator
types,
the returned spliterator's Spliterator.getComparator()
will always
throw IllegalStateException
, even when the underlying spliterator is
sorted.
spliterator
- a float spliterator.