Package de.gurkenlabs.litiengine.util
Class ArrayUtilities
java.lang.Object
de.gurkenlabs.litiengine.util.ArrayUtilities
public final class ArrayUtilities
extends java.lang.Object
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_STRING_DELIMITER
Method Summary
Modifier and Type Method Description static <T> T[]
append(T[] input, T addItem)
Adds the specified item to the input array and returns a new array instance with the length of the input array +1.static <T> T[]
arrayCopy(T[] original)
static byte[]
concat(byte[] first, byte[] second)
Concatenates the two specified byte arrays to a new array.static double[]
concat(double[] first, double[] second)
Concatenates the two specified double arrays to a new array.static int[]
concat(int[] first, int[] second)
Concatenates the two specified int arrays to a new array.static long[]
concat(long[] first, long[] second)
Concatenates the two specified long arrays to a new array.static <T> T[]
concat(T[] first, T[] second)
Concatenates the two specified double arrays to a new array.static boolean
contains(java.lang.Object[] arr, java.lang.Object value)
Return true if the array contains the specified value.static boolean
contains(java.lang.String[] arr, java.lang.String argument, boolean ignoreCase)
Return true if the array contains the specified string argument.static <T> T[]
distinct(T[] first, T[] second)
Combines the two specified arrays by only keeping distinct values.static java.lang.String
join(boolean[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(boolean[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(byte[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(byte[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(double[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(double[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(float[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(float[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(int[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(int[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(long[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(long[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(short[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(short[] arr, java.lang.String delimiter)
static java.lang.String
join(java.lang.Object[] arr)
Joins the specified array with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(java.lang.Object[] arr, java.lang.String delimiter)
Joins the specified array with the defined delimiter.static java.lang.String
join(java.util.Collection<?> collection)
Joins the specified list with theDEFAULT_STRING_DELIMITER
.static java.lang.String
join(java.util.Collection<?> collection, java.lang.String delimiter)
Joins the specified collection with the defined delimiter.static <T> T[]
remove(T[] input, T deleteItem)
Removes the specified deleteItem from the input array and returns a trimmed new array instance without null entries.static double[]
splitDouble(java.lang.String delimiterSeparatedString)
Splits the specified string by theDEFAULT_STRING_DELIMITER
into a double array.static double[]
splitDouble(java.lang.String delimiterSeparatedString, java.lang.String delimiter)
Splits the specified string by the defined delimiter into a double array.static int[]
splitInt(java.lang.String delimiterSeparatedString)
Splits the specified string by theDEFAULT_STRING_DELIMITER
into an int array.static int[]
splitInt(java.lang.String delimiterSeparatedString, java.lang.String delimiter)
Splits the specified string by the defined delimiter into an int array.static int[]
toIntegerArray(java.util.List<java.lang.Integer> intList)
static <T> java.util.List<T>
toList(T[][] arr)
Field Details
DEFAULT_STRING_DELIMITER
public static final java.lang.String DEFAULT_STRING_DELIMITER- See Also:
- Constant Field Values
Method Details
concat
public static byte[] concat(byte[] first, byte[] second)Concatenates the two specified byte arrays to a new array.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with both specified arrays in sequence.
concat
public static int[] concat(int[] first, int[] second)Concatenates the two specified int arrays to a new array.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with both specified arrays in sequence.
concat
public static long[] concat(long[] first, long[] second)Concatenates the two specified long arrays to a new array.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with both specified arrays in sequence.
concat
public static double[] concat(double[] first, double[] second)Concatenates the two specified double arrays to a new array.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with both specified arrays in sequence.
concat
public static <T> T[] concat(T[] first, T[] second)Concatenates the two specified double arrays to a new array.- Type Parameters:
T
- The type of the array elements.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with both specified arrays in sequence.
splitInt
public static int[] splitInt(java.lang.String delimiterSeparatedString)Splits the specified string by theDEFAULT_STRING_DELIMITER
into an int array.- Parameters:
delimiterSeparatedString
- The string to split.- Returns:
- An int array with all separated elements of the specified string.
splitInt
public static int[] splitInt(java.lang.String delimiterSeparatedString, java.lang.String delimiter)Splits the specified string by the defined delimiter into an int array.- Parameters:
delimiterSeparatedString
- The string to split.delimiter
- The delimiter by which to split the elements.- Returns:
- An int array with all separated elements of the specified string.
splitDouble
public static double[] splitDouble(java.lang.String delimiterSeparatedString)Splits the specified string by theDEFAULT_STRING_DELIMITER
into a double array.- Parameters:
delimiterSeparatedString
- The string to split.- Returns:
- An double array with all separated elements of the specified string.
splitDouble
public static double[] splitDouble(java.lang.String delimiterSeparatedString, java.lang.String delimiter)Splits the specified string by the defined delimiter into a double array.- Parameters:
delimiterSeparatedString
- The string to split.delimiter
- The delimiter by which to split the elements.- Returns:
- An double array with all separated elements of the specified string.
join
public static java.lang.String join(boolean[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(boolean[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(int[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(int[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(double[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(double[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(float[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(float[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(short[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(short[] arr, java.lang.String delimiter)join
public static java.lang.String join(long[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(long[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(byte[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(byte[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(java.util.Collection<?> collection)Joins the specified list with theDEFAULT_STRING_DELIMITER
.- Parameters:
collection
- The list that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(java.util.Collection<?> collection, java.lang.String delimiter)Joins the specified collection with the defined delimiter.- Parameters:
collection
- The list that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(java.lang.Object[] arr)Joins the specified array with theDEFAULT_STRING_DELIMITER
.- Parameters:
arr
- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
join
public static java.lang.String join(java.lang.Object[] arr, java.lang.String delimiter)Joins the specified array with the defined delimiter.- Parameters:
arr
- The array that provides the elements to be joined.delimiter
- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
toList
public static <T> java.util.List<T> toList(T[][] arr)contains
public static boolean contains(java.lang.Object[] arr, java.lang.Object value)Return true if the array contains the specified value.- Parameters:
arr
- The array that is tested for the existence of the element.value
- The element to check for in the array.- Returns:
- True if the specified element is in the array; otherwise false.
contains
public static boolean contains(java.lang.String[] arr, java.lang.String argument, boolean ignoreCase)Return true if the array contains the specified string argument.- Parameters:
arr
- The array that is tested for the existence of the argument.argument
- The argument to check for in the array.ignoreCase
- A flag indicating whether the case should be ignored when checking for equality.- Returns:
- True if the specified argument is in the array; otherwise false.
remove
public static <T> T[] remove(T[] input, T deleteItem)Removes the specified deleteItem from the input array and returns a trimmed new array instance without null entries. The resulting array will have a length -1;- Type Parameters:
T
- The element type of the array.- Parameters:
input
- The original arraydeleteItem
- The item to delete- Returns:
- A new array with the length input.length - 1.
append
public static <T> T[] append(T[] input, T addItem)Adds the specified item to the input array and returns a new array instance with the length of the input array +1.- Type Parameters:
T
- The element type of the array.- Parameters:
input
- The original array.addItem
- The item to add.- Returns:
- A new array with the item to add appended at the end.
distinct
public static <T> T[] distinct(T[] first, T[] second)Combines the two specified arrays by only keeping distinct values.- Type Parameters:
T
- The element type of the array.- Parameters:
first
- The first array.second
- The second array.- Returns:
- A new array with every distinct value of the specified arrays.
arrayCopy
public static <T> T[] arrayCopy(T[] original)toIntegerArray
public static int[] toIntegerArray(java.util.List<java.lang.Integer> intList)