Class ShortSpliterators
public final class ShortSpliterators
extends java.lang.Object
- Since:
- 8.5.0
- Author:
- C. Sean Young <csyoung@google.com>
- See Also:
Spliterators
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShortSpliterators.AbstractIndexBasedSpliteratorA skeletal implementation for a spliterator backed by an index based data store.static classShortSpliterators.EarlyBindingSizeIndexBasedSpliteratorA skeletal implementation for a spliterator backed by an index based data store.static classShortSpliterators.EmptySpliteratorA class returning no elements and a type-specific spliterator interface.static classShortSpliterators.LateBindingSizeIndexBasedSpliteratorA skeletal implementation for a spliterator backed by an index based data store. -
Field Summary
Fields Modifier and Type Field Description static intCOLLECTION_SPLITERATOR_CHARACTERISTICSstatic ShortSpliterators.EmptySpliteratorEMPTY_SPLITERATORAn empty spliterator.static intLIST_SPLITERATOR_CHARACTERISTICSstatic intSET_SPLITERATOR_CHARACTERISTICSstatic intSORTED_SET_SPLITERATOR_CHARACTERISTICS -
Method Summary
Modifier and Type Method Description static it.unimi.dsi.fastutil.shorts.ShortIteratorasIterator(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator)Wrap a type-specificSpliteratoras a type-specificIteratorstatic it.unimi.dsi.fastutil.shorts.ShortSpliteratorasShortSpliterator(java.util.Spliterator i)Wraps a standard spliterator into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorasShortSpliterator(java.util.Spliterator i, ShortComparator comparatorOverride)Wraps a standard spliterator into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorasSpliterator(it.unimi.dsi.fastutil.shorts.ShortIterator iter, long size, int additionalCharacterisitcs)Wrap a type-specificIteratorof a known size as a type-specificSpliteratorstatic it.unimi.dsi.fastutil.shorts.ShortSpliteratorasSpliteratorFromSorted(it.unimi.dsi.fastutil.shorts.ShortIterator iter, long size, int additionalCharacterisitcs, ShortComparator comparator)Wrap a type-specific, sortedIteratorof a known size as a type-specificSpliteratorstatic it.unimi.dsi.fastutil.shorts.ShortSpliteratorasSpliteratorFromSortedUnknownSize(it.unimi.dsi.fastutil.shorts.ShortIterator iter, int additionalCharacterisitcs, ShortComparator comparator)Wrap a type-specific, sortedIteratorof an unknown size as a type-specificSpliteratorstatic it.unimi.dsi.fastutil.shorts.ShortSpliteratorasSpliteratorUnknownSize(it.unimi.dsi.fastutil.shorts.ShortIterator iter, int characterisitcs)Wrap a type-specificIteratorof an unknown size as a type-specificSpliteratorstatic it.unimi.dsi.fastutil.shorts.ShortSpliteratorconcat(it.unimi.dsi.fastutil.shorts.ShortSpliterator... a)Concatenates all spliterators contained in an array.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorconcat(it.unimi.dsi.fastutil.shorts.ShortSpliterator[] a, int offset, int length)Concatenates a sequence of spliterators contained in an array.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorfromTo(short from, short to)Creates a type-specific spliterator over an interval.static it.unimi.dsi.fastutil.shorts.ShortSpliteratornarrow(java.util.Spliterator.OfInt i)Wrap a JDK primitive spliterator to a type-specific spliterator, making checked narrowed casts.static voidonEachMatching(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator, ShortPredicate predicate, ShortConsumer action)Perform the givenactionon each element that matches the givenpredicate.static voidonEachMatching(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator, java.util.function.IntPredicate predicate, java.util.function.IntConsumer action)Perform the givenactionon each element that matches the givenpredicate.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorsingleton(short element)Returns a spliterator that iterates just over the given element.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorsingleton(short element, ShortComparator comparator)Returns a spliterator that iterates just over the given element.static it.unimi.dsi.fastutil.ints.IntSpliteratorwiden(it.unimi.dsi.fastutil.shorts.ShortSpliterator i)Wrap a type-specific spliterator to a JDK compatible primitive spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrap(short[] array)Wraps the given array into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrap(short[] array, int offset, int length)Wraps the given part of an array into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrap(short[] array, int offset, int length, int additionalCharacteristics)Wraps the given part of an array into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrap(it.unimi.dsi.fastutil.bytes.ByteSpliterator spliterator)Returns a spliterator backed by the specified byte spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrapPreSorted(short[] array, int offset, int length, int additionalCharacteristics, ShortComparator comparator)Wraps the given part of a sorted array into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrapPreSorted(short[] array, int offset, int length, ShortComparator comparator)Wraps the given part of a sorted array into a type-specific spliterator.static it.unimi.dsi.fastutil.shorts.ShortSpliteratorwrapPreSorted(short[] array, ShortComparator comparator)Wraps the given sorted array into a type-specific spliterator.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
COLLECTION_SPLITERATOR_CHARACTERISTICS
public static final int COLLECTION_SPLITERATOR_CHARACTERISTICS- See Also:
- Constant Field Values
-
LIST_SPLITERATOR_CHARACTERISTICS
public static final int LIST_SPLITERATOR_CHARACTERISTICS- See Also:
- Constant Field Values
-
SET_SPLITERATOR_CHARACTERISTICS
public static final int SET_SPLITERATOR_CHARACTERISTICS- See Also:
- Constant Field Values
-
SORTED_SET_SPLITERATOR_CHARACTERISTICS
public static final int SORTED_SET_SPLITERATOR_CHARACTERISTICS- See Also:
- Constant Field Values
-
EMPTY_SPLITERATOR
An empty spliterator. It is serializable and cloneable.The class of this objects represent an abstract empty spliterator that can iterate as a type-specific spliterator.
-
-
Method Details
-
singleton
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator singleton(short element)Returns a spliterator that iterates just over the given element.- Parameters:
element- the only element to be returned by a type-specific spliterator.- Returns:
- a spliterator that iterates just over
element.
-
singleton
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator singleton(short element, ShortComparator comparator)Returns a spliterator that iterates just over the given element.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.- Parameters:
element- the only element to be returned by a type-specific spliterator.comparator- the comparator to return whenSpliterator.getComparator()is called.- Returns:
- a spliterator that iterates just over
element.
-
wrap
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrap(short[] array, int offset, int length)Wraps the given part of an array into a type-specific spliterator.The type-specific spliterator returned by this method will iterate
lengthtimes, advancing over consecutive elements of the given array starting from the one with indexoffset.The returned spliterator will report characteristics
Spliterator.SIZED,Spliterator.SUBSIZED,Spliterator.ORDERED, and for primitive arrays,Spliterator.NONNULL.- Parameters:
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.- Returns:
- a spliterator that will iterate over
lengthelements ofarraystarting at positionoffset.
-
wrap
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrap(short[] array)Wraps the given array into a type-specific spliterator.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.- Parameters:
array- an array to wrap into a type-specific spliterator.- Returns:
- a spliterator that will iterate over the elements of
array.
-
wrap
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrap(short[] array, int offset, int length, int additionalCharacteristics)Wraps the given part of an array into a type-specific spliterator.The type-specific spliterator returned by this method will iterate
lengthtimes, advancing over consecutive elements of the given array starting from the one with indexoffset.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 inadditionalCharacteristics(for example, if the caller knows the backing array has distinct elements, they can passSpliterator.DISTINCT).- Parameters:
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.- Returns:
- a spliterator that will iterate over
lengthelements ofarraystarting at positionoffset.
-
wrapPreSorted
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrapPreSorted(short[] array, int offset, int length, int additionalCharacteristics, ShortComparator comparator)Wraps the given part of a sorted array into a type-specific spliterator.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
lengthtimes, advancing over consecutive elements of the given array starting from the one with indexoffset.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 inadditionalCharacteristics(for example, if the caller knows the backing array has distinct elements, they can passSpliterator.DISTINCT).- Parameters:
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 (ornullfor natural ordering)- Returns:
- a spliterator that will iterate over
lengthelements ofarraystarting at positionoffset.
-
wrapPreSorted
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrapPreSorted(short[] array, int offset, int length, ShortComparator comparator)Wraps the given part of a sorted array into a type-specific spliterator.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
lengthtimes, advancing over consecutive elements of the given array starting from the one with indexoffset.The returned spliterator will report characteristics
Spliterator.SIZED,Spliterator.SUBSIZED,Spliterator.ORDERED,Spliterator.SORTED, and for primitive arrays,Spliterator.NONNULL.- Parameters:
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 (ornullfor natural ordering)- Returns:
- a spliterator that will iterate over
lengthelements ofarraystarting at positionoffset.
-
wrapPreSorted
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrapPreSorted(short[] array, ShortComparator comparator)Wraps the given sorted array into a type-specific spliterator.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.- Parameters:
array- an array to wrap into a type-specific spliterator.comparator- the comparator the array was sorted with (ornullfor natural ordering)- Returns:
- a spliterator that will iterate over
lengthelements ofarraystarting at positionoffset.
-
asShortSpliterator
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asShortSpliterator(java.util.Spliterator i)Wraps a standard spliterator into a type-specific spliterator.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 byi: changes to one of the spliterators will affect the other, too.If
iis already type-specific, it will returned and no new object will be generated.- Parameters:
i- a spliterator.- Returns:
- a type-specific spliterator backed by
i.
-
asShortSpliterator
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asShortSpliterator(java.util.Spliterator i, ShortComparator comparatorOverride)Wraps a standard spliterator into a type-specific spliterator.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 byi: changes to one of the spliterators will affect the other, too.This method will cause the returned spliterator's
Spliterator.getComparator()method to always returncomparatorOverride, regardless of what the wrapped spliterator'sgetComparator()method returns.NOTE:This is mostly intended for supporting default implementations in interfaces that wrap JDK spliterators, and not a general purpose method.
If
iis already type-specific, this method will throw, as such spliterators already have agetComparator()that returns a properly typed comparator.- Parameters:
i- a spliterator.comparatorOverride- the comparator to return whenSpliterator.getComparator()- Returns:
- a type-specific spliterator backed by
i.
-
narrow
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator narrow(java.util.Spliterator.OfInt i)Wrap a JDK primitive spliterator to a type-specific spliterator, making checked narrowed casts.The
tryAdvancemethod throwsIllegalArgumentExceptionif any element would underflow or overflow.- Parameters:
i- a spiterator- Returns:
- a type-specific spliterator backed by
i
-
widen
public static it.unimi.dsi.fastutil.ints.IntSpliterator widen(it.unimi.dsi.fastutil.shorts.ShortSpliterator i)Wrap a type-specific spliterator to a JDK compatible primitive spliterator.- Parameters:
i- a spliterator- Returns:
- a JDK compatible primitive spliterator backed by
i
-
onEachMatching
public static void onEachMatching(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator, ShortPredicate predicate, ShortConsumer action)Perform the givenactionon each element that matches the givenpredicate.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). -
onEachMatching
public static void onEachMatching(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator, java.util.function.IntPredicate predicate, java.util.function.IntConsumer action)Perform the givenactionon each element that matches the givenpredicate.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). -
fromTo
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator fromTo(short from, short to)Creates a type-specific spliterator over an interval.The type-specific spliterator returned by this method will return the elements
from,from+1,…,to-1.- Parameters:
from- the starting element (inclusive).to- the ending element (exclusive).- Returns:
- a type-specific spliterator enumerating the elements from
fromtoto.
-
concat
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator concat(it.unimi.dsi.fastutil.shorts.ShortSpliterator... a)Concatenates all spliterators contained in an array.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
Comparatoris consistent between each inner spliterator, the returned spliterator'sSpliterator.getComparator()will always throwIllegalStateException, even when if the current or even all the inner spliterators are sorted.- Parameters:
a- an array of spliterators.- Returns:
- a spliterator obtained by concatenation.
-
concat
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator concat(it.unimi.dsi.fastutil.shorts.ShortSpliterator[] a, int offset, int length)Concatenates a sequence of spliterators contained in an array.This method returns a spliterator that will enumerate in order the elements returned by
a[offset], then those returned bya[offset + 1], and so on up toa[offset + length - 1].Note: Due to there being no way to ensure the
Comparatoris consistent between each inner spliterator, the returned spliterator'sSpliterator.getComparator()will always throwIllegalStateException, even when if the current or even all the inner spliterators are sorted.- Parameters:
a- an array of spliterators.offset- the index of the first spliterator to concatenate.length- the number of spliterators to concatenate.- Returns:
- a spliterator obtained by concatenation of
lengthelements ofastarting atoffset.
-
asSpliterator
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asSpliterator(it.unimi.dsi.fastutil.shorts.ShortIterator iter, long size, int additionalCharacterisitcs)Wrap a type-specificIteratorof a known size as a type-specificSpliteratorThe returned spliterator will report
characteristicsadditionalCharacterisitcs, and for primitive types,Spliterator.NONNULL. It will also reportSpliterator.SIZED,Spliterator.SUBSIZED, unlessSpliterator.CONCURRENTis to be reported, in which case these two are not implicitly reported.Because
Iteratoris an inherently linear API, the returned spliterator will yield limited performance gains when run in parallel contexts, as the returned spliterator'sSpliterator.trySplit()will have linear runtime.- Parameters:
iter- the type-specificIteratorto wrapsize- the number of elements the iterator will returnadditionalCharacterisitcs- any additional characteristics to report- Returns:
- a type-specific
Spliteratorthat will give the same elements the iterator will return. - See Also:
Spliterators.spliterator(java.util.Iterator, long, int)
-
asSpliteratorFromSorted
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asSpliteratorFromSorted(it.unimi.dsi.fastutil.shorts.ShortIterator iter, long size, int additionalCharacterisitcs, ShortComparator comparator)Wrap a type-specific, sortedIteratorof a known size as a type-specificSpliteratorIt is the caller's responsibility to ensure the iterator's order is actually sorted according to the comparator given.
The returned spliterator will report
characteristicsadditionalCharacterisitcs,Spliterator.ORDERED,Spliterator.SORTED, and for primitive types,Spliterator.NONNULL. It will also reportSpliterator.SIZED,Spliterator.SUBSIZED, unlessSpliterator.CONCURRENTis to be reported, in which case these two are not implicitly reported.Because
Iteratoris an inherently linear API, the returned spliterator will yield limited performance gains when run in parallel contexts, as the returned spliterator'sSpliterator.trySplit()will have linear runtime.- Parameters:
iter- the type-specificIteratorto wrapsize- the number of elements the iterator will returnadditionalCharacterisitcs- any additional characteristics to reportcomparator- the comparator the iterator is ordered on (ornullfor natural ordering)- Returns:
- a type-specific
Spliteratorthat will give the same elements the iterator will return.
-
asSpliteratorUnknownSize
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asSpliteratorUnknownSize(it.unimi.dsi.fastutil.shorts.ShortIterator iter, int characterisitcs)Wrap a type-specificIteratorof an unknown size as a type-specificSpliteratorThe returned spliterator will report
additionalCharacterisitcs, and for primitive types,Spliterator.NONNULL.Because
Iteratoris an inherently linear API, the returned spliterator will yield limited performance gains when run in parallel contexts, as the returned spliterator'sSpliterator.trySplit()will have linear runtime.- Parameters:
iter- the type-specificIteratorto wrapcharacterisitcs- the characteristics to report- Returns:
- a type-specific
Spliteratorthat will give the same elements the iterator will return. - See Also:
Spliterators.spliteratorUnknownSize(java.util.Iterator, int)
-
asSpliteratorFromSortedUnknownSize
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator asSpliteratorFromSortedUnknownSize(it.unimi.dsi.fastutil.shorts.ShortIterator iter, int additionalCharacterisitcs, ShortComparator comparator)Wrap a type-specific, sortedIteratorof an unknown size as a type-specificSpliteratorIt is the caller's responsibility to ensure the iterator's order is actually sorted according to the comparator given.
The returned spliterator will report
characteristicsadditionalCharacterisitcs,Spliterator.ORDERED,Spliterator.SORTED, and for primitive types,Spliterator.NONNULL.Because
Iteratoris an inherently linear API, the returned spliterator will yield limited performance gains when run in parallel contexts, as the returned spliterator'sSpliterator.trySplit()will have linear runtime.- Parameters:
iter- the type-specificIteratorto wrapadditionalCharacterisitcs- the characteristics to reportcomparator- the comparator the iterator is ordered on (ornullfor natural ordering)- Returns:
- a type-specific
Spliteratorthat will give the same elements the iterator will return.
-
asIterator
public static it.unimi.dsi.fastutil.shorts.ShortIterator asIterator(it.unimi.dsi.fastutil.shorts.ShortSpliterator spliterator)Wrap a type-specificSpliteratoras a type-specificIterator- Parameters:
spliterator- the type-specificSpliteratorto wrap- Returns:
- a type-specific
Iteratorthat will return the same elements the spliterator will give. - See Also:
Spliterators.iterator(java.util.Spliterator)
-
wrap
public static it.unimi.dsi.fastutil.shorts.ShortSpliterator wrap(it.unimi.dsi.fastutil.bytes.ByteSpliterator spliterator)Returns a spliterator backed by the specified byte spliterator.Note: Due to the incompatibility of primitive
Comparatortypes, the returned spliterator'sSpliterator.getComparator()will always throwIllegalStateException, even when the underlying spliterator is sorted.- Parameters:
spliterator- a byte spliterator.- Returns:
- a spliterator backed by the specified byte spliterator.
-