net.israfil.foundation.collections
Class ArrayUtils

java.lang.Object
  extended by net.israfil.foundation.collections.ArrayUtils

@Copyright(years={"2003","2004","2005","2006"},
           owner="Israfil Consulting Services Corporation",
           license="BSD")
public class ArrayUtils
extends java.lang.Object

An array utility class. This class is generic, so its usage is similar to the following: Foo[] foo1 = new Foo[]{ aFoo, bFoo, cFoo }; Foo[] foo2 = new Foo[]{ dFoo, eFoo, fFoo }; Foo[] fooResult = ArrayUtils.add(new Foo[],foo1,foo2); fooResult would be equivalent: new Foo[]{ aFoo, bFoo, cFoo, dFoo, eFoo, fFoo } This util is mostly helpful for putting together large batches of like arrays into a long single array, such as large groups of parameter lists or whatever.

Author:
Christian Edward Gruber

Constructor Summary
ArrayUtils()
           
 
Method Summary
static
<E> E[]
aggregate(E[] resultBucket, E[]... arrays)
          Adds arrays of like type creating a new array containing all elements of the added arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

aggregate

public static <E> E[] aggregate(E[] resultBucket,
                                E[]... arrays)
Adds arrays of like type creating a new array containing all elements of the added arrays. Note that you have to pass in a typed array, because you can't create an array from a generic type in the code. i.e. you can't do this with Generics.
   public class Foo {
       public T[] getArray() {
                T[] array = new T[a];
             }
   }
 
However, as described in the tests, you can simply pass it an empty array of that type.

Parameters:
resultBucket - An array of the type you are attempting to aggregate. Can be empty. If it has sufficient space, it will be used for the aggregated result.
arrays - The arrays to be aggregated.
Returns:
An array of the provided type, containing the aggregated contents of the provided arrays.


Copyright © 2003-2006 null. All Rights Reserved.