Package net.dermetfan.utils
Class ArrayUtils
java.lang.Object
net.dermetfan.utils.ArrayUtils
- Direct Known Subclasses:
ArrayUtils
public class ArrayUtils
extends java.lang.Object
array utility methods
-
Constructor Summary
Constructors Constructor Description ArrayUtils()
-
Method Summary
Modifier and Type Method Description static java.lang.Boolean[]
box(boolean[] values)
static java.lang.Float[]
box(float[] values)
static java.lang.Integer[]
box(int[] values)
static void
checkRegion(float[] array, int offset, int length)
static void
checkRegion(int[] array, int offset, int length)
static void
checkRegion(java.lang.Object[] array, int offset, int length)
static <T, T2 extends T>
booleancontains(T[] array, T2[] other, boolean identity)
static <T> boolean
contains(T[] array, T value, boolean identity)
static <T, T2 extends T>
booleancontainsAny(T[] array, T2[] other, boolean identity)
static boolean
equalsAny(java.lang.Object obj, java.lang.Object[] array)
static boolean
equalsAny(java.lang.Object obj, java.lang.Object[] array, int offset, int length)
static float
getRepeated(float[] array, int index)
static int
getRepeated(int[] array, int index)
static <T> T
getRepeated(T[] array, int index)
static boolean
regionEquals(byte[] array, int offset, byte[] other)
static boolean
regionEquals(byte[] array, int offset, int length, byte[] other)
static boolean
regionEquals(byte[] array, int offset, int length, byte[] other, int otherOffset)
static boolean
regionEquals(double[] array, int offset, double[] other, double epsilon)
static boolean
regionEquals(double[] array, int offset, int length, double[] other, double epsilon)
static boolean
regionEquals(double[] array, int offset, int length, double[] other, int otherOffset, double epsilon)
static boolean
regionEquals(float[] array, int offset, float[] other, float epsilon)
static boolean
regionEquals(float[] array, int offset, int length, float[] other, float epsilon)
static boolean
regionEquals(float[] array, int offset, int length, float[] other, int otherOffset, float epsilon)
static boolean
regionEquals(int[] array, int offset, int[] other)
static boolean
regionEquals(int[] array, int offset, int length, int[] other)
static boolean
regionEquals(int[] array, int offset, int length, int[] other, int otherOffset)
static boolean
regionEquals(long[] array, int offset, int length, long[] other)
static boolean
regionEquals(long[] array, int offset, int length, long[] other, int otherOffset)
static boolean
regionEquals(long[] array, int offset, long[] other)
static boolean
regionEquals(short[] array, int offset, int length, short[] other)
static boolean
regionEquals(short[] array, int offset, int length, short[] other, int otherOffset)
static boolean
regionEquals(short[] array, int offset, short[] other)
static boolean
regionEquals(java.lang.Object[] array, int offset, int length, java.lang.Object[] other, boolean identity)
static boolean
regionEquals(java.lang.Object[] array, int offset, int length, java.lang.Object[] other, int otherOffset, boolean identity)
static boolean
regionEquals(java.lang.Object[] array, int offset, java.lang.Object[] other, boolean identity)
static int
repeat(int length, int index)
static int
repeat(int offset, int length, int index)
Repeats the given index within the given length (of an array).static void
requireCapacity(float[] source, int offset, int length, float[] dest, int destOffset)
throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offsetstatic void
requireCapacity(int[] source, int offset, int length, int[] dest, int destOffset)
throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offsetstatic void
requireCapacity(java.lang.Object[] source, int offset, int length, java.lang.Object[] dest, int destOffset)
throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offsetstatic float[]
select(float[] items, int everyXth)
static float[]
select(float[] items, int[] indices)
static float[]
select(float[] items, int[] indices, float[] dest)
static float[]
select(float[] items, int[] indices, float[] dest, int destOffset)
static float[]
select(float[] items, int[] indices, int indicesOffset, int indicesLength, float[] dest, int destOffset)
static float[]
select(float[] items, int everyXth, float[] dest)
static float[]
select(float[] items, int start, int everyXth)
static float[]
select(float[] items, int start, int everyXth, float[] dest)
static float[]
select(float[] items, int offset, int length, int start, int everyXth)
static float[]
select(float[] items, int offset, int length, int start, int everyXth, float[] dest)
static float[]
select(float[] items, int offset, int length, int start, int everyXth, float[] dest, int destOffset)
static int[]
select(int[] items, int everyXth)
static int[]
select(int[] items, int[] indices)
static int[]
select(int[] items, int[] indices, int[] dest)
static int[]
select(int[] items, int[] indices, int[] dest, int destOffset)
static int[]
select(int[] items, int[] indices, int indicesOffset, int indicesLength, int[] dest, int destOffset)
static int[]
select(int[] items, int start, int everyXth)
static int[]
select(int[] items, int everyXth, int[] dest)
static int[]
select(int[] items, int start, int everyXth, int[] dest)
static int[]
select(int[] items, int offset, int length, int start, int everyXth)
static int[]
select(int[] items, int offset, int length, int start, int everyXth, int[] dest)
static int[]
select(int[] items, int offset, int length, int start, int everyXth, int[] dest, int destOffset)
static <T> T[]
select(T[] items, int everyXth)
static <T> T[]
select(T[] items, int[] indices)
static <T> T[]
select(T[] items, int[] indices, int indicesOffset, int indicesLength, T[] dest, int destOffset)
static <T> T[]
select(T[] items, int[] indices, T[] dest)
static <T> T[]
select(T[] items, int[] indices, T[] dest, int destOffset)
static <T> T[]
select(T[] items, int start, int everyXth)
static <T> T[]
select(T[] items, int offset, int length, int start, int everyXth)
static <T> T[]
select(T[] items, int offset, int length, int start, int everyXth, T[] dest)
static <T> T[]
select(T[] items, int offset, int length, int start, int everyXth, T[] dest, int destOffset)
static <T> T[]
select(T[] items, int start, int everyXth, T[] dest)
static <T> T[]
select(T[] items, int everyXth, T[] dest)
static int
selectCount(int offset, int length, int start, int everyXth)
static void
shift(float[] array, int shift)
static void
shift(float[] array, int offset, int length, int shift)
static void
shift(int[] array, int shift)
static void
shift(int[] array, int offset, int length, int shift)
static void
shift(java.lang.Object[] array, int shift)
static void
shift(java.lang.Object[] array, int offset, int length, int shift)
static void
shuffle(float[] array)
static void
shuffle(float[] array, int offset, int length)
shuffles the given arraystatic void
shuffle(int[] array)
static void
shuffle(int[] array, int offset, int length)
shuffles the given arraystatic void
shuffle(java.lang.Object[] array)
static void
shuffle(java.lang.Object[] array, int offset, int length)
shuffles the given arraystatic java.lang.String
toString(float[] array)
static java.lang.String
toString(float[] array, int offset, int length)
static java.lang.String
toString(float[] array, int offset, int length, java.lang.String separator)
a more sophisticated version ofArrays.toString(Object[])
static java.lang.String
toString(float[] array, java.lang.String separator)
static java.lang.String
toString(int[] array)
static java.lang.String
toString(int[] array, int offset, int length)
static java.lang.String
toString(int[] array, int offset, int length, java.lang.String separator)
a more sophisticated version ofArrays.toString(Object[])
static java.lang.String
toString(int[] array, java.lang.String separator)
static java.lang.String
toString(java.lang.Object[] array)
static java.lang.String
toString(java.lang.Object[] array, int offset, int length)
static java.lang.String
toString(java.lang.Object[] array, int offset, int length, java.lang.String separator)
a more sophisticated version ofArrays.toString(Object[])
static java.lang.String
toString(java.lang.Object[] array, java.lang.String separator)
static boolean[]
unbox(java.lang.Boolean[] values)
static float[]
unbox(java.lang.Float[] values)
static int[]
unbox(java.lang.Integer[] values)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
toString
public static java.lang.String toString(java.lang.Object[] array)- See Also:
toString(Object[], int, int)
-
toString
public static java.lang.String toString(java.lang.Object[] array, java.lang.String separator)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(java.lang.Object[] array, int offset, int length)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(java.lang.Object[] array, int offset, int length, java.lang.String separator)a more sophisticated version ofArrays.toString(Object[])
-
toString
public static java.lang.String toString(int[] array)- See Also:
toString(Object[], int, int)
-
toString
public static java.lang.String toString(int[] array, java.lang.String separator)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(int[] array, int offset, int length)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(int[] array, int offset, int length, java.lang.String separator)a more sophisticated version ofArrays.toString(Object[])
-
toString
public static java.lang.String toString(float[] array)- See Also:
toString(Object[], int, int)
-
toString
public static java.lang.String toString(float[] array, java.lang.String separator)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(float[] array, int offset, int length)- See Also:
toString(Object[], int, int, String)
-
toString
public static java.lang.String toString(float[] array, int offset, int length, java.lang.String separator)a more sophisticated version ofArrays.toString(Object[])
-
getRepeated
public static <T> T getRepeated(T[] array, int index)- Parameters:
array
- the array from which to access a value at the wrapped index- Returns:
- the value at the wrapped index
- See Also:
repeat(int, int)
-
getRepeated
public static int getRepeated(int[] array, int index)- See Also:
getRepeated(Object[], int)
-
getRepeated
public static float getRepeated(float[] array, int index)- See Also:
getRepeated(Object[], int)
-
repeat
public static int repeat(int length, int index)- See Also:
repeat(int, int, int)
-
repeat
public static int repeat(int offset, int length, int index)Repeats the given index within the given length (of an array). For example for a length of 10:
index returns 0 0 5 5 10 0 15 5 20 0 55 5 - Parameters:
length
- the length of the arrayindex
- the index to repeat- Returns:
- the repeated index
-
contains
public static <T> boolean contains(T[] array, T value, boolean identity)- Parameters:
array
- the array that may contain the given valuevalue
- the value to search for in the given arrayidentity
- if==
comparison should be used instead ofequals(Object)
- Returns:
- if the given value is contained in the given array
-
contains
public static <T, T2 extends T> boolean contains(T[] array, T2[] other, boolean identity)- Type Parameters:
T
- the type of the containing arrayT2
- the type of the contained array- Parameters:
array
- the array to check if it contains the other array's valuesother
- the array to check if it is contained in the other array- Returns:
- if the second given array's values are completely contained in the first array
-
containsAny
public static <T, T2 extends T> boolean containsAny(T[] array, T2[] other, boolean identity)- Type Parameters:
T
- the type of the containing arrayT2
- the type of the contained array- Parameters:
array
- the array to check if it contains the other array's valuesother
- the array to check if any of its values is contained in the other array- Returns:
- if any value from the second array is contained in the first array
-
regionEquals
public static boolean regionEquals(java.lang.Object[] array, int offset, int length, java.lang.Object[] other, int otherOffset, boolean identity)- Parameters:
offset
- the region offset in the arraylength
- the region length in the arrayotherOffset
- the region offset in the other arrayidentity
- if==
comparison should be used instead ofequals(Object)
- Returns:
- whether the specified region in both arrays matches
- Since:
- 0.13.5
-
regionEquals
public static boolean regionEquals(java.lang.Object[] array, int offset, int length, java.lang.Object[] other, boolean identity) -
regionEquals
public static boolean regionEquals(java.lang.Object[] array, int offset, java.lang.Object[] other, boolean identity) -
regionEquals
public static boolean regionEquals(long[] array, int offset, int length, long[] other, int otherOffset) -
regionEquals
public static boolean regionEquals(long[] array, int offset, int length, long[] other) -
regionEquals
public static boolean regionEquals(long[] array, int offset, long[] other)- See Also:
regionEquals(long[], int, int, long[])
-
regionEquals
public static boolean regionEquals(int[] array, int offset, int length, int[] other, int otherOffset) -
regionEquals
public static boolean regionEquals(int[] array, int offset, int length, int[] other) -
regionEquals
public static boolean regionEquals(int[] array, int offset, int[] other)- See Also:
regionEquals(int[], int, int, int[])
-
regionEquals
public static boolean regionEquals(double[] array, int offset, int length, double[] other, int otherOffset, double epsilon) -
regionEquals
public static boolean regionEquals(double[] array, int offset, int length, double[] other, double epsilon) -
regionEquals
public static boolean regionEquals(double[] array, int offset, double[] other, double epsilon) -
regionEquals
public static boolean regionEquals(float[] array, int offset, int length, float[] other, int otherOffset, float epsilon) -
regionEquals
public static boolean regionEquals(float[] array, int offset, int length, float[] other, float epsilon) -
regionEquals
public static boolean regionEquals(float[] array, int offset, float[] other, float epsilon) -
regionEquals
public static boolean regionEquals(short[] array, int offset, int length, short[] other, int otherOffset) -
regionEquals
public static boolean regionEquals(short[] array, int offset, int length, short[] other) -
regionEquals
public static boolean regionEquals(short[] array, int offset, short[] other)- See Also:
regionEquals(short[], int, int, short[])
-
regionEquals
public static boolean regionEquals(byte[] array, int offset, int length, byte[] other, int otherOffset) -
regionEquals
public static boolean regionEquals(byte[] array, int offset, int length, byte[] other) -
regionEquals
public static boolean regionEquals(byte[] array, int offset, byte[] other)- See Also:
regionEquals(byte[], int, int, byte[])
-
equalsAny
public static boolean equalsAny(java.lang.Object obj, java.lang.Object[] array, int offset, int length)- Parameters:
obj
- the object to comparearray
- the array which items to compare- Returns:
- if the given object equals any of the items in the given array
-
equalsAny
public static boolean equalsAny(java.lang.Object obj, java.lang.Object[] array)- See Also:
equalsAny(Object, Object[], int, int)
-
shift
public static void shift(java.lang.Object[] array, int shift)- See Also:
shift(Object[], int, int, int)
-
shift
public static void shift(java.lang.Object[] array, int offset, int length, int shift)- Parameters:
array
- the array to shiftshift
- The amount by which to shift. 1 means that every item will be moved 1 index to the right.
-
shift
public static void shift(int[] array, int shift)- See Also:
shift(int[], int, int, int)
-
shift
public static void shift(int[] array, int offset, int length, int shift)- Parameters:
array
- the array to shiftshift
- The amount by which to shift. 1 means that every item will be moved 1 index to the right.
-
shift
public static void shift(float[] array, int shift)- See Also:
shift(float[], int, int, int)
-
shift
public static void shift(float[] array, int offset, int length, int shift)- Parameters:
array
- the array to shiftshift
- The amount by which to shift. 1 means that every item will be moved 1 index to the right.
-
shuffle
public static void shuffle(java.lang.Object[] array)- See Also:
shuffle(Object[], int, int)
-
shuffle
public static void shuffle(java.lang.Object[] array, int offset, int length)shuffles the given array- Parameters:
array
- the array to shuffle
-
shuffle
public static void shuffle(int[] array)- See Also:
shuffle(int[], int, int)
-
shuffle
public static void shuffle(int[] array, int offset, int length)shuffles the given array- Parameters:
array
- the array to shuffle
-
shuffle
public static void shuffle(float[] array)- See Also:
shuffle(float[], int, int)
-
shuffle
public static void shuffle(float[] array, int offset, int length)shuffles the given array- Parameters:
array
- the array to shuffle
-
unbox
public static float[] unbox(java.lang.Float[] values)- Returns:
- an array of the unboxed values from the given values
- See Also:
box(float[])
-
box
public static java.lang.Float[] box(float[] values)- Returns:
- an array of the boxed values from the given values
- See Also:
unbox(Float[])
-
unbox
public static int[] unbox(java.lang.Integer[] values)- Returns:
- an array of the unboxed values from the given values
- See Also:
box(int[])
-
box
public static java.lang.Integer[] box(int[] values)- Returns:
- an array of the boxed values from the given values
- See Also:
unbox(Integer[])
-
unbox
public static boolean[] unbox(java.lang.Boolean[] values)- Returns:
- an array of the unboxed values from the given values
- See Also:
box(boolean[])
-
box
public static java.lang.Boolean[] box(boolean[] values)- Returns:
- an array of the boxed values from the given values
- See Also:
unbox(Boolean[])
-
checkRegion
public static void checkRegion(java.lang.Object[] array, int offset, int length)- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid region is specifiedjava.lang.IllegalArgumentException
- if the array is null
-
requireCapacity
public static void requireCapacity(java.lang.Object[] source, int offset, int length, java.lang.Object[] dest, int destOffset)throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset- Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException
- See Also:
checkRegion(Object[], int, int)
-
selectCount
public static int selectCount(int offset, int length, int start, int everyXth)- Parameters:
start
- the index at which to start (may be negative)offset
- the index at which the array interval to uselength
- the length of the array interval to useeveryXth
- select every xth item- Returns:
- the capacity needed in the output array
- See Also:
select(Object[], int, int, int, int, Object[], int)
-
select
public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth, T[] dest, int destOffset)- Parameters:
items
- the items to select fromstart
- the array index at which to start (may be negative)everyXth
- select every xth of itemsdest
- The array to put the values in. Must have at least the capacity returned byselectCount
.- Returns:
- the dest array containing everyXth item of the given items array
- Throws:
java.lang.IllegalArgumentException
- if the given dest array is not null and smaller than the required length
-
select
public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth, T[] dest) -
select
public static <T> T[] select(T[] items, int start, int everyXth, T[] dest) -
select
public static <T> T[] select(T[] items, int everyXth, T[] dest)- See Also:
select(Object[], int, int, Object[])
-
select
public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth) -
select
public static <T> T[] select(T[] items, int start, int everyXth)- See Also:
select(Object[], int, int, int, int)
-
select
public static <T> T[] select(T[] items, int everyXth)- See Also:
select(Object[], int, int)
-
select
public static <T> T[] select(T[] items, int[] indices, int indicesOffset, int indicesLength, T[] dest, int destOffset)- Parameters:
items
- the items to select fromindices
- the indices to selectdest
- the array to fill- Returns:
- the given dest array
-
select
public static <T> T[] select(T[] items, int[] indices, T[] dest, int destOffset) -
select
public static <T> T[] select(T[] items, int[] indices, T[] dest)- See Also:
select(Object[], int[], Object[], int)
-
select
public static <T> T[] select(T[] items, int[] indices)- See Also:
select(Object[], int[], Object[])
-
checkRegion
public static void checkRegion(float[] array, int offset, int length)- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid region is specifiedjava.lang.NullPointerException
- if the array is null
-
requireCapacity
public static void requireCapacity(float[] source, int offset, int length, float[] dest, int destOffset)throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset- Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException
- See Also:
checkRegion(float[], int, int)
-
select
public static float[] select(float[] items, int offset, int length, int start, int everyXth, float[] dest, int destOffset)- Parameters:
items
- the items to select fromstart
- the array index at which to start (may be negative)everyXth
- select every xth of itemsdest
- The array to put the values in. Must have at least the capacity returned byselectCount
.- Returns:
- the dest array containing everyXth item of the given items array
- Throws:
java.lang.IllegalArgumentException
- if the given dest array is not null and smaller than the required length
-
select
public static float[] select(float[] items, int offset, int length, int start, int everyXth, float[] dest) -
select
public static float[] select(float[] items, int start, int everyXth, float[] dest) -
select
public static float[] select(float[] items, int everyXth, float[] dest)- See Also:
select(Object[], int, int, Object[])
-
select
public static float[] select(float[] items, int offset, int length, int start, int everyXth) -
select
public static float[] select(float[] items, int start, int everyXth)- See Also:
select(Object[], int, int, int, int)
-
select
public static float[] select(float[] items, int everyXth)- See Also:
select(Object[], int, int)
-
select
public static float[] select(float[] items, int[] indices, int indicesOffset, int indicesLength, float[] dest, int destOffset)- Parameters:
items
- the items to select fromindices
- the indices to selectdest
- the array to fill- Returns:
- the given dest array
-
select
public static float[] select(float[] items, int[] indices, float[] dest, int destOffset) -
select
public static float[] select(float[] items, int[] indices, float[] dest)- See Also:
select(Object[], int[], Object[], int)
-
select
public static float[] select(float[] items, int[] indices)- See Also:
select(Object[], int[], Object[])
-
checkRegion
public static void checkRegion(int[] array, int offset, int length)- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid region is specifiedjava.lang.IllegalArgumentException
- if the array is null
-
requireCapacity
public static void requireCapacity(int[] source, int offset, int length, int[] dest, int destOffset)throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset- Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException
- See Also:
checkRegion(int[], int, int)
-
select
public static int[] select(int[] items, int offset, int length, int start, int everyXth, int[] dest, int destOffset)- Parameters:
items
- the items to select fromstart
- the array index at which to start (may be negative)everyXth
- select every xth of itemsdest
- The array to put the values in. Must have at least the capacity returned byselectCount
.- Returns:
- the dest array containing everyXth item of the given items array
- Throws:
java.lang.IllegalArgumentException
- if the given dest array is not null and smaller than the required length
-
select
public static int[] select(int[] items, int offset, int length, int start, int everyXth, int[] dest) -
select
public static int[] select(int[] items, int start, int everyXth, int[] dest) -
select
public static int[] select(int[] items, int everyXth, int[] dest)- See Also:
select(Object[], int, int, Object[])
-
select
public static int[] select(int[] items, int offset, int length, int start, int everyXth) -
select
public static int[] select(int[] items, int start, int everyXth)- See Also:
select(Object[], int, int, int, int)
-
select
public static int[] select(int[] items, int everyXth)- See Also:
select(Object[], int, int)
-
select
public static int[] select(int[] items, int[] indices, int indicesOffset, int indicesLength, int[] dest, int destOffset)- Parameters:
items
- the items to select fromindices
- the indices to selectdest
- the array to fill- Returns:
- the given dest array
-
select
public static int[] select(int[] items, int[] indices, int[] dest, int destOffset) -
select
public static int[] select(int[] items, int[] indices, int[] dest)- See Also:
select(Object[], int[], Object[], int)
-
select
public static int[] select(int[] items, int[] indices)- See Also:
select(Object[], int[], Object[])
-