Package eu.bandm.tools.util.java
Class Arrays
java.lang.Object
eu.bandm.tools.util.java.Arrays
Library of constants and combinators for java language level 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 <A,
B> B[] Deprecated, for removal: This API element is subject to removal in a future version.use streams insteadstatic <A,
B> B[] map
(Function<? super A, ? extends B> fun, Class<B> range, Collection<A> things) Deprecated, for removal: This API element is subject to removal in a future version.use streams instead
-
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
-
map
@Deprecated(forRemoval=true, since="1.0") @SafeVarargs public static <A,B> B[] map(Function<? super A, ? extends B> fun, Class<B> range, A... things) Deprecated, for removal: This API element is subject to removal in a future version.use streams insteadReturns an array containing elements obtained from the given elements by applying a function to each.- Type Parameters:
A
- the input element typeB
- the ouput element type- Parameters:
fun
- the function to apply to each elementrange
- the output element typethings
- an array or vararg sequence of elements- Returns:
- an array
out
such thatout[i] = fun.apply(in[i])
holds throughout
-
map
@Deprecated(forRemoval=true, since="1.0") public static <A,B> B[] map(Function<? super A, ? extends B> fun, Class<B> range, Collection<A> things) Deprecated, for removal: This API element is subject to removal in a future version.use streams insteadReturns an array containing elements obtained from the given elements by applying a function to each.- Type Parameters:
A
- the input element typeB
- the ouput element type- Parameters:
fun
- the function to apply to each elementrange
- the output element typethings
- a collection of elements- Returns:
- a collection
out
FIXME
-
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
-