Class Arrays

java.lang.Object
eu.bandm.tools.util.java.Arrays

public abstract class Arrays extends Object
Library of constants and combinators for java language level arrays.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A> A[]
    append(A[] part1, A[]... parts)
    Returns an array containing all elements of the given arrays.
    static <A> A[]
    append(Class<A> range, A[]... parts)
    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[]
    filter(Predicate<? super A> pred, A... things)
    Returns an array containing only the elements that satisfy a given predicate.
    static <A> A[]
    filter(Predicate<? super A> pred, Class<A> range, A... things)
    Returns an array containing only the elements that satisfy a given predicate.
    static <A> A[]
    flatten(Object[] data, Class<A> cls)
    Makes a one-level array of non-array objects from nested arrays.
    static <A> A[]
    flatten(Object[] data, Class<A> cls, int estimatedSize)
    Makes a one-level array of non-array objects from nested arrays.
    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 instead
    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 instead

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • flatten

      public static <A> A[] flatten(Object[] data, Class<A> cls, int estimatedSize)
      Makes a one-level array of non-array objects from nested arrays. The input array may contain objects of type A and A[] and A[][], 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
      estimatedSize - 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

      public static <A> A[] flatten(Object[] data, Class<A> cls)
      Makes a one-level array of non-array objects from nested arrays. The input array may contain objects of type A and A[] and A[][], 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

      @SafeVarargs public static <A> int countNonNull(A... parts)
      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 that parts[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 instead
      Returns an array containing elements obtained from the given elements by applying a function to each.
      Type Parameters:
      A - the input element type
      B - the ouput element type
      Parameters:
      fun - the function to apply to each element
      range - the output element type
      things - an array or vararg sequence of elements
      Returns:
      an array out such that out[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 instead
      Returns an array containing elements obtained from the given elements by applying a function to each.
      Type Parameters:
      A - the input element type
      B - the ouput element type
      Parameters:
      fun - the function to apply to each element
      range - the output element type
      things - a collection of elements
      Returns:
      a collection out FIXME
    • append

      @SafeVarargs public static <A> A[] append(Class<A> range, A[]... parts)
      Returns an array containing all elements of the given arrays.
      Type Parameters:
      A - the element type
      Parameters:
      range - the element type
      parts - zero or more arrays
      Returns:
      an array containing all elements of part[0], followed by all elements of parts[1], etc.
      Throws:
      NullPointerException - if any array is null
    • append

      @SafeVarargs public static <A> A[] append(A[] part1, A[]... parts)
      Returns an array containing all elements of the given arrays.
      Type Parameters:
      A - the element type
      Parameters:
      part1 - the first array
      parts - more arrays
      Returns:
      an array containing all elements of part1, followed by all elements of parts[0], etc.
      Throws:
      NullPointerException - if any array is null
    • filter

      @SafeVarargs public static <A> A[] filter(Predicate<? super A> pred, A... things)
      Returns an array containing only the elements that satisfy a given predicate.
      Type Parameters:
      A - the element type
      Parameters:
      pred - the predicate to satisfy
      things - an array or vararg sequence of elements
      Returns:
      an array containing only those of the input elements e for which pred.test(e) is true, in the original order
      Throws:
      NullPointerException - if pred or things is null
    • filter

      @SafeVarargs public static <A> A[] filter(Predicate<? super A> pred, Class<A> range, A... things)
      Returns an array containing only the elements that satisfy a given predicate.
      Type Parameters:
      A - the element type
      Parameters:
      pred - the predicate to satisfy
      range - the element type
      things - an array or vararg sequence of elements
      Returns:
      an array containing only those of the input elements e for which pred.test(e) is true, in the original order
      Throws:
      NullPointerException - if pred or things is null