fr.univNantes.intcolls
Class ArrayLongList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<java.lang.Long>
          extended by fr.univNantes.intcolls.ArrayLongList
All Implemented Interfaces:
java.lang.Iterable<java.lang.Long>, java.util.Collection<java.lang.Long>, java.util.List<java.lang.Long>, java.util.RandomAccess

public class ArrayLongList
extends java.util.AbstractList<java.lang.Long>
implements java.util.RandomAccess

This class implements a List by an Array of integer. Unlike ArrayList the array contains directly integers and not references on Long objects.

Author:
Pierre-Olivier Terrisse.

Field Summary
private static int DEFAULT_CAPACITY
          Default capacity
private  int increment
          Increment of the capacity of the backing array
private  int size
          Actuel size of the list
private  long[] tab
          Contains the elements of the list
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayLongList()
          Constructor of the list without arguments.
ArrayLongList(java.util.Collection<java.lang.Long> coll)
          Constructor with another collection of Integers
ArrayLongList(int capacity)
          Constructor of the list
 
Method Summary
 void add(int index, java.lang.Long element)
          Inserts the specified element at the specified position in this list.
 boolean add(java.lang.Long i)
          Adds a specified integer at the end of the list
 boolean addAll(int index, java.util.Collection<? extends java.lang.Long> c)
          Inserts all of the elements in the specified collection into this list, starting at the specified position.
 boolean addAll(int index, long[] arr)
          Inserts all of the elements in the specified collection into this list, starting at the specified position.
 boolean addAll(int index, long[] arr, int count)
          Inserts all of the elements in the specified collection into this list, starting at the specified position.
 boolean addAll(long[] arr)
          Inserts all of the elements in the specified collection into this list, starting at the end of the list.
 void addLong(long i)
          Adds a specified integer at the end of the list
 boolean contains(java.lang.Object o)
           
 boolean containsLong(long value)
          Returns true if the list contains a given value
 boolean equals(java.lang.Object obj)
          Returns true if this list is equal to another
 java.lang.Long get(int index)
          Returns the element at the specified position in this list.
 long getLong(int index)
          Returns the element at the specified position in this list.
 int hashCode()
          Returns a hash code value for the object
 ArrayLongListIterator iterator()
          Returns an iterator on the list
 ArrayLongListIterator listIterator()
          Returns an iterator on the list
 java.lang.Long remove(int index)
          Removes the element at the specified position in this list
 java.lang.Long set(int index, java.lang.Long element)
          Replaces the element at the specified position in this list with the specified element
 long setLong(int index, long element)
          Replaces the element at the specified position in this list with the specified element
 int size()
          Returns the size of the liste
protected  void verifyCapacity(int incSize)
          Increase the size of the backing array if necessary.
 
Methods inherited from class java.util.AbstractList
clear, indexOf, lastIndexOf, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

DEFAULT_CAPACITY

private static final int DEFAULT_CAPACITY
Default capacity

See Also:
Constant Field Values

tab

private long[] tab
Contains the elements of the list


increment

private int increment
Increment of the capacity of the backing array


size

private int size
Actuel size of the list

Constructor Detail

ArrayLongList

public ArrayLongList(int capacity)
Constructor of the list

Parameters:
capacity - initial capacity of the liste

ArrayLongList

public ArrayLongList()
Constructor of the list without arguments. The capacity of the list will be the default capacity


ArrayLongList

public ArrayLongList(java.util.Collection<java.lang.Long> coll)
Constructor with another collection of Integers

Parameters:
coll - another collection
Method Detail

equals

public boolean equals(java.lang.Object obj)
Returns true if this list is equal to another

Specified by:
equals in interface java.util.Collection<java.lang.Long>
Specified by:
equals in interface java.util.List<java.lang.Long>
Overrides:
equals in class java.util.AbstractList<java.lang.Long>
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise

hashCode

public int hashCode()
Returns a hash code value for the object

Specified by:
hashCode in interface java.util.Collection<java.lang.Long>
Specified by:
hashCode in interface java.util.List<java.lang.Long>
Overrides:
hashCode in class java.util.AbstractList<java.lang.Long>
Returns:
a hash code value for this object.

listIterator

public ArrayLongListIterator listIterator()
Returns an iterator on the list

Specified by:
listIterator in interface java.util.List<java.lang.Long>
Overrides:
listIterator in class java.util.AbstractList<java.lang.Long>
Returns:
iterator

iterator

public ArrayLongListIterator iterator()
Returns an iterator on the list

