org.garret.consus
Class AnyArray

java.lang.Object
  extended by org.garret.consus.AnyArray

public class AnyArray
extends java.lang.Object

Modification (insert, remove) and search operastions with Java arrays


Constructor Summary
AnyArray()
           
 
Method Summary
static java.lang.Object add(java.lang.Object[] arr, java.lang.Object val)
          Append new element to the array if there is no such element in the array.
static java.lang.Object append(java.lang.Object[] arr, java.lang.Object val)
          Append one element to the array.
static int find(java.lang.Object[] arr, java.lang.Object val)
          Find object in the array.
static java.lang.Object insert(java.lang.Object arr)
          Extend array by one element
static java.lang.Object insert(java.lang.Object arr, int n)
          Insert n elemenst at the end of array
static java.lang.Object insert(java.lang.Object arr, int pos, int n)
          Insert n elements at the position pos.
static int length(java.lang.Object arr)
          Get array length.
static void memcpy(java.lang.Object dst, int dstPos, java.lang.Object src, int srcPos, int n)
          Copy array elements.
static java.lang.Object prepend(java.lang.Object[] arr, java.lang.Object val)
          Insert object at the first position in the array.
static java.lang.Object remove(java.lang.Object arr)
          Truncate array by one element
static java.lang.Object remove(java.lang.Object[] arr, java.lang.Object elem)
          Remove object from the array.
static java.lang.Object remove(java.lang.Object arr, int from)
          Remove one element from the specified position
static java.lang.Object remove(java.lang.Object arr, int from, int n)
          Remove n elements starting from the position from
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnyArray

public AnyArray()
Method Detail

add

public static java.lang.Object add(java.lang.Object[] arr,
                                   java.lang.Object val)
Append new element to the array if there is no such element in the array.

Parameters:
arr - original array
val - object to be appended
Returns:
new array

append

public static java.lang.Object append(java.lang.Object[] arr,
                                      java.lang.Object val)
Append one element to the array.

Parameters:
arr - original array
val - object to be appended
Returns:
new array

find

public static int find(java.lang.Object[] arr,
                       java.lang.Object val)
Find object in the array. The method uses == operator for comparing objects.

Parameters:
arr - original array
val - object to be found
Returns:
index of object (-1 if object is not present in the array).

insert

public static java.lang.Object insert(java.lang.Object arr)
Extend array by one element

Parameters:
arr - original array
Returns:
new array

insert

public static java.lang.Object insert(java.lang.Object arr,
                                      int n)
Insert n elemenst at the end of array

Parameters:
arr - original array
n - number of inserted elements
Returns:
new array

insert

public static java.lang.Object insert(java.lang.Object arr,
                                      int pos,
                                      int n)
Insert n elements at the position pos.

Parameters:
arr - original array
pos - insert position
n - number of elements to be added
Returns:
new array

length

public static int length(java.lang.Object arr)
Get array length.

Parameters:
arr - array
Returns:
number of elements in the array.

memcpy

public static void memcpy(java.lang.Object dst,
                          int dstPos,
                          java.lang.Object src,
                          int srcPos,
                          int n)
Copy array elements. This method calls System.arraycopy but with the order of parameters as expected by C programmers.

Parameters:
dst - destination array
dstPos - start position in destination array
src - source array
srcPos - start position in source array
n - number of elements to be copied

prepend

public static java.lang.Object prepend(java.lang.Object[] arr,
                                       java.lang.Object val)
Insert object at the first position in the array.

Parameters:
arr - original array
val - object to be inserted
Returns:
new array

remove

public static java.lang.Object remove(java.lang.Object arr)
Truncate array by one element

Parameters:
arr - original array
Returns:
new array

remove

public static java.lang.Object remove(java.lang.Object[] arr,
                                      java.lang.Object elem)
Remove object from the array. Method first tries to locate specified object and remove it if the object was found. Method uses == operator for comparing objects.

Parameters:
arr - original array
elem - object to be remove
Returns:
new array (the same if object was not found in array)

remove

public static java.lang.Object remove(java.lang.Object arr,
                                      int from)
Remove one element from the specified position

Parameters:
arr - original array
from - position of removed element
Returns:
new array

remove

public static java.lang.Object remove(java.lang.Object arr,
                                      int from,
                                      int n)
Remove n elements starting from the position from

Parameters:
arr - original array
from - position of removed element
n - number of elements to be removed
Returns:
new array