org.openmobileis.common.util.collection
Class Array

java.lang.Object
  extended byorg.openmobileis.common.util.collection.Array
All Implemented Interfaces:
FilterCollection, OpenMISSerializable, java.io.Serializable

public class Array
extends java.lang.Object
implements FilterCollection, OpenMISSerializable

Use to store an Array of objects.

Since:
JDK 1.1
Version:
1.0.
Author:
Philippe Delrieu
See Also:
Serialized Form

Field Summary
protected  java.lang.Object[] elementData
          The array buffer into which the elements of the ArrayList are stored.
protected static long serialVersionUID
           
protected  int size
          The size of the ArrayList (the number of elements it contains).
 
Constructor Summary
Array()
          Constructs an empty ArrayList.Initial capacity is 10
Array(int initialCapacity)
          Constructs an empty ArrayList with the specified initial capacity.
Array(java.lang.Object[] array)
           
 
Method Summary
 boolean add(int index, java.lang.Object o)
          Appends the specified element to the end of this ArrayList.
 boolean add(java.lang.Object o)
          Appends the specified element to the end of this ArrayList.
 boolean addArray(Array a)
          Appends the specified ArrayList to the end of this ArrayList.
 void clear()
           
 java.lang.Object clone()
           
 boolean contains(java.lang.Object o)
          return true if the array contains the specified object false otherwise.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 boolean equals(java.lang.Object obj)
           
 java.lang.Object get(int index)
          Returns the element at the specified position in this ArrayList.
protected  java.lang.Object[] getArrayElements()
           
 java.lang.Object getLastAdded()
          return the last added object in the array.
 int indexOf(java.lang.Object o)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 boolean isEmpty()
          Tests if this ArrayList has no elements.
static void main(java.lang.String[] args)
           
 java.lang.Object remove(int index)
          Removes the element at the specified position in this ArrayList.
 java.lang.Object remove(java.lang.Object element)
          Removes the element in this ArrayList.
 void removeAll()
           
 boolean replace(int index, java.lang.Object o)
          replace at the specified index the element.
protected  void setArrayElements(java.lang.Object[] array)
           
 void setSize(int size)
          set the size of the array.
 int size()
          Returns the number of elements in this ArrayList.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this ArrayList in the correct order.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array containing all of the elements in this ArrayList in the correct order.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
See Also:
Constant Field Values

elementData

protected java.lang.Object[] elementData
The array buffer into which the elements of the ArrayList are stored. The capacity of the ArrayList is the length of this array buffer.


size

protected int size
The size of the ArrayList (the number of elements it contains).

Constructor Detail

Array

public Array(java.lang.Object[] array)

Array

public Array(int initialCapacity)
Constructs an empty ArrayList with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the ArrayList.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

Array

public Array()
Constructs an empty ArrayList.Initial capacity is 10

Method Detail

clear

public void clear()

getArrayElements

protected java.lang.Object[] getArrayElements()

setArrayElements

protected void setArrayElements(java.lang.Object[] array)

ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

size

public int size()
Returns the number of elements in this ArrayList.

Returns:
the number of elements in this ArrayList.

setSize

public void setSize(int size)
set the size of the array. All element after the size are removed.


isEmpty

public boolean isEmpty()
Tests if this ArrayList has no elements.

Returns:
true if this ArrayList has no elements; false otherwise.

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this ArrayList in the correct order.

Returns:
an array containing all of the elements in this ArrayList in the correct order.

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this ArrayList in the correct order. The runtime type of the returned array is that of the specified array. If the ArrayList fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this ArrayList.

If the ArrayList fits in the specified array with room to spare (i.e., the ArrayList has more elements than the array), the element in the array immediately following the end of the collection is set to null.

Parameters:
a - the array into which the elements of the ArrayList are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the ArrayList.
Throws:
java.lang.ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this ArrayList.

get

public java.lang.Object get(int index)
Returns the element at the specified position in this ArrayList.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this ArrayList.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

add

public boolean add(java.lang.Object o)
Appends the specified element to the end of this ArrayList.

Specified by:
add in interface FilterCollection
Parameters:
o - element to be appended to this ArrayList.
Returns:
true.

replace

public boolean replace(int index,
                       java.lang.Object o)
replace at the specified index the element. if there is no element at index add the new one at the end of the array.

Parameters:
index - index in the array where element is replaced.
o - element to be replaced to this ArrayList.
Returns:
true.

add

public boolean add(int index,
                   java.lang.Object o)
Appends the specified element to the end of this ArrayList.

Parameters:
o - element to be appended to this ArrayList.
Returns:
true.

getLastAdded

public java.lang.Object getLastAdded()
return the last added object in the array.

Returns:
last added Object.

contains

public boolean contains(java.lang.Object o)
return true if the array contains the specified object false otherwise.

Returns:
true if the specified object is inside the array.

indexOf

public int indexOf(java.lang.Object o)
Searches for the first occurence of the given argument, testing for equality using the equals method. return the index of the occurence, -1 if not found

Returns:
index of the first occurence, -1 if not found.

addArray

public boolean addArray(Array a)
Appends the specified ArrayList to the end of this ArrayList.

Parameters:
a - ArrayList to be appended to this ArrayList..
Returns:
true.

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this ArrayList. Shifts any subsequent elements to the left (subtracts one from their indices).

Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the ArrayList.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

remove

public java.lang.Object remove(java.lang.Object element)
Removes the element in this ArrayList. To find the element, array element is compared with equals method until found.

Parameters:
element - to removed.
Returns:
the element that was removed from the ArrayList. Null if not found.

removeAll

public void removeAll()

main

public static void main(java.lang.String[] args)

clone

public java.lang.Object clone()

equals

public boolean equals(java.lang.Object obj)


Copyright 2006 OpenMobileIS. All Rights Reserved.