Specified by:
iterator in interface java.lang.Iterable<java.lang.Long>
Specified by:
iterator in interface java.util.Collection<java.lang.Long>
Specified by:
iterator in interface java.util.List<java.lang.Long>
Overrides:
iterator in class java.util.AbstractList<java.lang.Long>
Returns:
iterator

getLong

public long getLong(int index)
Returns the element at the specified position in this list.

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

get

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

Specified by:
get in interface java.util.List<java.lang.Long>
Specified by:
get in class java.util.AbstractList<java.lang.Long>
Parameters:
index - position in the list
Returns:
the element at the specified position in this list
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

size

public int size()
Returns the size of the liste

Specified by:
size in interface java.util.Collection<java.lang.Long>
Specified by:
size in interface java.util.List<java.lang.Long>
Specified by:
size in class java.util.AbstractCollection<java.lang.Long>
Returns:
the number of elements in the list

add

public void add(int index,
                java.lang.Long element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Specified by:
add in interface java.util.List<java.lang.Long>
Overrides:
add in class java.util.AbstractList<java.lang.Long>
Parameters:
index - index at which the specified element is to be inserted
element - element to be inserted

addLong

public void addLong(long i)
Adds a specified integer at the end of the list

Parameters:
i - integer to add

add

public boolean add(java.lang.Long i)
Adds a specified integer at the end of the list

Specified by:
add in interface java.util.Collection<java.lang.Long>
Specified by:
add in interface java.util.List<java.lang.Long>
Overrides:
add in class java.util.AbstractList<java.lang.Long>
Parameters:
i - integer to add

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends java.lang.Long> c)
Inserts all of the elements in the specified collection into this list, starting at the specified position.

Specified by:
addAll in interface java.util.List<java.lang.Long>
Overrides:
addAll in class java.util.AbstractList<java.lang.Long>
Parameters:
index - index at which to insert the first element from the specified collection
c - collection containing elements to be added to this list
Returns:
true if the collection changed
Throws:
java.lang.IndexOutOfBoundsException - - if the index is out of range (index < 0 || index > size())
java.lang.NullPointerException - - if the specified collection is null

addAll

public boolean addAll(int index,
                      long[] arr,
                      int count)
Inserts all of the elements in the specified collection into this list, starting at the specified position.

Parameters:
index - index at which to insert the first element from the specified collection
arr - array containing elements to be added to this list
count - number of elements to add from the array
Returns:
true if the collection changed
Throws:
java.lang.IndexOutOfBoundsException - - if the index is out of range (index < 0 || index > size())
java.lang.NullPointerException - - if the specified collection is null

addAll

public boolean addAll(int index,
                      long[] arr)
Inserts all of the elements in the specified collection into this list, starting at the specified position. Convenience method for addAll(index,arr,arr.length).

Parameters:
index - index at which to insert the first element from the specified collection
arr - array containing elements to be added to this list
Returns:
true if the collection changed
Throws:
java.lang.IndexOutOfBoundsException - - if the index is out of range (index < 0 || index > size())
java.lang.NullPointerException - - if the specified array is null

addAll

public boolean addAll(long[] arr)
Inserts all of the elements in the specified collection into this list, starting at the end of the list. Convenience method for addAll(size(),index,arr,arr.length).

Parameters:
arr - array containing elements to be added to this list
Returns:
true if the collection changed
Throws:
java.lang.IndexOutOfBoundsException - - if the index is out of range (index < 0 || index > size())
java.lang.NullPointerException - - if the specified array is null

setLong

public long setLong(int index,
                    long element)
Replaces the element at the specified position in this list with the specified element

Parameters:
index - index of the element to replace
element - element to be stored at the specified position
Returns:
the element previously at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

set

public java.lang.Long set(int index,
                          java.lang.Long element)
Replaces the element at the specified position in this list with the specified element

Specified by:
set in interface java.util.List<java.lang.Long>
Overrides:
set in class java.util.AbstractList<java.lang.Long>
Parameters:
index - index of the element to replace
element - element to be stored at the specified position
Returns:
the element previously at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

remove

public java.lang.Long remove(int index)
Removes the element at the specified position in this list

Specified by:
remove in interface java.util.List<java.lang.Long>
Overrides:
remove in class java.util.AbstractList<java.lang.Long>
Parameters:
index - the index of the element to be removed
Returns:
the element previously at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

containsLong

public boolean containsLong(long value)
Returns true if the list contains a given value

Parameters:
value - value to search
Returns:
true if list contains the value

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<java.lang.Long>
Specified by:
contains in interface java.util.List<java.lang.Long>
Overrides:
contains in class java.util.AbstractCollection<java.lang.Long>

verifyCapacity

protected void verifyCapacity(int incSize)
Increase the size of the backing array if necessary.

Parameters:
incSize - incremental size