org.omnaest.utils.structure.collection.list
Class IndexArrayList<E extends Comparable<? super E>>

java.lang.Object
  extended by org.omnaest.utils.structure.collection.list.IndexArrayList<E>
Type Parameters:
E -
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, IndexList<E>

public class IndexArrayList<E extends Comparable<? super E>>
extends Object
implements IndexList<E>

This class implements the list interface.
The implementation is based on an internal ArrayList with a second list acting as an index.
What means that the list will need some more than twice the memory than an ArrayList and more time to add elements to the list.
For the increased memory space used and the increased time used for adding elements, it offers look up methods, like contains(Object), indexOf(Object), lastIndexOf(Object), that are based on an index search algorithm.
The algorithm uses binary search, and has by that a limited cost of log(n) for searching and adding, whereby n is the size of the list.
The order of the list is the same, as the order of the elements added.
A limitation of the list is, that it can only be used for objects, that implement the Comparable interface. This is caused by the use of a sorted internal table for the index.

Author:
Omnaest

Constructor Summary
IndexArrayList()
          Creates a new empty indexed list.
IndexArrayList(Collection<? extends E> c)
          Creates a new indexed list, which is filled with all objects of the collection.
IndexArrayList(int initialSize)
           
 
Method Summary
 boolean add(E e)
           
 void add(int index, E element)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 E get(int index)
           
 int[] indexesOf(E e)
          Returns all index positions, where the data values at are equal to the given element.
 int[] indexesOfElementsEqualOrBetween(E smallestElement, E largestElement)
          Returns the indexes of the elements that are equal or between the smallestElement and the largestElement.
 int[] indexesOfElementsGreaterThan(E element)
          Returns the indexes of the elements greater than the as parameter given element.
 int[] indexesOfElementsLessThan(E element)
          Returns the indexes of the elements less than the parameter element.
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 void printDataList()
           
 void printIndexList()
           
 E remove(int dataListIndexPosition)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 E set(int index, E element)
           
 int size()
           
 List<E> subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

IndexArrayList

public IndexArrayList()
Creates a new empty indexed list.


IndexArrayList

public IndexArrayList(int initialSize)

IndexArrayList

public IndexArrayList(Collection<? extends E> c)
Creates a new indexed list, which is filled with all objects of the collection.

Parameters:
c -
Method Detail

add

public boolean add(E e)
Specified by:
add in interface Collection<E extends Comparable<? super E>>
Specified by:
add in interface List<E extends Comparable<? super E>>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E extends Comparable<? super E>>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E extends Comparable<? super E>>
Specified by:
addAll in interface List<E extends Comparable<? super E>>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E extends Comparable<? super E>>

clear

public void clear()
Specified by:
clear in interface Collection<E extends Comparable<? super E>>
Specified by:
clear in interface List<E extends Comparable<? super E>>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E extends Comparable<? super E>>
Specified by:
contains in interface List<E extends Comparable<? super E>>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E extends Comparable<? super E>>
Specified by:
containsAll in interface List<E extends Comparable<? super E>>

get

public E get(int index)
Specified by:
get in interface List<E extends Comparable<? super E>>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<E extends Comparable<? super E>>

indexesOfElementsGreaterThan

public int[] indexesOfElementsGreaterThan(E element)
Returns the indexes of the elements greater than the as parameter given element.

Specified by:
indexesOfElementsGreaterThan in interface IndexList<E extends Comparable<? super E>>
Parameters:
element -
Returns:

indexesOfElementsLessThan

public int[] indexesOfElementsLessThan(E element)
Returns the indexes of the elements less than the parameter element.

Specified by:
indexesOfElementsLessThan in interface IndexList<E extends Comparable<? super E>>
Parameters:
element -
Returns:

indexesOfElementsEqualOrBetween

public int[] indexesOfElementsEqualOrBetween(E smallestElement,
                                             E largestElement)
Returns the indexes of the elements that are equal or between the smallestElement and the largestElement.

Specified by:
indexesOfElementsEqualOrBetween in interface IndexList<E extends Comparable<? super E>>
Parameters:
elementFrom -
Returns:

indexesOf

public int[] indexesOf(E e)
Returns all index positions, where the data values at are equal to the given element.

Specified by:
indexesOf in interface IndexList<E extends Comparable<? super E>>
Parameters:
e -
Returns:
See Also:
indexOf(Object), lastIndexOf(Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E extends Comparable<? super E>>
Specified by:
isEmpty in interface List<E extends Comparable<? super E>>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends Comparable<? super E>>
Specified by:
iterator in interface Collection<E extends Comparable<? super E>>
Specified by:
iterator in interface List<E extends Comparable<? super E>>

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<E extends Comparable<? super E>>

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E extends Comparable<? super E>>

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E extends Comparable<? super E>>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E extends Comparable<? super E>>
Specified by:
remove in interface List<E extends Comparable<? super E>>

remove

public E remove(int dataListIndexPosition)
Specified by:
remove in interface List<E extends Comparable<? super E>>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E extends Comparable<? super E>>
Specified by:
removeAll in interface List<E extends Comparable<? super E>>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E extends Comparable<? super E>>
Specified by:
retainAll in interface List<E extends Comparable<? super E>>

set

public E set(int index,
             E element)
Specified by:
set in interface List<E extends Comparable<? super E>>

size

public int size()
Specified by:
size in interface Collection<E extends Comparable<? super E>>
Specified by:
size in interface List<E extends Comparable<? super E>>

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List<E extends Comparable<? super E>>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E extends Comparable<? super E>>
Specified by:
toArray in interface List<E extends Comparable<? super E>>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E extends Comparable<? super E>>
Specified by:
toArray in interface List<E extends Comparable<? super E>>

printDataList

public void printDataList()

printIndexList

public void printIndexList()


Copyright © 2013. All Rights Reserved.