de.jstacs.utils
Class IntList

java.lang.Object
  extended by de.jstacs.utils.IntList
All Implemented Interfaces:
Cloneable

public final class IntList
extends Object
implements Cloneable

A simple list of primitive type int.

Author:
Jens Keilwagen

Constructor Summary
IntList()
          This is the default constructor that creates an IntList with initial length 10.
IntList(int size)
          This is the default constructor that creates an IntList with initial length size.
 
Method Summary
 void add(int val)
          Adds the element val at the end of the list.
 int addConditional(int val)
          Adds val to the list only if it is not already contained in the list.
 void clear()
          Removes all elements from the list.
 IntList clone()
           
 int contains(int val)
          Checks if val is already returned in the list.
 boolean equals(Object o)
           
 int get(int index)
          Returns the element with the specified index.
 int length()
          Returns the number of inserted elements.
 int pop()
          Returns the last element and removes it from the list.
 void reverse()
          This method reverses the list, i.e., after invoking this method the formerly first element is than the last, the formerly second element is than the last but one, ...
 void sort()
          This method sorts the elements of the list.
 int[] toArray()
          This method returns an int array containing all elements of the list.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntList

public IntList()
This is the default constructor that creates an IntList with initial length 10.


IntList

public IntList(int size)
        throws IllegalArgumentException
This is the default constructor that creates an IntList with initial length size.

Parameters:
size - the initial size, has to be positive
Throws:
IllegalArgumentException - if size is less than 1
Method Detail

clone

public IntList clone()
              throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

add

public void add(int val)
Adds the element val at the end of the list.

Parameters:
val - the element that should be inserted

addConditional

public int addConditional(int val)
Adds val to the list only if it is not already contained in the list.

Parameters:
val - the value to be added
Returns:
the index of val if it is already contained in the list and -1 otherwise

clear

public void clear()
Removes all elements from the list.


get

public int get(int index)
Returns the element with the specified index.

Parameters:
index - the specified index of the element to return
Returns:
the corresponding element

pop

public int pop()
Returns the last element and removes it from the list.

Returns:
the last element

contains

public int contains(int val)
Checks if val is already returned in the list.

Parameters:
val - the value
Returns:
the index of val if it is contained in the list and -1 otherwise

length

public int length()
Returns the number of inserted elements.

Returns:
the number of inserted elements

toArray

public int[] toArray()
This method returns an int array containing all elements of the list.

Returns:
an int array containing all elements of the list

reverse

public void reverse()
This method reverses the list, i.e., after invoking this method the formerly first element is than the last, the formerly second element is than the last but one, ...


sort

public void sort()
This method sorts the elements of the list.

See Also:
Arrays.sort(int[], int, int)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object