public final class XArrays extends Object
| Modifier and Type | Method and Description |
|---|---|
static int[] |
_intAdd(int[] a1,
int... a2) |
static int[] |
add(int[] a1,
int... a2) |
static long[] |
add(long[] a1,
long... a2) |
static <T> T[] |
add(T[] a1,
T... a2)
Adds all elements of the first array and all elements of the second array into one result array.
|
static <T> T[] |
add(T[] array,
T element) |
static <T> T[] |
and(T[] a1,
T[] a2) |
static <T> boolean |
applies(T[] array,
Predicate<? super T> predicate) |
static <D,S extends D> |
arraycopy(S[] src,
int srcPos,
D[] dest,
int destPos,
int length)
Convenience method, calling either
System.arraycopy(Object, int, Object, int, int) for
length >= 0 or reverseArraycopy(Object[], int, Object[], int, int) for length < 0
and returns dest.If length is known to be positive and performance badly matters or negative length shall be treated as an error, use System.arraycopy(Object, int, Object, int, int) directly. |
static int |
arrayHashCode(Object[] data,
int size) |
static void |
checkBounds(int arrayLength,
int start,
int bound) |
static void |
checkBounds(Object[] array,
int start,
int bound) |
static <T> T[] |
clear(T[] array) |
static <T,S extends T> |
combine(Class<T> componentType,
S[]... arrays) |
static <T> T[] |
combine(T[]... arrays) |
static <E> Class<E> |
componentType(E[] array) |
static <E> boolean |
contains(Collection<? super E> c,
E sample,
Equalator<? super E> equalator) |
static <E> boolean |
containS(Collection<E> c,
E element) |
static <E> boolean |
contains(E[] array,
E element)
This method checks if
array contains element by object identity |
static boolean |
contains(int[] values,
int value) |
static <T,S extends T> |
contains(T[] array,
S element,
Equalator<? super T> cmp) |
static <E> boolean |
containsId(Collection<E> c,
E element) |
static boolean |
containsNull(Object[] data,
int offset,
int length) |
static <T> T[] |
convertArray(Object[] objects,
Class<T> type) |
static <T> T[] |
copy(T[] array) |
static <E> E[] |
copyRange(E[] elements,
int offset,
int length) |
static <T,E extends T> |
copyTo(XGettingCollection<E> source,
T[] target)
At least for Java 1.8, the types seem to not be checked.
|
static <T,E extends T> |
copyTo(XGettingCollection<E> source,
T[] target,
int targetOffset)
At least for Java 1.8, the types seem to not be checked.
|
static <T> int |
count(T[] array,
Predicate<? super T> predicate) |
static <T> T[] |
enlarge(T[] array,
int newLength) |
static <T> T[] |
ensureContained(T[] a1,
T... a2) |
static <T> T[] |
ensureContained(T[] ts,
T t) |
static <E> boolean |
eqContains(E[] array,
E element) |
static boolean |
equals(byte[] a,
byte[] a2,
int length) |
static <E> boolean |
equals(E[] array1,
int startIndex1,
E[] array2,
int startIndex2,
int length,
Equalator<? super E> comparator) |
static boolean |
equals(Object[] array1,
Object[] array2)
Compares two Object arrays by reference of their content.
|
static byte[] |
fill(byte[] array,
byte fillElement) |
static char[] |
fill(char[] array,
char fillElement) |
static double[] |
fill(double[] array,
double fillElement) |
static float[] |
fill(float[] array,
float fillElement) |
static int[] |
fill(int[] array,
int fillElement) |
static <T> T[] |
fill(T[] array,
int offset,
int bound,
Supplier<? extends T> supplier) |
static <T> T[] |
fill(T[] array,
Supplier<? extends T> supplier) |
static <T> T[] |
fill(T[] array,
T fillElement,
int fromIndex,
int toIndex) |
static <E> E[] |
filter(E[] elements,
Predicate<? super E> predicate) |
static <E,C extends Consumer<? super E>> |
filterTo(E[] elements,
C target,
Predicate<? super E> predicate) |
static boolean |
hasNoContent(Object[] array)
Returns if the passed array is either null or has the length 0.
|
static int |
indexOf(boolean value,
boolean[] values) |
static int |
indexOf(byte[] data,
byte[] subject) |
static int |
indexOf(byte[] data,
byte[] subject,
int startIndex) |
static int |
indexOf(byte value,
byte[] values) |
static int |
indexOf(char value,
char[] values) |
static int |
indexOf(double value,
double[] values) |
static int |
indexOf(float value,
float[] values) |
static int |
indexOf(int value,
int[] values) |
static int |
indexOf(long value,
long[] values) |
static int |
indexOf(short value,
short[] values) |
static <T,S> int |
indexOf(S sample,
T[] array,
BiPredicate<T,S> predicate) |
static <T> int |
indexOf(T element,
T[] array) |
static <E,I extends Consumer<? super E>> |
iterate(E[] elements,
I iterator) |
static <E> void |
iterate(E[] elements,
int offset,
int length,
Consumer<? super E> iterator) |
static void |
iterate(int[] elements,
_intProcedure iterator) |
static void |
iterate(int[] elements,
int offset,
int length,
_intProcedure iterator) |
static void |
iterate(long[] elements,
_longProcedure iterator) |
static void |
iterate(long[] elements,
int offset,
int length,
_longProcedure iterator) |
static int |
max(int... data) |
static <T> T[] |
merge(T[] a1,
T... a2)
Merges the both passed arrays by taking all elements from
a1 (even duplicates) and adds all
elements of a2 (also duplicates as well) that are not already contained in a1. |
static int |
min(int... data) |
static <T> T[] |
not(T[] a1,
T[] a2) |
static <T> T[] |
or(T[] a1,
T[] a2) |
static <T,S extends T> |
orderByIndices(S[] elements,
int[] indices,
int indicesOffset,
T[] target)
Orders the passed elements by the passed indices.
|
static boolean[] |
rebuild(boolean[] oldArray,
int newLength) |
static byte[] |
rebuild(byte[] oldArray,
int newLength) |
static char[] |
rebuild(char[] oldArray,
int newLength) |
static double[] |
rebuild(double[] oldArray,
int newLength) |
static <E> E[] |
rebuild(E[] oldArray,
int newLength) |
static float[] |
rebuild(float[] oldArray,
int newLength) |
static int[] |
rebuild(int[] oldArray,
int newLength) |
static long[] |
rebuild(long[] oldArray,
int newLength) |
static short[] |
rebuild(short[] oldArray,
int newLength) |
static <T> T[] |
remove(T[] array,
int i) |
static <E> int |
removeAllFromArray(E[] array,
int start,
int bound,
E e)
Removed all occurances of
e from array array. |
static <E> int |
removeAllFromArray(E[] array,
int start,
int bound,
E e,
Equalator<? super E> equalator) |
static <E> int |
removeAllFromArray(E[] array,
int start,
int bound,
XGettingCollection<? extends E> elements,
Equalator<? super E> equalator) |
static int |
removeAllFromArray(int[] array,
int start,
int bound,
int e) |
static <E> int |
removeAllFromArray(XGettingCollection<? extends E> elements,
E[] array,
int start,
int bound) |
static <E> E[] |
removeDuplicates(E... elements) |
static <T> T |
removeFromIndex(T[] elements,
int size,
int i) |
static <E> int |
replaceAllInArray(E[] data,
int startLow,
int boundHigh,
E oldElement,
E newElement) |
static <E> int |
replaceAllInArray(E[] data,
int startLow,
int boundHigh,
E sample,
Equalator<? super E> equalator,
E newElement) |
static <T> T[] |
replicate(T subject,
int times) |
static <T> T[] |
reverse(T[] array) |
static int[] |
reverseArraycopy(int[] src,
int srcPos,
int[] dest,
int destPos,
int length) |
static <D,S extends D> |
reverseArraycopy(S[] src,
int srcPos,
D[] dest,
int destPos,
int length)
Reverse order counterpart to
System.arraycopy(Object, int, Object, int, int). |
static <T> T |
search(T[] array,
Predicate<? super T> predicate) |
static void |
set_booleanInBytes(byte[] bytes,
int index,
boolean value) |
static void |
set_byteInBytes(byte[] bytes,
int index,
byte value) |
static void |
set_charInBytes(byte[] bytes,
int index,
char value) |
static void |
set_doubleInBytes(byte[] bytes,
int index,
double value) |
static void |
set_floatInBytes(byte[] bytes,
int index,
float value) |
static void |
set_intInBytes(byte[] bytes,
int index,
int value) |
static void |
set_longInBytes(byte[] bytes,
int index,
long value) |
static void |
set_shortInBytes(byte[] bytes,
int index,
short value) |
static <T> T[] |
shrink(T[] array,
int newLength) |
static <E> E[] |
shuffle(E[] array,
int startIndex,
int endIndex)
Moves the contents of the given array in a random order.
|
static int[] |
shuffle(FastRandom random,
int... data) |
static long[] |
shuffle(FastRandom random,
long... data) |
static int[] |
shuffle(int... data) |
static long[] |
shuffle(long... data) |
static <T> T[] |
shuffle(T... data)
Moves the contents of the given array in a random order.
|
static int |
smoothCapacityDecrease(int oldCapacity) |
static int |
smoothCapacityIncrease(int oldCapacity) |
static byte[] |
subArray(byte[] array,
int offset,
int length) |
static char[] |
subArray(char[] array,
int offset,
int length) |
static <T> T[] |
subArray(T[] array,
int offset,
int length) |
static <T> T[] |
toReversed(T[] array) |
static <T> T[] |
toReversed(T[] array,
int offset,
int length) |
static <T> T[] |
uncheckedFill(T[] array,
int offset,
int bound,
Supplier<? extends T> supplier) |
static int |
validateArrayIndex(int arrayLength,
int index) |
static int |
validateArrayRange(int arrayLength,
int offset,
int length) |
static int |
validateArrayRange(Object[] array,
int offset,
int length) |
static void |
validateRange0toUpperBound(int upperBound,
int offset,
int length) |
static int |
validIndex(int index,
Object[] array) |
public static final void validateRange0toUpperBound(int upperBound,
int offset,
int length)
public static final int validateArrayIndex(int arrayLength,
int index)
public static final int validIndex(int index,
Object[] array)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionpublic static final int validateArrayRange(Object[] array, int offset, int length)
public static final int validateArrayRange(int arrayLength,
int offset,
int length)
public static final void checkBounds(Object[] array, int start, int bound)
public static final void checkBounds(int arrayLength,
int start,
int bound)
public static boolean hasNoContent(Object[] array)
array - the array to checktrue if the passed array has no contentpublic static final <T> T[] fill(T[] array,
Supplier<? extends T> supplier)
public static final <T> T[] fill(T[] array,
int offset,
int bound,
Supplier<? extends T> supplier)
public static final <T> T[] uncheckedFill(T[] array,
int offset,
int bound,
Supplier<? extends T> supplier)
public static final <T> T[] fill(T[] array,
T fillElement,
int fromIndex,
int toIndex)
public static final int[] fill(int[] array,
int fillElement)
public static final char[] fill(char[] array,
char fillElement)
public static final byte[] fill(byte[] array,
byte fillElement)
public static final float[] fill(float[] array,
float fillElement)
public static final double[] fill(double[] array,
double fillElement)
public static final <T> T[] clear(T[] array)
public static final <T> T[] replicate(T subject,
int times)
public static final <T> T[] subArray(T[] array,
int offset,
int length)
public static final byte[] subArray(byte[] array,
int offset,
int length)
public static final char[] subArray(char[] array,
int offset,
int length)
public static boolean equals(Object[] array1, Object[] array2)
Note that specific equality of each element is situational and thus cannot be a concern of a generic array comparison, just as it cannot be the concern of the element's class directly.
array1 - the first arrayarray2 - the second arraytrue if both arrays are equalpublic static final <E> boolean equals(E[] array1,
int startIndex1,
E[] array2,
int startIndex2,
int length,
Equalator<? super E> comparator)
public static final boolean equals(byte[] a,
byte[] a2,
int length)
public static <T> T[] add(T[] array,
T element)
public static <T> T[] remove(T[] array,
int i)
@SafeVarargs public static final <T> T[] add(T[] a1, T... a2)
T - the type of the array elementsa1 - the first arraya2 - the second arraypublic static final int[] add(int[] a1,
int... a2)
public static final long[] add(long[] a1,
long... a2)
@SafeVarargs public static final <T> T[] combine(T[]... arrays)
public static final <T,S extends T> T[] combine(Class<T> componentType, S[]... arrays)
public static final int[] _intAdd(int[] a1,
int... a2)
@SafeVarargs public static final <T> T[] merge(T[] a1, T... a2)
a1 (even duplicates) and adds all
elements of a2 (also duplicates as well) that are not already contained in a1.T - the type of the array elementsa1 - the first arraya2 - the second array@SafeVarargs public static final <T> T[] ensureContained(T[] a1, T... a2)
public static final <T> T[] ensureContained(T[] ts,
T t)
public static final <E> boolean contains(E[] array,
E element)
array contains element by object identityE - any typearray - the array to be searched inelement - the element to be searched (by identity)true if array contains element by object identity, else falsepublic static final <E> boolean eqContains(E[] array,
E element)
public static final <T,S extends T> boolean contains(T[] array,
S element,
Equalator<? super T> cmp)
public static final <E> boolean containsId(Collection<E> c, E element)
public static final <E> boolean containS(Collection<E> c, E element)
public static final <E> boolean contains(Collection<? super E> c, E sample, Equalator<? super E> equalator)
public static <E> int removeAllFromArray(E[] array,
int start,
int bound,
E e)
throws ArrayIndexOutOfBoundsException
e from array array.E - the element typearray - the array containing all elements.start - the starting offset (inclusive lower bound)bound - the bounding offset (exclusive upper bound)e - the element to be removedArrayIndexOutOfBoundsExceptionpublic static int removeAllFromArray(int[] array,
int start,
int bound,
int e)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsException@SafeVarargs public static final <E> E[] removeDuplicates(E... elements)
public static <E> int removeAllFromArray(XGettingCollection<? extends E> elements, E[] array, int start, int bound) throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionpublic static <E> int removeAllFromArray(E[] array,
int start,
int bound,
E e,
Equalator<? super E> equalator)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionpublic static <E> int removeAllFromArray(E[] array,
int start,
int bound,
XGettingCollection<? extends E> elements,
Equalator<? super E> equalator)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionpublic static final <T> T[] reverse(T[] array)
public static final <T> T[] toReversed(T[] array)
public static final <T> T[] toReversed(T[] array,
int offset,
int length)
public static final <T> T[] copy(T[] array)
public static final <T,E extends T> T[] copyTo(XGettingCollection<E> source, T[] target) throws IndexBoundsException
E - the source element typeT - the target element typesource - the source collectiontarget - the target arrayIndexBoundsExceptionpublic static final <T,E extends T> T[] copyTo(XGettingCollection<E> source, T[] target, int targetOffset) throws IndexBoundsException
E - the source element typeT - the target element typesource - the source collectiontarget - the target arraytargetOffset - the target start offsetIndexBoundsException@SafeVarargs public static final <T> T[] shuffle(T... data)
T - the element typedata - the array to shufflepublic static final <E> E[] shuffle(E[] array,
int startIndex,
int endIndex)
E - the element typearray - the array to shufflestartIndex - the start index of the shuffle rangeendIndex - the end index of the shuffle rangepublic static final int[] shuffle(int... data)
public static final int[] shuffle(FastRandom random, int... data)
public static final long[] shuffle(long... data)
public static final long[] shuffle(FastRandom random, long... data)
public static <D,S extends D> D[] arraycopy(S[] src,
int srcPos,
D[] dest,
int destPos,
int length)
System.arraycopy(Object, int, Object, int, int) for
length >= 0 or reverseArraycopy(Object[], int, Object[], int, int) for length < 0
and returns dest.System.arraycopy(Object, int, Object, int, int) directly. Otherwise, this method is a convenient
alternative to handle more flexible bi-directional array copying.D - the destination element typeS - the source element typesrc - the source arraysrcPos - the source array positiondest - the destination arraydestPos - the destination array positionlength - the length of the range to copypublic static <T> T[] enlarge(T[] array,
int newLength)
public static <T> T[] shrink(T[] array,
int newLength)
public static <T> T removeFromIndex(T[] elements,
int size,
int i)
public static final boolean containsNull(Object[] data, int offset, int length)
public static <E> E[] copyRange(E[] elements,
int offset,
int length)
public static <E> E[] filter(E[] elements,
Predicate<? super E> predicate)
public static <E,C extends Consumer<? super E>> C filterTo(E[] elements, C target, Predicate<? super E> predicate)
public static <E> int replaceAllInArray(E[] data,
int startLow,
int boundHigh,
E oldElement,
E newElement)
public static <E> int replaceAllInArray(E[] data,
int startLow,
int boundHigh,
E sample,
Equalator<? super E> equalator,
E newElement)
public static <T> T[] and(T[] a1,
T[] a2)
public static <T> T[] or(T[] a1,
T[] a2)
public static <T> T[] not(T[] a1,
T[] a2)
public static <T,S extends T> T[] orderByIndices(S[] elements,
int[] indices,
int indicesOffset,
T[] target)
throws IllegalArgumentException
T - the target element typeS - the source element typeelements - the elements to be sorted according to the passed indices.indices - the indices defining the order in which the passed elements shall be rearranged.indicesOffset - the start offset of the indicestarget - the target array to receive the sorted elements.IllegalArgumentExceptionpublic static final int min(int... data)
public static final int max(int... data)
public static final <T> boolean applies(T[] array,
Predicate<? super T> predicate)
public static final <T> T search(T[] array,
Predicate<? super T> predicate)
public static final <T> int count(T[] array,
Predicate<? super T> predicate)
public static <D,S extends D> D[] reverseArraycopy(S[] src,
int srcPos,
D[] dest,
int destPos,
int length)
System.arraycopy(Object, int, Object, int, int).
Copies source elements from src, starting at srcPos in negative direction (-length
and copies them one by one to dest, starting at destPos in positive direction (+length,
thus effectively copying the elements in reverse order.
S - the source element typeD - the destination element typesrc - the source array.srcPos - starting position in the source array (the highest index for reverse iteration).dest - the destination array.destPos - starting position in the destination data (the lowest index in the target array).length - the number of array elements to be copied in reverse order.ArrayIndexOutOfBoundsException - if copying would cause access of data outside array bounds.ArrayStoreException - if an element in the src array could not be stored into the
dest array because of a type mismatch.NullPointerException - if either src or dest is null.public static int[] reverseArraycopy(int[] src,
int srcPos,
int[] dest,
int destPos,
int length)
public static final <T> T[] convertArray(Object[] objects, Class<T> type) throws ClassCastException
ClassCastExceptionpublic static <E> Class<E> componentType(E[] array)
public static final int arrayHashCode(Object[] data, int size)
public static final boolean contains(int[] values,
int value)
public static <E,I extends Consumer<? super E>> I iterate(E[] elements, I iterator)
public static <E> void iterate(E[] elements,
int offset,
int length,
Consumer<? super E> iterator)
public static void iterate(int[] elements,
_intProcedure iterator)
public static void iterate(int[] elements,
int offset,
int length,
_intProcedure iterator)
public static void iterate(long[] elements,
_longProcedure iterator)
public static void iterate(long[] elements,
int offset,
int length,
_longProcedure iterator)
public static final <T,S> int indexOf(S sample,
T[] array,
BiPredicate<T,S> predicate)
public static final <T> int indexOf(T element,
T[] array)
public static final int indexOf(byte value,
byte[] values)
public static final int indexOf(boolean value,
boolean[] values)
public static final int indexOf(short value,
short[] values)
public static final int indexOf(char value,
char[] values)
public static final int indexOf(int value,
int[] values)
public static final int indexOf(float value,
float[] values)
public static final int indexOf(long value,
long[] values)
public static final int indexOf(double value,
double[] values)
public static final int indexOf(byte[] data,
byte[] subject)
public static final int indexOf(byte[] data,
byte[] subject,
int startIndex)
public static final byte[] rebuild(byte[] oldArray,
int newLength)
public static final boolean[] rebuild(boolean[] oldArray,
int newLength)
public static final short[] rebuild(short[] oldArray,
int newLength)
public static final char[] rebuild(char[] oldArray,
int newLength)
public static final int[] rebuild(int[] oldArray,
int newLength)
public static final float[] rebuild(float[] oldArray,
int newLength)
public static final long[] rebuild(long[] oldArray,
int newLength)
public static final double[] rebuild(double[] oldArray,
int newLength)
public static final <E> E[] rebuild(E[] oldArray,
int newLength)
public static final void set_byteInBytes(byte[] bytes,
int index,
byte value)
public static final void set_booleanInBytes(byte[] bytes,
int index,
boolean value)
public static final void set_shortInBytes(byte[] bytes,
int index,
short value)
public static final void set_charInBytes(byte[] bytes,
int index,
char value)
public static final void set_intInBytes(byte[] bytes,
int index,
int value)
public static final void set_floatInBytes(byte[] bytes,
int index,
float value)
public static final void set_longInBytes(byte[] bytes,
int index,
long value)
public static final void set_doubleInBytes(byte[] bytes,
int index,
double value)
public static final int smoothCapacityIncrease(int oldCapacity)
public static final int smoothCapacityDecrease(int oldCapacity)
Copyright © 2022 MicroStream Software. All rights reserved.