net.sf.molae.pipe.hash
Class HashList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--net.sf.molae.pipe.hash.HashList
All Implemented Interfaces:
Collection, List

public class HashList
extends AbstractList

A list where the index of each element equals its hash code.


Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
HashList(List base)
          Constructs a HashList object.
 
Method Summary
 boolean add(Object o)
          Appends the specified element to the end of this List (optional operation).
 void clear()
          Removes all of the elements from this collection (optional operation).
 boolean contains(Object o)
          Returns true if this collection contains the specified element.
 Object get(int index)
          Returns the element at the specified position in this list.
 int indexOf(Object o)
          Returns the index in this list of the first occurence of the specified element, or -1 if the list does not contain this element.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 int lastIndexOf(Object o)
          Returns the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element.
 Object set(int index, Object element)
          Replaces the element at the specified position in this list with the specified element (optional operation).
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, 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, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

HashList

public HashList(List base)
Constructs a HashList object.
Parameters:
base - the underling lists where the elements are stored.
Method Detail

size

public int size()
Returns the number of elements in this collection.
Overrides:
size in class AbstractCollection
Returns:
the number of elements in this collection.

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.
Overrides:
isEmpty in class AbstractCollection
Returns:
true if this collection contains no elements.

contains

public boolean contains(Object o)
Returns true if this collection contains the specified element. This implementation checks if the specified element equals the element at the position with the specified element's hash code.
Overrides:
contains in class AbstractCollection
Parameters:
o - object to be checked for containment in this collection.
Returns:
true if this collection contains the specified element.

add

public boolean add(Object o)
Appends the specified element to the end of this List (optional operation).

This implementation calls the corresponding method of the base list if the hash code of the specified element equals the size of the list.

Overrides:
add in class AbstractList
Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).
Throws:
UnsupportedOperationException - if the add method is not supported by the base list.
ClassCastException - if the class of the specified element prevents it from being added to the base list.
IllegalArgumentException - some aspect of this element prevents it from being added to the base list or if the hash code of the specified element is not equal to the size of this list.

clear

public void clear()
Removes all of the elements from this collection (optional operation).
Overrides:
clear in class AbstractList
Throws:
UnsupportedOperationException - if the clear method is not supported by the base list

get

public Object get(int index)
Returns the element at the specified position in this list.
Overrides:
get in class AbstractList
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if the given index is out of range (index < 0 || index >= size()).

set

public Object set(int index,
                  Object element)
Replaces the element at the specified position in this list with the specified element (optional operation).

This implementation checks the hash code of the new element first.

Overrides:
set in class AbstractList
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
UnsupportedOperationException - if the set method is not supported by the base list.
ClassCastException - if the class of the specified element prevents it from being added to the base list.
IllegalArgumentException - if some aspect of the specified element prevents it from being added to this list.
IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

indexOf

public int indexOf(Object o)
Returns the index in this list of the first occurence of the specified element, or -1 if the list does not contain this element. This implementation returns the hash code of the element if it is contained in the list.
Overrides:
indexOf in class AbstractList
Parameters:
o - element to search for.
Returns:
the index in this List of the first occurence of the specified element, or -1 if the List does not contain this element.

lastIndexOf

public int lastIndexOf(Object o)
Returns the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element. This implementation calls indexOf.
Overrides:
lastIndexOf in class AbstractList
Parameters:
o - element to search for.
Returns:
the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element.