Package eu.bandm.tools.util.java
Class Arrays
java.lang.Object
eu.bandm.tools.util.java.Arrays
Library of constants and operations for arrays.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> A[]
append
(A[] part1, A[]... parts) Returns an array containing all elements of the given arrays.static <A> A[]
Returns an array containing all elements of the given arrays.static <A> int
countNonNull
(A... parts) Returns the number of elements that are not null.static <A> A[]
Returns an array containing only the elements that satisfy a given predicate.static <A> A[]
Returns an array containing only the elements that satisfy a given predicate.static <A> A[]
Makes a one-level array of non-array objects from nested arrays.static <A> A[]
Makes a one-level array of non-array objects from nested arrays.static int[]
intArray
(Collection<Integer> data) Deprecated.Required by some deficient APIs.
-
Method Details
-
flatten
Makes a one-level array of non-array objects from nested arrays. The input array may contain objects of typeA
andA[]
andA[][]
, etc., so the procedure can only be typed dynamically.- Type Parameters:
A
- the element type- Parameters:
data
- the nested array(s)cls
- the element typeestimatedSize
- an informed guess for the required array size; if this is a valid approximation from above, then the resizing of temporary buffers can be avoided.- Returns:
- an array of all the elements of type
A
nested whithin the arrays
-
flatten
Makes a one-level array of non-array objects from nested arrays. The input array may contain objects of typeA
andA[]
andA[][]
, etc., so the procedure can only be typed dynamically.- Type Parameters:
A
- the element type- Parameters:
data
- the nested array(s)cls
- the element type- Returns:
- an array of all the elements of type
A
nested whithin the arrays
-
countNonNull
Returns the number of elements that are not null.- Type Parameters:
A
- the element type- Parameters:
parts
- an array or vararg sequence of elements- Returns:
- the number of index positions
i
such thatparts[i] != null
holds
-
append
Returns an array containing all elements of the given arrays.- Type Parameters:
A
- the element type- Parameters:
range
- the element typeparts
- zero or more arrays- Returns:
- an array containing all elements of
part[0]
, followed by all elements ofparts[1]
, etc. - Throws:
NullPointerException
- if any array is null
-
append
Returns an array containing all elements of the given arrays.- Type Parameters:
A
- the element type- Parameters:
part1
- the first arrayparts
- more arrays- Returns:
- an array containing all elements of
part1
, followed by all elements ofparts[0]
, etc. - Throws:
NullPointerException
- if any array is null
-
filter
Returns an array containing only the elements that satisfy a given predicate.- Type Parameters:
A
- the element type- Parameters:
pred
- the predicate to satisfythings
- an array or vararg sequence of elements- Returns:
- an array containing only those of the input elements
e
for whichpred.test(e)
is true, in the original order - Throws:
NullPointerException
- ifpred
orthings
is null
-
filter
Returns an array containing only the elements that satisfy a given predicate.- Type Parameters:
A
- the element type- Parameters:
pred
- the predicate to satisfyrange
- the element typethings
- an array or vararg sequence of elements- Returns:
- an array containing only those of the input elements
e
for whichpred.test(e)
is true, in the original order - Throws:
NullPointerException
- ifpred
orthings
is null
-
intArray
Deprecated.Required by some deficient APIs.Returns an array of primitive integer values.- Parameters:
data
- the integers to convert- Returns:
- an array of unboxed values
-