org.vostok.io
Class Arrays

java.lang.Object
  extended by org.vostok.io.Arrays

public class Arrays
extends java.lang.Object

A collection of static method to perform actions on arrays

Author:
levreau.jerome@vostoksystem.eu

Constructor Summary
Arrays()
           
 
Method Summary
static
<T> T[]
append(T[] obj, T data)
          append "data" to the end of "obj" this is an optimized version ( a little faster than java.util.Arrays.copyOf too)
static
<T> T[]
append(T[] obj, T[] data)
          append "data" to the end of "obj" Note all elements must be of the same class
static
<T> T[]
concat(T[]... a)
          concat all arrays into a new one. didn't make copy of the inner Ts Note all arrays must be of the same type.
static
<T> T[]
flatten(T[] a)
          flatten an array or arrays into a single dimention (new) array Note all element must be of the same class
static
<T> T[]
inject(T[] obj, int index, T data)
          inject "data" into "obj" at index "index" Similar to others inject method, this one is optimized for injection of a single element Note all elements must be of the same class
static
<T> T[]
inject(T[] obj, int index, T[] data)
          inject "data" into "obj", at the index "index".
static
<T> T[]
inject(T[] obj, int index, T data, int length)
          Inject into "obj" at index "index" as much as "length" from "data", If length=1 you should concider inject(T[] obj, int index, T data),instead Note all elements must be of the same class Be aware that beside for index, the method doesn't check for valid arguments
static
<T> void
move(T[] obj, int from, int to)
          move the T at index "from" to index "to", shifting other element (up or down) For performances optimization, no arguments verification will be performed
static
<T> T[]
prepend(T[] obj, T data)
          prepend "data" to the start of "obj"
static
<T> T[]
prepend(T[] obj, T[] data)
          prepend "data" to the start of "obj"
static
<T> T[]
remove(T[] obj, int index, int length)
          Remove as mutch as "length" element(s) at index "index" from "obj".
static
<T> void
shiftLeft(T[] obj, int index, int length, int padding)
          shift "length" element(s) at index "index" from the amount "padding", padding to the left.
static
<T> void
shiftRight(T[] obj, int index, int length, int padding)
          shift "length" element(s) at index "index" from the amount "padding", padding to the right.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Arrays

public Arrays()
Method Detail

concat

public static <T> T[] concat(T[]... a)
concat all arrays into a new one. didn't make copy of the inner Ts Note all arrays must be of the same type. For performances optimization, no arguments verification will be performed With just 2 arrays, you should consider Arrays.append instead

Type Parameters:
T -
Parameters:
a - list of arrays to concat
Returns:

flatten

public static <T> T[] flatten(T[] a)
flatten an array or arrays into a single dimention (new) array Note all element must be of the same class

Type Parameters:
T -
Parameters:
a - an array of T[] to flatten
Returns:
a single dimention array

move

public static <T> void move(T[] obj,
                            int from,
                            int to)
move the T at index "from" to index "to", shifting other element (up or down) For performances optimization, no arguments verification will be performed

Parameters:
obj -
index -

remove

public static <T> T[] remove(T[] obj,
                             int index,
                             int length)
Remove as mutch as "length" element(s) at index "index" from "obj". A newly affected array will be returned. If length is bigger than available length, just cut what's available.

Parameters:
obj -
index - : index of first element to remove
length - : number of element to remove. if length bigger than element available, act as a troncate op
Returns:

shiftLeft

public static <T> void shiftLeft(T[] obj,
                                 int index,
                                 int length,
                                 int padding)
shift "length" element(s) at index "index" from the amount "padding", padding to the left.

Parameters:
obj - : arrays to work with
index - : start index
length - : number of element(s) to shift
padding - :shift up to padding, or up to the beginning of the array

shiftRight

public static <T> void shiftRight(T[] obj,
                                  int index,
                                  int length,
                                  int padding)
shift "length" element(s) at index "index" from the amount "padding", padding to the right.

Parameters:
obj - : arrays to work with
index - : start index
length - : number of element(s) to shift
padding - : shift up to padding, or until the end of the array

inject

public static <T> T[] inject(T[] obj,
                             int index,
                             T[] data)
inject "data" into "obj", at the index "index". if index bigger than or equal to obj.length, act like Arrays.concat Note all elements must be of the same class

Parameters:
obj - source array
index - : index where to inject data. if index >= obj.length, append to the end
data - : array to inject into obj
Returns:
a new array

inject

public static <T> T[] inject(T[] obj,
                             int index,
                             T data,
                             int length)
Inject into "obj" at index "index" as much as "length" from "data", If length=1 you should concider inject(T[] obj, int index, T data),instead Note all elements must be of the same class Be aware that beside for index, the method doesn't check for valid arguments

Parameters:
obj - the source array
index - : where to inject the new data. if index >= obj.length, append to the end
data - : T to add
length - : number of data to add
Returns:

inject

public static <T> T[] inject(T[] obj,
                             int index,
                             T data)
inject "data" into "obj" at index "index" Similar to others inject method, this one is optimized for injection of a single element Note all elements must be of the same class

Parameters:
obj -
index - : index to inject element into. if index >= obj.length, append to the end
data -
Returns:

append

public static <T> T[] append(T[] obj,
                             T data)
append "data" to the end of "obj" this is an optimized version ( a little faster than java.util.Arrays.copyOf too)

Parameters:
obj -
data -
Returns:
a new array

append

public static <T> T[] append(T[] obj,
                             T[] data)
append "data" to the end of "obj" Note all elements must be of the same class

Parameters:
obj -
data -
Returns:
a new array

prepend

public static <T> T[] prepend(T[] obj,
                              T data)
prepend "data" to the start of "obj"

Type Parameters:
T -
Parameters:
obj -
data -
Returns:

prepend

public static <T> T[] prepend(T[] obj,
                              T[] data)
prepend "data" to the start of "obj"

Type Parameters:
T -
Parameters:
obj -
data -
Returns: