java.lang.Object
org.tquadrat.foundation.util.ArrayUtils
@UtilityClass
@ClassVersion(sourceVersion="$Id: ArrayUtils.java 1060 2023-09-24 19:21:40Z tquadrat $")
public final class ArrayUtils
extends Object
This class provides some utility functions that extends
Arrays
to some extent. All methods are static, no objects of this class are
allowed.- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: ArrayUtils.java 1060 2023-09-24 19:21:40Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.ArrayUtils"
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Prevent the creation of any object of this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
isComparableIn
(Comparable<? super T> o, T... list) This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter.static <T> boolean
isEqualIn
(T o, T... list) This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter.static boolean
isIn
(byte v, byte... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(char v, char... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(double v, double... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(float v, float... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(int v, int... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(long v, long... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static boolean
isIn
(short v, short... list) This method checks if the given value is at least once in the list that is provided as the second parameter.static <T> boolean
isIn
(T o, T... list) This method checks if the given object is in the list of objects that is provided as the second parameter.static char
max
(char... list) Determines the greatest value in the given array.static double
max
(double... list) Determines the greatest value in the given array.static int
max
(int... list) Determines the greatest value in the given array.static long
max
(long... list) Determines the greatest value in the given array.static <T> T
max
(Comparator<? super T> comparator, T... list) Determines the greatest value in the given array, based on the givenComparator
.static <T extends Comparable<T>>
Tmax
(T... list) Determines the greatest value in the given array.static char
min
(char... list) Determines the smallest value in the given array.static double
min
(double... list) Determines the smallest value in the given array.static int
min
(int... list) Determines the smallest value in the given array.static long
min
(long... list) Determines the smallest value in the given array.static <T> T
min
(Comparator<? super T> comparator, T... list) Determines the smallest value in the given array, based on the givenComparator
.static <T extends Comparable<T>>
Tmin
(T... list) Determines the smallest value in the given array.static <T> void
revert
(T... a) Modifies the given array to contain the elements in reverted order.static <T> T[]
revertCopy
(T... a) Returns a copy of the given array with the elements in reverted order.static <T> T[]
subArray
(T[] source, int start) Returns a part of the given array as a copy, beginning with the given start position to the end of the array.static <T> T[]
subArray
(T[] source, int start, int len) Returns a part of the given array as a copy.
The semantics of this method are slightly different from that inArrays
.static Object[]
toObjectArray
(Object array) Translates the given array to an array of element typeObject
.static String
toString
(Object[] array, CharSequence separator) Renders the given array to a single string where the elements are separated by the given character sequence.
This method allows to control the output a bit better thanArrays.toString(Object[])
,Objects.toString(Object)
, orObjects.toString(Object)
.
-
Field Details
-
MSG_IllegalIndex
The illegal index message.- See Also:
-
MSG_NoArray
"The message indicates that the given value is not an array."- See Also:
-
MSG_NoValues
The message indicates that the given value set is empty.- See Also:
-
-
Constructor Details
-
ArrayUtils
private ArrayUtils()Prevent the creation of any object of this class.
-
-
Method Details
-
toObjectArray
Translates the given array to an array of element typeObject
. Primitive types will be automatically converted into the respective Wrapper types.
The array elements will not be copied.- Parameters:
array
- The array to translate.- Returns:
- The translated array.
-
isComparableIn
@SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> boolean isComparableIn(Comparable<? super T> o, T... list) This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter. The test is made usingcompareTo()
. For a test on object identity, using==
, useisIn()
.- Type Parameters:
T
- The class for the objects.- Parameters:
o
- The object to look for.list
- The list of object to look into.- Returns:
true
if the object is in the list,false
otherwise.- Throws:
NullPointerException
- At least one entry oflist
isnull
.
-
isEqualIn
This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter. The test is made usingequals()
. For a test on object identity, using==
, useisIn()
.- Type Parameters:
T
- The class for the objects.- Parameters:
o
- The object to look for.list
- The list of object to look into.- Returns:
true
if the object is in the list,false
otherwise.
-
isIn
This method checks if the given object is in the list of objects that is provided as the second parameter. The test is made on object identity, using==
. For a test withequals()
, useisEqualIn()
- Type Parameters:
T
- The class for the objects.- Parameters:
o
- The object to look for; may benull
.list
- The list of object to look into.- Returns:
true
if the object is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter. The test is made on identity, using==
; this means, due to the nature ofdouble
, that values may not be found, although they appear to be equal.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter. The test is made on identity, using==
; this means, due to the nature offloat
, that values may not be found, although they appear to be equal.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
isIn
This method checks if the given value is at least once in the list that is provided as the second parameter.- Parameters:
v
- The value to look for.list
- The list of values to look into.- Returns:
true
if the value is in the list,false
otherwise.
-
max
@SafeVarargs @API(status=STABLE, since="0.1.0") public static <T> T max(Comparator<? super T> comparator, T... list) Determines the greatest value in the given array, based on the givenComparator
.- Type Parameters:
T
- The class for the objects.- Parameters:
comparator
- The comparator to use.list
- The values.- Returns:
- The greatest value in the list.
-
max
@SafeVarargs @API(status=STABLE, since="0.0.5") public static <T extends Comparable<T>> T max(T... list) Determines the greatest value in the given array.- Type Parameters:
T
- The class for the objects.- Parameters:
list
- The values.- Returns:
- The greatest value in the list.
-
max
Determines the greatest value in the given array.- Parameters:
list
- The values.- Returns:
- The greatest value in the list.
-
max
Determines the greatest value in the given array.- Parameters:
list
- The values.- Returns:
- The greatest value in the list.
-
max
Determines the greatest value in the given array.- Parameters:
list
- The values.- Returns:
- The greatest value in the list.
-
max
Determines the greatest value in the given array.- Parameters:
list
- The values.- Returns:
- The greatest value in the list.
-
min
@SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> T min(Comparator<? super T> comparator, T... list) Determines the smallest value in the given array, based on the givenComparator
.- Type Parameters:
T
- The class for the objects.- Parameters:
comparator
- The comparator.list
- The values.- Returns:
- The smallest value in the list.
-
min
@SafeVarargs @API(status=STABLE, since="0.0.5") public static <T extends Comparable<T>> T min(T... list) Determines the smallest value in the given array.- Type Parameters:
T
- The class for the objects.- Parameters:
list
- The values.- Returns:
- The smallest value in the list.
-
min
Determines the smallest value in the given array.- Parameters:
list
- The values.- Returns:
- The smallest value in the list.
-
min
Determines the smallest value in the given array.- Parameters:
list
- The values.- Returns:
- The smallest value in the list.
-
min
Determines the smallest value in the given array.- Parameters:
list
- The values.- Returns:
- The smallest value in the list.
-
min
Determines the smallest value in the given array.- Parameters:
list
- The values.- Returns:
- The smallest value in the list.
-
revert
Modifies the given array to contain the elements in reverted order.- Type Parameters:
T
- The type of the array elements.- Parameters:
a
- The array to revert.
-
revertCopy
Returns a copy of the given array with the elements in reverted order.- Type Parameters:
T
- The type of the array elements.- Parameters:
a
- The array to revert.- Returns:
- The copy in reverted order.
-
subArray
Returns a part of the given array as a copy.
The semantics of this method are slightly different from that inArrays
.- Type Parameters:
T
- The type of the array elements.- Parameters:
source
- The source array.start
- The start index.len
- The number of elements for the partial array.- Returns:
- The new array.
- See Also:
-
subArray
Returns a part of the given array as a copy, beginning with the given start position to the end of the array.- Type Parameters:
T
- The type of the array elements.- Parameters:
source
- The source array.start
- The start index.- Returns:
- The new array.
-
toString
@API(status=STABLE, since="0.0.5") public static String toString(Object[] array, CharSequence separator) Renders the given array to a single string where the elements are separated by the given character sequence.
This method allows to control the output a bit better thanArrays.toString(Object[])
,Objects.toString(Object)
, orObjects.toString(Object)
. Especially it does not frame the output with those square brackets ...- Parameters:
array
- The input array.separator
- The separator character sequence; ifnull
, the empty string is used.- Returns:
- The concatenated string.
-