fr.inria.oadymppac.utils
Class DynamicIntArray

java.lang.Object
  extended byfr.inria.oadymppac.utils.DynamicIntArray
All Implemented Interfaces:
java.lang.Cloneable

public class DynamicIntArray
extends java.lang.Object
implements java.lang.Cloneable


Field Summary
static int NONE
          Comment for NONE This defines the NONE value for the DynamicArrayList.
 
Constructor Summary
DynamicIntArray()
          build a default dynamic integer array : The initial capacity is set to DEFAULT_EXTEND The default block size for extension is set to the DEFAULT_EXTEND
DynamicIntArray(int reserve)
          build a new dynamic integer array :
DynamicIntArray(int[] values)
          build a new dynamic integer array with predefined values
DynamicIntArray(int reserve, int extend)
          build a new dynamic integer array :
 
Method Summary
 void add(int element)
          Append a new element at the end of the array
 void add(int[] elements)
          Append a set a of new elements at the end of the array
 void clear()
          Clear the array : the content is reset but the array remains usable Its capacity remains avalilable to store new elements.
 int clear(int index)
          Clear the value of the array at index
 void clear(int from, int to)
          Clear the values contained by the array between index from and index to; the rest of the array is not
 java.lang.Object clone()
          Clone the Array (i.e. build a copy)
 int count()
          count the number of values different from NONE
 int get(int index)
          query the array to get the value stored at index
 int getExtend()
          Query the array to get it current block size for extension
 int[] getValues()
           
 void insert(int index, int[] elements)
          Insert into the array a set a of new elements at the given index
 int last()
          gives index of a significant value
 void remove(int element)
          remove all occurence of the given element from the array
 void remove(int indexFrom, int indexTo)
          Remove the element stored between index from and index to
 void removeAt(int index)
          Remove the element stored at index in the array
 int set(int index, int element)
          Store the given element at the given index
 void setExtend(int extend)
          Set the block size for extension;
 void shrink()
          collect the NONE values NOTE : calling this method
 int[] toArray()
          Build a copy of the array limited to the last element
 java.lang.String toString()
          Convert the dynamic array into a string
 java.lang.String toStringContent()
          Convert the content of the array into a string
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Comment for NONE This defines the NONE value for the DynamicArrayList. This particular value is used to mark removed element or to fill the unused space of the array

See Also:
Constant Field Values
Constructor Detail

DynamicIntArray

public DynamicIntArray()
build a default dynamic integer array : The initial capacity is set to DEFAULT_EXTEND The default block size for extension is set to the DEFAULT_EXTEND


DynamicIntArray

public DynamicIntArray(int reserve)
build a new dynamic integer array :

Parameters:
reserve - : the initial capacity of the array The default block size for extension is set to the DEFAULT_EXTEND

DynamicIntArray

public DynamicIntArray(int reserve,
                       int extend)
build a new dynamic integer array :

Parameters:
reserve - = the initial capacity
extend - = the default block size for extension

DynamicIntArray

public DynamicIntArray(int[] values)
build a new dynamic integer array with predefined values

Parameters:
values - : the intial values of this array;
Method Detail

add

public void add(int element)
Append a new element at the end of the array

Parameters:
element - : the integer appended

add

public void add(int[] elements)
Append a set a of new elements at the end of the array

Parameters:
elements - : elements to appentd

insert

public void insert(int index,
                   int[] elements)
Insert into the array a set a of new elements at the given index

Parameters:
elements - : elements to append NOTE: The previous constant is first shifted and then elements are inserted

clear

public final void clear()
Clear the array : the content is reset but the array remains usable Its capacity remains avalilable to store new elements.


clear

public int clear(int index)
Clear the value of the array at index

Parameters:
index - : the index to be cleared;
Returns:
the cleared value

clear

public void clear(int from,
                  int to)
Clear the values contained by the array between index from and index to; the rest of the array is not


clone

public final java.lang.Object clone()
                             throws java.lang.CloneNotSupportedException
Clone the Array (i.e. build a copy)

Throws:
java.lang.CloneNotSupportedException
See Also:
The content is also cloned

count

public final int count()
count the number of values different from NONE

Returns:
the number of "significant" values

get

public final int get(int index)
query the array to get the value stored at index

Parameters:
index - : the index of the value
Returns:
: the value of the array at the index

getExtend

public final int getExtend()
Query the array to get it current block size for extension

Returns:
: the size of the extension

last

public int last()
gives index of a significant value

Returns:
Returns the last .

remove

public void remove(int element)
remove all occurence of the given element from the array

Parameters:
element - : the value to remove from the array

remove

public void remove(int indexFrom,
                   int indexTo)
Remove the element stored between index from and index to

Parameters:
indexFrom - : the first index of element to be removed

removeAt

public void removeAt(int index)
Remove the element stored at index in the array

Parameters:
index - : the index of the removed
See Also:
remove(int from , int to);

set

public int set(int index,
               int element)
Store the given element at the given index

Parameters:
index - : the storage index
element - : the element to store
Returns:
: the previous value stored int the array (eventually NONE)

setExtend

public final void setExtend(int extend)
Set the block size for extension;

Parameters:
extend - : the new size for extension

toArray

public final int[] toArray()
Build a copy of the array limited to the last element

Returns:
the copied array

toString

public java.lang.String toString()
Convert the dynamic array into a string

See Also:
Object.toString()

toStringContent

public java.lang.String toStringContent()
Convert the content of the array into a string

Returns:
the string corresponding to the content

shrink

public void shrink()
collect the NONE values NOTE : calling this method


getValues

public int[] getValues()
Returns:
Returns the values.