Modifier and Type | Method and Description |
---|---|
static int |
compare(double[] a,
double[] b)
Compares two
double arrays lexicographically. |
static int |
compare(double[] a,
int aFromIndex,
int aToIndex,
double[] b,
int bFromIndex,
int bToIndex)
Compares two
double arrays lexicographically over the specified
ranges. |
static int |
compare(int[] a,
int[] b)
Compares two
int arrays lexicographically. |
static int |
compare(int[] a,
int aFromIndex,
int aToIndex,
int[] b,
int bFromIndex,
int bToIndex)
Compares two
int arrays lexicographically over the specified
ranges. |
static int |
compare(long[] a,
int aFromIndex,
int aToIndex,
long[] b,
int bFromIndex,
int bToIndex)
Compares two
long arrays lexicographically over the specified
ranges. |
static int |
compare(long[] a,
long[] b)
Compares two
long arrays lexicographically. |
static <T extends Comparable<? super T>> |
compare(T[] a,
int aFromIndex,
int aToIndex,
T[] b,
int bFromIndex,
int bToIndex)
Compares two
Object arrays lexicographically over the specified
ranges. |
static <T> int |
compare(T[] a,
int aFromIndex,
int aToIndex,
T[] b,
int bFromIndex,
int bToIndex,
Comparator<? super T> cmp)
Compares two
Object arrays lexicographically over the specified
ranges. |
static <T extends Comparable<? super T>> |
compare(T[] a,
T[] b)
Compares two
Object arrays, within comparable elements,
lexicographically. |
static <T> int |
compare(T[] a,
T[] b,
Comparator<? super T> cmp)
Compares two
Object arrays lexicographically using a specified
comparator. |
static boolean |
equals(double[] a,
int aFromIndex,
int aToIndex,
double[] b,
int bFromIndex,
int bToIndex)
Returns true if the two specified arrays of doubles, over the specified
ranges, are equal to one another.
|
static boolean |
equals(int[] a,
int aFromIndex,
int aToIndex,
int[] b,
int bFromIndex,
int bToIndex)
Returns true if the two specified arrays of ints, over the specified
ranges, are equal to one another.
|
static boolean |
equals(long[] a,
int aFromIndex,
int aToIndex,
long[] b,
int bFromIndex,
int bToIndex)
Returns true if the two specified arrays of longs, over the specified
ranges, are equal to one another.
|
static boolean |
equals(Object[] a,
int aFromIndex,
int aToIndex,
Object[] b,
int bFromIndex,
int bToIndex)
Returns true if the two specified arrays of Objects, over the specified
ranges, are equal to one another.
|
static <T> boolean |
equals(T[] a,
int aFromIndex,
int aToIndex,
T[] b,
int bFromIndex,
int bToIndex,
Comparator<? super T> cmp)
Returns true if the two specified arrays of Objects, over the specified
ranges, are equal to one another.
|
static <T> boolean |
equals(T[] a,
T[] a2,
Comparator<? super T> cmp)
Returns
true if the two specified arrays of Objects are
equal to one another. |
static int |
mismatch(double[] a,
double[] b)
Finds and returns the index of the first mismatch between two
double arrays, otherwise return -1 if no mismatch is found. |
static int |
mismatch(double[] a,
int aFromIndex,
int aToIndex,
double[] b,
int bFromIndex,
int bToIndex)
Finds and returns the relative index of the first mismatch between two
double arrays over the specified ranges, otherwise return -1 if
no mismatch is found. |
static int |
mismatch(int[] a,
int[] b)
Finds and returns the index of the first mismatch between two
int
arrays, otherwise return -1 if no mismatch is found. |
static int |
mismatch(int[] a,
int aFromIndex,
int aToIndex,
int[] b,
int bFromIndex,
int bToIndex)
Finds and returns the relative index of the first mismatch between two
int arrays over the specified ranges, otherwise return -1 if no
mismatch is found. |
static int |
mismatch(long[] a,
int aFromIndex,
int aToIndex,
long[] b,
int bFromIndex,
int bToIndex)
Finds and returns the relative index of the first mismatch between two
long arrays over the specified ranges, otherwise return -1 if no
mismatch is found. |
static int |
mismatch(long[] a,
long[] b)
Finds and returns the index of the first mismatch between two
long
arrays, otherwise return -1 if no mismatch is found. |
static int |
mismatch(Object[] a,
int aFromIndex,
int aToIndex,
Object[] b,
int bFromIndex,
int bToIndex)
Finds and returns the relative index of the first mismatch between two
Object arrays over the specified ranges, otherwise return -1 if
no mismatch is found. |
static int |
mismatch(Object[] a,
Object[] b)
Finds and returns the index of the first mismatch between two
Object arrays, otherwise return -1 if no mismatch is found. |
static <T> int |
mismatch(T[] a,
int aFromIndex,
int aToIndex,
T[] b,
int bFromIndex,
int bToIndex,
Comparator<? super T> cmp)
Finds and returns the relative index of the first mismatch between two
Object arrays over the specified ranges, otherwise return -1 if
no mismatch is found. |
static <T> int |
mismatch(T[] a,
T[] b,
Comparator<? super T> cmp)
Finds and returns the index of the first mismatch between two
Object arrays, otherwise return -1 if no mismatch is found. |
static void |
parallelPrefix(double[] array,
DoubleBinaryOperator op)
Cumulates, in parallel, each element of the given array in place,
using the supplied function.
|
static void |
parallelPrefix(double[] array,
int fromIndex,
int toIndex,
DoubleBinaryOperator op)
Performs
parallelPrefix(double[], DoubleBinaryOperator)
for the given subrange of the array. |
static void |
parallelPrefix(int[] array,
IntBinaryOperator op)
Cumulates, in parallel, each element of the given array in place,
using the supplied function.
|
static void |
parallelPrefix(int[] array,
int fromIndex,
int toIndex,
IntBinaryOperator op)
Performs
parallelPrefix(int[], IntBinaryOperator)
for the given subrange of the array. |
static void |
parallelPrefix(long[] array,
int fromIndex,
int toIndex,
LongBinaryOperator op)
Performs
parallelPrefix(long[], LongBinaryOperator)
for the given subrange of the array. |
static void |
parallelPrefix(long[] array,
LongBinaryOperator op)
Cumulates, in parallel, each element of the given array in place,
using the supplied function.
|
static <T> void |
parallelPrefix(T[] array,
BinaryOperator<T> op)
Cumulates, in parallel, each element of the given array in place,
using the supplied function.
|
static <T> void |
parallelPrefix(T[] array,
int fromIndex,
int toIndex,
BinaryOperator<T> op)
Performs
parallelPrefix(Object[], BinaryOperator)
for the given subrange of the array. |
static void |
parallelSetAll(double[] array,
IntToDoubleFunction generator)
Set all elements of the specified array, in parallel, using the
provided generator function to compute each element.
|
static void |
parallelSetAll(int[] array,
IntUnaryOperator generator)
Set all elements of the specified array, in parallel, using the
provided generator function to compute each element.
|
static void |
parallelSetAll(long[] array,
IntToLongFunction generator)
Set all elements of the specified array, in parallel, using the
provided generator function to compute each element.
|
static <T> void |
parallelSetAll(T[] array,
IntFunction<? extends T> generator)
Set all elements of the specified array, in parallel, using the
provided generator function to compute each element.
|
static void |
parallelSort(byte[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(byte[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(char[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(char[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(double[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(double[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(float[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(float[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(int[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(int[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(long[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(long[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static void |
parallelSort(short[] a)
Sorts the specified array into ascending numerical order.
|
static void |
parallelSort(short[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the array into ascending numerical order.
|
static <T extends Comparable<? super T>> |
parallelSort(T[] a)
Sorts the specified array of objects into ascending order, according
to the natural ordering of its elements.
|
static <T> void |
parallelSort(T[] a,
Comparator<? super T> cmp)
Sorts the specified array of objects according to the order induced by
the specified comparator.
|
static <T extends Comparable<? super T>> |
parallelSort(T[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the specified array of objects into
ascending order, according to the
natural ordering of its
elements.
|
static <T> void |
parallelSort(T[] a,
int fromIndex,
int toIndex,
Comparator<? super T> cmp)
Sorts the specified range of the specified array of objects according
to the order induced by the specified comparator.
|
static void |
setAll(double[] array,
IntToDoubleFunction generator)
Set all elements of the specified array, using the provided
generator function to compute each element.
|
static void |
setAll(int[] array,
IntUnaryOperator generator)
Set all elements of the specified array, using the provided
generator function to compute each element.
|
static void |
setAll(long[] array,
IntToLongFunction generator)
Set all elements of the specified array, using the provided
generator function to compute each element.
|
static <T> void |
setAll(T[] array,
IntFunction<? extends T> generator)
Set all elements of the specified array, using the provided
generator function to compute each element.
|
static Spliterator.OfDouble |
spliterator(double[] array)
Returns a
Spliterator.OfDouble covering all of the specified
array. |
static Spliterator.OfDouble |
spliterator(double[] array,
int startInclusive,
int endExclusive)
Returns a
Spliterator.OfDouble covering the specified range of
the specified array. |
static Spliterator.OfInt |
spliterator(int[] array)
Returns a
Spliterator.OfInt covering all of the specified array. |
static Spliterator.OfInt |
spliterator(int[] array,
int startInclusive,
int endExclusive)
Returns a
Spliterator.OfInt covering the specified range of the
specified array. |
static Spliterator.OfLong |
spliterator(long[] array)
Returns a
Spliterator.OfLong covering all of the specified array. |
static Spliterator.OfLong |
spliterator(long[] array,
int startInclusive,
int endExclusive)
Returns a
Spliterator.OfLong covering the specified range of the
specified array. |
static <T> Spliterator<T> |
spliterator(T[] array)
Returns a
Spliterator covering all of the specified array. |
static <T> Spliterator<T> |
spliterator(T[] array,
int startInclusive,
int endExclusive)
Returns a
Spliterator covering the specified range of the
specified array. |
static DoubleStream |
stream(double[] array)
Returns a sequential
DoubleStream with the specified array as its
source. |
static DoubleStream |
stream(double[] array,
int startInclusive,
int endExclusive)
Returns a sequential
DoubleStream with the specified range of the
specified array as its source. |
static IntStream |
stream(int[] array)
Returns a sequential
IntStream with the specified array as its
source. |
static IntStream |
stream(int[] array,
int startInclusive,
int endExclusive)
Returns a sequential
IntStream with the specified range of the
specified array as its source. |
static LongStream |
stream(long[] array)
Returns a sequential
LongStream with the specified array as its
source. |
static LongStream |
stream(long[] array,
int startInclusive,
int endExclusive)
Returns a sequential
LongStream with the specified range of the
specified array as its source. |
static <T> Stream<T> |
stream(T[] array)
Returns a sequential
Stream with the specified array as its
source. |
static <T> Stream<T> |
stream(T[] array,
int startInclusive,
int endExclusive)
Returns a sequential
Stream with the specified range of the
specified array as its source. |
static <T> T[] |
toArray(Collection<T> col,
IntFunction<T[]> generator)
Returns an array containing all of the elements in the passed collection,
using the provided
generator function to allocate the returned array. |
public static <T> Spliterator<T> spliterator(T[] array)
Spliterator
covering all of the specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
T
- type of elementsarray
- the array, assumed to be unmodified during usepublic static <T> Spliterator<T> spliterator(T[] array, int startInclusive, int endExclusive)
Spliterator
covering the specified range of the
specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
T
- type of elementsarray
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static Spliterator.OfInt spliterator(int[] array)
Spliterator.OfInt
covering all of the specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usepublic static Spliterator.OfInt spliterator(int[] array, int startInclusive, int endExclusive)
Spliterator.OfInt
covering the specified range of the
specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static Spliterator.OfLong spliterator(long[] array)
Spliterator.OfLong
covering all of the specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usepublic static Spliterator.OfLong spliterator(long[] array, int startInclusive, int endExclusive)
Spliterator.OfLong
covering the specified range of the
specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static Spliterator.OfDouble spliterator(double[] array)
Spliterator.OfDouble
covering all of the specified
array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usepublic static Spliterator.OfDouble spliterator(double[] array, int startInclusive, int endExclusive)
Spliterator.OfDouble
covering the specified range of
the specified array.
The spliterator reports Spliterator.SIZED
,
Spliterator.SUBSIZED
, Spliterator.ORDERED
, and
Spliterator.IMMUTABLE
.
array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static <T> Stream<T> stream(T[] array)
Stream
with the specified array as its
source.T
- The type of the array elementsarray
- The array, assumed to be unmodified during useStream
for the arraypublic static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive)
Stream
with the specified range of the
specified array as its source.T
- the type of the array elementsarray
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverStream
for the array rangeArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static IntStream stream(int[] array)
IntStream
with the specified array as its
source.array
- the array, assumed to be unmodified during useIntStream
for the arraypublic static IntStream stream(int[] array, int startInclusive, int endExclusive)
IntStream
with the specified range of the
specified array as its source.array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverIntStream
for the array rangeArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static LongStream stream(long[] array)
LongStream
with the specified array as its
source.array
- the array, assumed to be unmodified during useLongStream
for the arraypublic static LongStream stream(long[] array, int startInclusive, int endExclusive)
LongStream
with the specified range of the
specified array as its source.array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverLongStream
for the array rangeArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static DoubleStream stream(double[] array)
DoubleStream
with the specified array as its
source.array
- the array, assumed to be unmodified during useDoubleStream
for the arraypublic static DoubleStream stream(double[] array, int startInclusive, int endExclusive)
DoubleStream
with the specified range of the
specified array as its source.array
- the array, assumed to be unmodified during usestartInclusive
- the first index to cover, inclusiveendExclusive
- index immediately past the last index to coverDoubleStream
for the array rangeArrayIndexOutOfBoundsException
- if startInclusive
is
negative, endExclusive
is less than
startInclusive
, or endExclusive
is greater than
the array sizepublic static void parallelSort(byte[] a)
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(byte[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(char[] a)
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(char[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(short[] a)
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(short[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(int[] a)
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(int[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(long[] a)
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(long[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(float[] a)
The <
relation does not provide a total order on all float
values: -0.0f == 0.0f
is true
and a Float.NaN
value compares neither less than, greater than, nor equal to any value,
even itself. This method uses the total order imposed by the method
Float.compareTo(java.lang.Float)
: -0.0f
is treated as less than value
0.0f
and Float.NaN
is considered greater than any
other value and all Float.NaN
values are considered equal.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(float[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
The <
relation does not provide a total order on all float
values: -0.0f == 0.0f
is true
and a Float.NaN
value compares neither less than, greater than, nor equal to any value,
even itself. This method uses the total order imposed by the method
Float.compareTo(java.lang.Float)
: -0.0f
is treated as less than value
0.0f
and Float.NaN
is considered greater than any
other value and all Float.NaN
values are considered equal.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static void parallelSort(double[] a)
The <
relation does not provide a total order on all double
values: -0.0d == 0.0d
is true
and a Double.NaN
value compares neither less than, greater than, nor equal to any value,
even itself. This method uses the total order imposed by the method
Double.compareTo(java.lang.Double)
: -0.0d
is treated as less than value
0.0d
and Double.NaN
is considered greater than any
other value and all Double.NaN
values are considered equal.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedpublic static void parallelSort(double[] a, int fromIndex, int toIndex)
fromIndex
,
inclusive, to the index toIndex
, exclusive. If
fromIndex == toIndex
, the range to be sorted is empty.
The <
relation does not provide a total order on all double
values: -0.0d == 0.0d
is true
and a Double.NaN
value compares neither less than, greater than, nor equal to any value,
even itself. This method uses the total order imposed by the method
Double.compareTo(java.lang.Double)
: -0.0d
is treated as less than value
0.0d
and Double.NaN
is considered greater than any
other value and all Double.NaN
values are considered equal.
Implementation Note:
The sorting algorithm is a Dual-Pivot Quicksort by
Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
offers O(n log(n)) performance on all data sets, and is typically
faster than traditional (one-pivot) Quicksort implementations.
a
- the array to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
public static <T extends Comparable<? super T>> void parallelSort(T[] a)
Comparable
interface. Furthermore, all elements in the array must be
mutually comparable (that is, e1.compareTo(e2)
must
not throw a ClassCastException
for any elements e1
and e2
in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation Note:
The sorting algorithm is a parallel sort-merge that breaks the
array into sub-arrays that are themselves sorted and then merged. When
the sub-array length reaches a minimum granularity, the sub-array is
sorted using the appropriate Arrays.sort
method. If the length of the specified array is less than the minimum
granularity, then it is sorted using the appropriate Arrays.sort
method. The algorithm requires a
working space no greater than the size of the original array. The
ForkJoin common pool
is used to
execute any parallel tasks.
T
- the class of the objects to be sorteda
- the array to be sortedClassCastException
- if the array contains elements that are not
mutually comparable (for example, strings and integers)IllegalArgumentException
- (optional) if the natural
ordering of the array elements is found to violate the
Comparable
contractpublic static <T extends Comparable<? super T>> void parallelSort(T[] a, int fromIndex, int toIndex)
fromIndex
, inclusive, to index toIndex
, exclusive.
(If fromIndex==toIndex
, the range to be sorted is empty.) All
elements in this range must implement the Comparable
interface. Furthermore, all elements in this range must be mutually
comparable (that is, e1.compareTo(e2)
must not throw a
ClassCastException
for any elements e1
and
e2
in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation Note:
The sorting algorithm is a parallel sort-merge that breaks the
array into sub-arrays that are themselves sorted and then merged. When
the sub-array length reaches a minimum granularity, the sub-array is
sorted using the appropriate Arrays.sort
method. If the length of the specified array is less than the minimum
granularity, then it is sorted using the appropriate Arrays.sort
method. The algorithm requires a working
space no greater than the size of the specified range of the original
array. The ForkJoin common pool
is
used to execute any parallel tasks.
T
- the class of the objects to be sorteda
- the array to be sortedfromIndex
- the index of the first element (inclusive) to be
sortedtoIndex
- the index of the last element (exclusive) to be sortedIllegalArgumentException
- if fromIndex > toIndex
or
(optional) if the natural ordering of the array elements is
found to violate the Comparable
contractArrayIndexOutOfBoundsException
- if fromIndex < 0
or
toIndex > a.length
ClassCastException
- if the array contains elements that are
not mutually comparable (for example, strings and
integers).public static <T> void parallelSort(T[] a, Comparator<? super T> cmp)
c.compare(e1, e2)
must not throw a ClassCastException
for any elements e1
and e2
in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation Note:
The sorting algorithm is a parallel sort-merge that breaks the
array into sub-arrays that are themselves sorted and then merged. When
the sub-array length reaches a minimum granularity, the sub-array is
sorted using the appropriate Arrays.sort
method. If the length of the specified array is less than the minimum
granularity, then it is sorted using the appropriate Arrays.sort
method. The algorithm requires a
working space no greater than the size of the original array. The
ForkJoin common pool
is used to
execute any parallel tasks.
T
- the class of the objects to be sorteda
- the array to be sortedcmp
- the comparator to determine the order of the array. A
null
value indicates that the elements'
natural ordering should be used.ClassCastException
- if the array contains elements that are
not mutually comparable using the specified comparatorIllegalArgumentException
- (optional) if the comparator is
found to violate the Comparator
contractpublic static <T> void parallelSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> cmp)
fromIndex
, inclusive, to index
toIndex
, exclusive. (If fromIndex==toIndex
, the
range to be sorted is empty.) All elements in the range must be
mutually comparable by the specified comparator (that is,
c.compare(e1, e2)
must not throw a ClassCastException
for any elements e1
and e2
in the range).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation Note:
The sorting algorithm is a parallel sort-merge that breaks the
array into sub-arrays that are themselves sorted and then merged. When
the sub-array length reaches a minimum granularity, the sub-array is
sorted using the appropriate Arrays.sort
method. If the length of the specified array is less than the minimum
granularity, then it is sorted using the appropriate Arrays.sort
method. The algorithm requires a working
space no greater than the size of the specified range of the original
array. The ForkJoin common pool
is
used to execute any parallel tasks.
T
- the class of the objects to be sorteda
- the array to be sortedfromIndex
- the index of the first element (inclusive) to be
sortedtoIndex
- the index of the last element (exclusive) to be sortedcmp
- the comparator to determine the order of the array. A
null
value indicates that the elements'
natural ordering should be used.IllegalArgumentException
- if fromIndex > toIndex
or
(optional) if the natural ordering of the array elements is
found to violate the Comparable
contractArrayIndexOutOfBoundsException
- if fromIndex < 0
or
toIndex > a.length
ClassCastException
- if the array contains elements that are
not mutually comparable (for example, strings and
integers).public static <T> void setAll(T[] array, IntFunction<? extends T> generator)
If the generator function throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
API Note:
Setting a subrange of an array, using a generator function to compute
each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.forEach(i -> array[i] = generator.apply(i));
T
- type of elements of the arrayarray
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static <T> void parallelSetAll(T[] array, IntFunction<? extends T> generator)
If the generator function throws an exception, an unchecked exception
is thrown from parallelSetAll
and the array is left in an
indeterminate state.
API Note:
Setting a subrange of an array, in parallel, using a generator function
to compute each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.parallel()
.forEach(i -> array[i] = generator.apply(i));
T
- type of elements of the arrayarray
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void setAll(int[] array, IntUnaryOperator generator)
If the generator function throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
API Note:
Setting a subrange of an array, using a generator function to compute
each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.forEach(i -> array[i] = generator.applyAsInt(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void parallelSetAll(int[] array, IntUnaryOperator generator)
If the generator function throws an exception, an unchecked exception
is thrown from parallelSetAll
and the array is left in an
indeterminate state.
API Note:
Setting a subrange of an array, in parallel, using a generator function
to compute each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.parallel()
.forEach(i -> array[i] = generator.applyAsInt(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void setAll(long[] array, IntToLongFunction generator)
If the generator function throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
API Note:
Setting a subrange of an array, using a generator function to compute
each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.forEach(i -> array[i] = generator.applyAsLong(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void parallelSetAll(long[] array, IntToLongFunction generator)
If the generator function throws an exception, an unchecked exception
is thrown from parallelSetAll
and the array is left in an
indeterminate state.
API Note:
Setting a subrange of an array, in parallel, using a generator function
to compute each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.parallel()
.forEach(i -> array[i] = generator.applyAsLong(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void setAll(double[] array, IntToDoubleFunction generator)
If the generator function throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
API Note:
Setting a subrange of an array, using a generator function to compute
each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.forEach(i -> array[i] = generator.applyAsDouble(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static void parallelSetAll(double[] array, IntToDoubleFunction generator)
If the generator function throws an exception, an unchecked exception
is thrown from parallelSetAll
and the array is left in an
indeterminate state.
API Note:
Setting a subrange of an array, in parallel, using a generator function
to compute each element, can be written as follows:
IntStreams.range(startInclusive, endExclusive)
.parallel()
.forEach(i -> array[i] = generator.applyAsDouble(i));
array
- array to be initializedgenerator
- a function accepting an index and producing the desired
value for that positionNullPointerException
- if the generator is nullpublic static <T> void parallelPrefix(T[] array, BinaryOperator<T> op)
[2, 1, 0, 3]
and the operation performs addition,
then upon return the array holds [2, 3, 3, 6]
.
Parallel prefix computation is usually more efficient than
sequential loops for large arrays.T
- the class of the objects in the arrayarray
- the array, which is modified in-place by this methodop
- a side-effect-free, associative function to perform the
cumulationNullPointerException
- if the specified array or function is nullpublic static <T> void parallelPrefix(T[] array, int fromIndex, int toIndex, BinaryOperator<T> op)
parallelPrefix(Object[], BinaryOperator)
for the given subrange of the array.T
- the class of the objects in the arrayarray
- the arrayfromIndex
- the index of the first element, inclusivetoIndex
- the index of the last element, exclusiveop
- a side-effect-free, associative function to perform the
cumulationIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > array.length
NullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(long[] array, LongBinaryOperator op)
[2, 1, 0, 3]
and the operation performs addition,
then upon return the array holds [2, 3, 3, 6]
.
Parallel prefix computation is usually more efficient than
sequential loops for large arrays.array
- the array, which is modified in-place by this methodop
- a side-effect-free, associative function to perform the
cumulationNullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(long[] array, int fromIndex, int toIndex, LongBinaryOperator op)
parallelPrefix(long[], LongBinaryOperator)
for the given subrange of the array.array
- the arrayfromIndex
- the index of the first element, inclusivetoIndex
- the index of the last element, exclusiveop
- a side-effect-free, associative function to perform the
cumulationIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > array.length
NullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(double[] array, DoubleBinaryOperator op)
[2.0, 1.0, 0.0, 3.0]
and the operation performs addition,
then upon return the array holds [2.0, 3.0, 3.0, 6.0]
.
Parallel prefix computation is usually more efficient than
sequential loops for large arrays.
Because floating-point operations may not be strictly associative, the returned result may not be identical to the value that would be obtained if the operation was performed sequentially.
array
- the array, which is modified in-place by this methodop
- a side-effect-free function to perform the cumulationNullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(double[] array, int fromIndex, int toIndex, DoubleBinaryOperator op)
parallelPrefix(double[], DoubleBinaryOperator)
for the given subrange of the array.array
- the arrayfromIndex
- the index of the first element, inclusivetoIndex
- the index of the last element, exclusiveop
- a side-effect-free, associative function to perform the
cumulationIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > array.length
NullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(int[] array, IntBinaryOperator op)
[2, 1, 0, 3]
and the operation performs addition,
then upon return the array holds [2, 3, 3, 6]
.
Parallel prefix computation is usually more efficient than
sequential loops for large arrays.array
- the array, which is modified in-place by this methodop
- a side-effect-free, associative function to perform the
cumulationNullPointerException
- if the specified array or function is nullpublic static void parallelPrefix(int[] array, int fromIndex, int toIndex, IntBinaryOperator op)
parallelPrefix(int[], IntBinaryOperator)
for the given subrange of the array.array
- the arrayfromIndex
- the index of the first element, inclusivetoIndex
- the index of the last element, exclusiveop
- a side-effect-free, associative function to perform the
cumulationIllegalArgumentException
- if fromIndex > toIndex
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or toIndex > array.length
NullPointerException
- if the specified array or function is nullpublic static boolean equals(Object[] a, int aFromIndex, int aToIndex, Object[] b, int bFromIndex, int bToIndex)
Two arrays are considered equal if the number of elements covered by each range is the same, and all corresponding pairs of elements over the specified ranges in the two arrays are equal. In other words, two arrays are equal if they contain, over the specified ranges, the same elements in the same order.
Two objects e1
and e2
are considered equal if
Objects.equals(e1, e2)
.
a
- the first array to be tested for equalityaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for equalitybFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedtrue
if the two arrays, over the specified ranges, are
equalIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static <T> boolean equals(T[] a, T[] a2, Comparator<? super T> cmp)
true
if the two specified arrays of Objects are
equal to one another.
Two arrays are considered equal if both arrays contain the same number
of elements, and all corresponding pairs of elements in the two arrays
are equal. In other words, the two arrays are equal if they contain the
same elements in the same order. Also, two array references are
considered equal if both are null
.
Two objects e1
and e2
are considered equal if,
given the specified comparator, cmp.compare(e1, e2) == 0
.
T
- the type of array elementsa
- one array to be tested for equalitya2
- the other array to be tested for equalitycmp
- the comparator to compare array elementstrue
if the two arrays are equalNullPointerException
- if the comparator is null
public static <T> boolean equals(T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
Two arrays are considered equal if the number of elements covered by each range is the same, and all corresponding pairs of elements over the specified ranges in the two arrays are equal. In other words, two arrays are equal if they contain, over the specified ranges, the same elements in the same order.
Two objects e1
and e2
are considered equal if,
given the specified comparator, cmp.compare(e1, e2) == 0
.
T
- the type of array elementsa
- the first array to be tested for equalityaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for equalitybFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedcmp
- the comparator to compare array elementstrue
if the two arrays, over the specified ranges, are
equalIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array or the comparator is null
public static <T extends Comparable<? super T>> int compare(T[] a, T[] b)
Object
arrays, within comparable elements,
lexicographically.
If the two arrays share a common prefix then the lexicographic
comparison is the result of comparing two elements of type T
at
an index i
within the respective arrays that is the prefix
length, as if by:
Comparators.nullsFirst(Comparators.<T>naturalOrder()).
compare(a[i], b[i])
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two array lengths.
(See mismatch(Object[], Object[])
for the definition of a common
and proper prefix.)
A null
array reference is considered lexicographically less
than a non-null
array reference. Two null
array
references are considered equal.
A null
array element is considered lexicographically less than a
non-null
array element. Two null
array elements are
considered equal.
The comparison is consistent with equals
,
more specifically the following holds for arrays a
and b
:
java.util.Arrays.equals(a, b) == (J8Arrays.compare(a, b) == 0)
API Note:
This method behaves as if (for non-null
array references
and elements):
int i = J8Arrays.mismatch(a, b);
if (i >= 0 && i < Math.min(a.length, b.length))
return a[i].compareTo(b[i]);
return a.length - b.length;
T
- the type of comparable array elementsa
- the first array to compareb
- the second array to compare0
if the first and second array are equal and
contain the same elements in the same order;
a value less than 0
if the first array is
lexicographically less than the second array; and
a value greater than 0
if the first array is
lexicographically greater than the second arraypublic static <T extends Comparable<? super T>> int compare(T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex)
Object
arrays lexicographically over the specified
ranges.
If the two arrays, over the specified ranges, share a common prefix
then the lexicographic comparison is the result of comparing two
elements of type T
at a relative index i
within the
respective arrays that is the prefix length, as if by:
Comparators.nullsFirst(Comparators.<T>naturalOrder()).
compare(a[aFromIndex + i, b[bFromIndex + i])
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two range lengths.
(See mismatch(Object[], int, int, Object[], int, int)
for the
definition of a common and proper prefix.)
The comparison is consistent with
equals
, more
specifically the following holds for arrays a
and b
with
specified ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively:
J8Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
(J8Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
API Note:
This method behaves as if (for non-null
array elements):
int i = J8Arrays.mismatch(a, aFromIndex, aToIndex,
b, bFromIndex, bToIndex);
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
return a[aFromIndex + i].compareTo(b[bFromIndex + i]);
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
T
- the type of comparable array elementsa
- the first array to compareaFromIndex
- the index (inclusive) of the first element in the
first array to be comparedaToIndex
- the index (exclusive) of the last element in the
first array to be comparedb
- the second array to comparebFromIndex
- the index (inclusive) of the first element in the
second array to be comparedbToIndex
- the index (exclusive) of the last element in the
second array to be compared0
if, over the specified ranges, the first and
second array are equal and contain the same elements in the same
order;
a value less than 0
if, over the specified ranges, the
first array is lexicographically less than the second array; and
a value greater than 0
if, over the specified ranges, the
first array is lexicographically greater than the second arrayIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static <T> int compare(T[] a, T[] b, Comparator<? super T> cmp)
Object
arrays lexicographically using a specified
comparator.
If the two arrays share a common prefix then the lexicographic
comparison is the result of comparing with the specified comparator two
elements at an index within the respective arrays that is the prefix
length.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two array lengths.
(See mismatch(Object[], Object[])
for the definition of a common
and proper prefix.)
A null
array reference is considered lexicographically less
than a non-null
array reference. Two null
array
references are considered equal.
API Note:
This method behaves as if (for non-null
array references):
int i = J8Arrays.mismatch(a, b, cmp);
if (i >= 0 && i < Math.min(a.length, b.length))
return cmp.compare(a[i], b[i]);
return a.length - b.length;
T
- the type of array elementsa
- the first array to compareb
- the second array to comparecmp
- the comparator to compare array elements0
if the first and second array are equal and
contain the same elements in the same order;
a value less than 0
if the first array is
lexicographically less than the second array; and
a value greater than 0
if the first array is
lexicographically greater than the second arrayNullPointerException
- if the comparator is null
public static <T> int compare(T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
Object
arrays lexicographically over the specified
ranges.
If the two arrays, over the specified ranges, share a common prefix
then the lexicographic comparison is the result of comparing with the
specified comparator two elements at a relative index within the
respective arrays that is the prefix length.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two range lengths.
(See mismatch(Object[], int, int, Object[], int, int)
for the
definition of a common and proper prefix.)
API Note:
This method behaves as if (for non-null
array elements):
int i = J8Arrays.mismatch(a, aFromIndex, aToIndex,
b, bFromIndex, bToIndex, cmp);
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
return cmp.compare(a[aFromIndex + i], b[bFromIndex + i]);
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
T
- the type of array elementsa
- the first array to compareaFromIndex
- the index (inclusive) of the first element in the
first array to be comparedaToIndex
- the index (exclusive) of the last element in the
first array to be comparedb
- the second array to comparebFromIndex
- the index (inclusive) of the first element in the
second array to be comparedbToIndex
- the index (exclusive) of the last element in the
second array to be comparedcmp
- the comparator to compare array elements0
if, over the specified ranges, the first and
second array are equal and contain the same elements in the same
order;
a value less than 0
if, over the specified ranges, the
first array is lexicographically less than the second array; and
a value greater than 0
if, over the specified ranges, the
first array is lexicographically greater than the second arrayIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array or the comparator is null
public static int mismatch(Object[] a, Object[] b)
Object
arrays, otherwise return -1 if no mismatch is found. The
index will be in the range of 0 (inclusive) up to the length (inclusive)
of the smaller array.
If the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(a.length, b.length) &&
J8Arrays.equals(a, 0, pl, b, 0, pl) &&
!Objects.equals(a[pl], b[pl])
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
, share a proper
prefix if the following expression is true:
a.length != b.length &&
J8Arrays.equals(a, 0, Math.min(a.length, b.length),
b, 0, Math.min(a.length, b.length))
a
- the first array to be tested for a mismatchb
- the second array to be tested for a mismatch-1
.NullPointerException
- if either array is null
public static int mismatch(Object[] a, int aFromIndex, int aToIndex, Object[] b, int bFromIndex, int bToIndex)
Object
arrays over the specified ranges, otherwise return -1 if
no mismatch is found. The index will be in the range of 0 (inclusive) up
to the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
J8Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
!Objects.equals(a[aFromIndex + pl], b[bFromIndex + pl])
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a proper
prefix if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
J8Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
a
- the first array to be tested for a mismatchaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for a mismatchbFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be tested-1
.IllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static <T> int mismatch(T[] a, T[] b, Comparator<? super T> cmp)
Object
arrays, otherwise return -1 if no mismatch is found.
The index will be in the range of 0 (inclusive) up to the length
(inclusive) of the smaller array.
The specified comparator is used to determine if two array elements from the each array are not equal.
If the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(a.length, b.length) &&
J8Arrays.equals(a, 0, pl, b, 0, pl, cmp)
cmp.compare(a[pl], b[pl]) != 0
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
, share a proper
prefix if the following expression is true:
a.length != b.length &&
J8Arrays.equals(a, 0, Math.min(a.length, b.length),
b, 0, Math.min(a.length, b.length),
cmp)
T
- the type of array elementsa
- the first array to be tested for a mismatchb
- the second array to be tested for a mismatchcmp
- the comparator to compare array elements-1
.NullPointerException
- if either array or the comparator is null
public static <T> int mismatch(T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
Object
arrays over the specified ranges, otherwise return -1 if
no mismatch is found. The index will be in the range of 0 (inclusive) up
to the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
J8Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl, cmp) &&
cmp.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a proper
prefix if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
J8Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
cmp)
T
- the type of array elementsa
- the first array to be tested for a mismatchaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for a mismatchbFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedcmp
- the comparator to compare array elements-1
.IllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array or the comparator is null
public static boolean equals(long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
Two arrays are considered equal if the number of elements covered by each range is the same, and all corresponding pairs of elements over the specified ranges in the two arrays are equal. In other words, two arrays are equal if they contain, over the specified ranges, the same elements in the same order.
a
- the first array to be tested for equalityaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for equalitybFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedtrue
if the two arrays, over the specified ranges, are
equalIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static boolean equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
Two arrays are considered equal if the number of elements covered by each range is the same, and all corresponding pairs of elements over the specified ranges in the two arrays are equal. In other words, two arrays are equal if they contain, over the specified ranges, the same elements in the same order.
a
- the first array to be tested for equalityaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for equalitybFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedtrue
if the two arrays, over the specified ranges, are
equalIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static boolean equals(double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
Two arrays are considered equal if the number of elements covered by each range is the same, and all corresponding pairs of elements over the specified ranges in the two arrays are equal. In other words, two arrays are equal if they contain, over the specified ranges, the same elements in the same order.
Two doubles d1
and d2
are considered equal if:
new Double(d1).equals(new Double(d2))
(Unlike the ==
operator, this method considers
NaN
equals to itself, and 0.0d unequal to -0.0d.)a
- the first array to be tested for equalityaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for equalitybFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be testedtrue
if the two arrays, over the specified ranges, are
equalIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
Double.equals(Object)
public static int compare(int[] a, int[] b)
int
arrays lexicographically.
If the two arrays share a common prefix then the lexicographic
comparison is the result of comparing two elements, as if by
Integers.compare(int, int)
, at an index within the respective
arrays that is the prefix length.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two array lengths.
(See mismatch(int[], int[])
for the definition of a common and
proper prefix.)
A null
array reference is considered lexicographically less
than a non-null
array reference. Two null
array
references are considered equal.
The comparison is consistent with Arrays.equals
,
more specifically the following holds for arrays a
and b
:
java.util.Arrays.equals(a, b) == (J8Arrays.compare(a, b) == 0)
API Note:
This method behaves as if (for non-null
array references):
int i = J8Arrays.mismatch(a, b);
if (i >= 0 && i < Math.min(a.length, b.length))
return java8.lang.Integers.compare(a[i], b[i]);
return a.length - b.length;
a
- the first array to compareb
- the second array to compare0
if the first and second array are equal and
contain the same elements in the same order;
a value less than 0
if the first array is
lexicographically less than the second array; and
a value greater than 0
if the first array is
lexicographically greater than the second arraypublic static int compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
int
arrays lexicographically over the specified
ranges.
If the two arrays, over the specified ranges, share a common prefix
then the lexicographic comparison is the result of comparing two
elements, as if by Integers.compare(int, int)
, at a relative index
within the respective arrays that is the length of the prefix.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two range lengths.
(See mismatch(int[], int, int, int[], int, int)
for the
definition of a common and proper prefix.)
The comparison is consistent with
equals
, more
specifically the following holds for arrays a
and b
with
specified ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively:
J8Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
(J8Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
API Note:
This method behaves as if:
int i = J8Arrays.mismatch(a, aFromIndex, aToIndex,
b, bFromIndex, bToIndex);
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
return java8.lang.Integers.compare(a[aFromIndex + i], b[bFromIndex + i]);
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
a
- the first array to compareaFromIndex
- the index (inclusive) of the first element in the
first array to be comparedaToIndex
- the index (exclusive) of the last element in the
first array to be comparedb
- the second array to comparebFromIndex
- the index (inclusive) of the first element in the
second array to be comparedbToIndex
- the index (exclusive) of the last element in the
second array to be compared0
if, over the specified ranges, the first and
second array are equal and contain the same elements in the same
order;
a value less than 0
if, over the specified ranges, the
first array is lexicographically less than the second array; and
a value greater than 0
if, over the specified ranges, the
first array is lexicographically greater than the second arrayIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static int compare(long[] a, long[] b)
long
arrays lexicographically.
If the two arrays share a common prefix then the lexicographic
comparison is the result of comparing two elements, as if by
Longs.compare(long, long)
, at an index within the respective
arrays that is the prefix length.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two array lengths.
(See mismatch(long[], long[])
for the definition of a common and
proper prefix.)
A null
array reference is considered lexicographically less
than a non-null
array reference. Two null
array
references are considered equal.
The comparison is consistent with Arrays.equals
,
more specifically the following holds for arrays a
and b
:
java.util.Arrays.equals(a, b) == (J8Arrays.compare(a, b) == 0)
API Note:
This method behaves as if (for non-null
array references):
int i = J8Arrays.mismatch(a, b);
if (i >= 0 && i < Math.min(a.length, b.length))
return java8.lang.Longs.compare(a[i], b[i]);
return a.length - b.length;
a
- the first array to compareb
- the second array to compare0
if the first and second array are equal and
contain the same elements in the same order;
a value less than 0
if the first array is
lexicographically less than the second array; and
a value greater than 0
if the first array is
lexicographically greater than the second arraypublic static int compare(long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
long
arrays lexicographically over the specified
ranges.
If the two arrays, over the specified ranges, share a common prefix
then the lexicographic comparison is the result of comparing two
elements, as if by Longs.compare(long, long)
, at a relative index
within the respective arrays that is the length of the prefix.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two range lengths.
(See mismatch(long[], int, int, long[], int, int)
for the
definition of a common and proper prefix.)
The comparison is consistent with
equals
, more
specifically the following holds for arrays a
and b
with
specified ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively:
J8Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
(J8Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
API Note:
This method behaves as if:
int i = J8Arrays.mismatch(a, aFromIndex, aToIndex,
b, bFromIndex, bToIndex);
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
return java8.lang.Longs.compare(a[aFromIndex + i], b[bFromIndex + i]);
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
a
- the first array to compareaFromIndex
- the index (inclusive) of the first element in the
first array to be comparedaToIndex
- the index (exclusive) of the last element in the
first array to be comparedb
- the second array to comparebFromIndex
- the index (inclusive) of the first element in the
second array to be comparedbToIndex
- the index (exclusive) of the last element in the
second array to be compared0
if, over the specified ranges, the first and
second array are equal and contain the same elements in the same
order;
a value less than 0
if, over the specified ranges, the
first array is lexicographically less than the second array; and
a value greater than 0
if, over the specified ranges, the
first array is lexicographically greater than the second arrayIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static int compare(double[] a, double[] b)
double
arrays lexicographically.
If the two arrays share a common prefix then the lexicographic
comparison is the result of comparing two elements, as if by
Double.compare(double, double)
, at an index within the respective
arrays that is the prefix length.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two array lengths.
(See mismatch(double[], double[])
for the definition of a common
and proper prefix.)
A null
array reference is considered lexicographically less
than a non-null
array reference. Two null
array
references are considered equal.
The comparison is consistent with Arrays.equals
,
more specifically the following holds for arrays a
and b
:
java.util.Arrays.equals(a, b) == (J8Arrays.compare(a, b) == 0)
API Note:
This method behaves as if (for non-null
array references):
int i = J8Arrays.mismatch(a, b);
if (i >= 0 && i < Math.min(a.length, b.length))
return Double.compare(a[i], b[i]);
return a.length - b.length;
a
- the first array to compareb
- the second array to compare0
if the first and second array are equal and
contain the same elements in the same order;
a value less than 0
if the first array is
lexicographically less than the second array; and
a value greater than 0
if the first array is
lexicographically greater than the second arraypublic static int compare(double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
double
arrays lexicographically over the specified
ranges.
If the two arrays, over the specified ranges, share a common prefix
then the lexicographic comparison is the result of comparing two
elements, as if by Double.compare(double, double)
, at a relative
index within the respective arrays that is the length of the prefix.
Otherwise, one array is a proper prefix of the other and, lexicographic
comparison is the result of comparing the two range lengths.
(See mismatch(double[], int, int, double[], int, int)
for the
definition of a common and proper prefix.)
The comparison is consistent with
equals
, more
specifically the following holds for arrays a
and b
with
specified ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively:
J8Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
(J8Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
API Note:
This method behaves as if:
int i = J8Arrays.mismatch(a, aFromIndex, aToIndex,
b, bFromIndex, bToIndex);
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
return Double.compare(a[aFromIndex + i], b[bFromIndex + i]);
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
a
- the first array to compareaFromIndex
- the index (inclusive) of the first element in the
first array to be comparedaToIndex
- the index (exclusive) of the last element in the
first array to be comparedb
- the second array to comparebFromIndex
- the index (inclusive) of the first element in the
second array to be comparedbToIndex
- the index (exclusive) of the last element in the
second array to be compared0
if, over the specified ranges, the first and
second array are equal and contain the same elements in the same
order;
a value less than 0
if, over the specified ranges, the
first array is lexicographically less than the second array; and
a value greater than 0
if, over the specified ranges, the
first array is lexicographically greater than the second arrayIllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static int mismatch(int[] a, int[] b)
int
arrays, otherwise return -1 if no mismatch is found. The index will be
in the range of 0 (inclusive) up to the length (inclusive) of the smaller
array.
If the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(a.length, b.length) &&
J8Arrays.equals(a, 0, pl, b, 0, pl) &&
a[pl] != b[pl]
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
, share a proper
prefix if the following expression is true:
a.length != b.length &&
J8Arrays.equals(a, 0, Math.min(a.length, b.length),
b, 0, Math.min(a.length, b.length))
a
- the first array to be tested for a mismatchb
- the second array to be tested for a mismatch-1
.NullPointerException
- if either array is null
public static int mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
int
arrays over the specified ranges, otherwise return -1 if no
mismatch is found. The index will be in the range of 0 (inclusive) up to
the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
J8Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
a[aFromIndex + pl] != b[bFromIndex + pl]
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a proper
prefix if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
J8Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
a
- the first array to be tested for a mismatchaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for a mismatchbFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be tested-1
.IllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static int mismatch(long[] a, long[] b)
long
arrays, otherwise return -1 if no mismatch is found. The index will be
in the range of 0 (inclusive) up to the length (inclusive) of the smaller
array.
If the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(a.length, b.length) &&
J8Arrays.equals(a, 0, pl, b, 0, pl) &&
a[pl] != b[pl]
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
, share a proper
prefix if the following expression is true:
a.length != b.length &&
J8Arrays.equals(a, 0, Math.min(a.length, b.length),
b, 0, Math.min(a.length, b.length))
a
- the first array to be tested for a mismatchb
- the second array to be tested for a mismatch-1
.NullPointerException
- if either array is null
public static int mismatch(long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
long
arrays over the specified ranges, otherwise return -1 if no
mismatch is found. The index will be in the range of 0 (inclusive) up to
the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
J8Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
a[aFromIndex + pl] != b[bFromIndex + pl]
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a proper
prefix if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
J8Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
a
- the first array to be tested for a mismatchaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for a mismatchbFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be tested-1
.IllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static int mismatch(double[] a, double[] b)
double
arrays, otherwise return -1 if no mismatch is found. The
index will be in the range of 0 (inclusive) up to the length (inclusive)
of the smaller array.
If the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(a.length, b.length) &&
J8Arrays.equals(a, 0, pl, b, 0, pl) &&
Double.compare(a[pl], b[pl]) != 0
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
, share a proper
prefix if the following expression is true:
a.length != b.length &&
J8Arrays.equals(a, 0, Math.min(a.length, b.length),
b, 0, Math.min(a.length, b.length))
a
- the first array to be tested for a mismatchb
- the second array to be tested for a mismatch-1
.NullPointerException
- if either array is null
public static int mismatch(double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
double
arrays over the specified ranges, otherwise return -1 if
no mismatch is found. The index will be in the range of 0 (inclusive) up
to the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
J8Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
Double.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non-null
arrays, a
and b
with specified
ranges [aFromIndex
, atoIndex
) and
[bFromIndex
, btoIndex
) respectively, share a proper
prefix if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
J8Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
a
- the first array to be tested for a mismatchaFromIndex
- the index (inclusive) of the first element in the
first array to be testedaToIndex
- the index (exclusive) of the last element in the
first array to be testedb
- the second array to be tested for a mismatchbFromIndex
- the index (inclusive) of the first element in the
second array to be testedbToIndex
- the index (exclusive) of the last element in the
second array to be tested-1
.IllegalArgumentException
- if aFromIndex > aToIndex
or
if bFromIndex > bToIndex
ArrayIndexOutOfBoundsException
- if aFromIndex < 0 or aToIndex > a.length
or
if bFromIndex < 0 or bToIndex > b.length
NullPointerException
- if either array is null
public static <T> T[] toArray(Collection<T> col, IntFunction<T[]> generator)
generator
function to allocate the returned array.
If the passed collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
API Note:
This method acts as a bridge between array-based and collection-based APIs.
It allows creation of an array of a particular runtime type. Use
Collection.toArray()
to create an array whose runtime type is
Object[]
, or use Collection.toArray(T[])
to reuse an existing array.
Suppose x
is a collection known to contain only strings.
The following code can be used to dump the collection into a newly
allocated array of String
:
String[] y = J8Arrays.toArray(x, String[]::new);
Implementation Requirements:
The default implementation calls the generator function with zero
and then passes the resulting array to Collection.toArray(T[])
.
T
- the component type of the array to contain the collectioncol
- the collection to work ongenerator
- a function which produces a new array of the desired
type and the provided lengthArrayStoreException
- if the runtime type of any element in the
passed collection is not assignable to the runtime component type of the generated arrayNullPointerException
- if the collection or the generator function is nullCopyright © 2021. All rights reserved.