com.taco.data
Class ListToVectorAdapter

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by java.util.Vector
              extended by com.taco.data.ListToVectorAdapter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class ListToVectorAdapter
extends java.util.Vector

An adapter from an ArrayList to a Vector, which allows interoperability with legacy code that expects instances of Vector without the performance hit due to the synchronization of methods. Obviously, none of the methods of this class are synchronized!

See Also:
Serialized Form

Field Summary
protected  java.util.ArrayList _arrayList
          If the _list is an instance of ArrayList, this field is set to the casted version of _list.
protected  java.util.List _list
          The list that this instance decorates.
static ICollectionFactory LIST_TO_VECTOR_ADAPTER_FACTORY
          A collection factory that creates instances of this class.
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ListToVectorAdapter()
          Construct a new instance, which is initially empty, and decorates a new ArrayList.
ListToVectorAdapter(java.util.Collection c)
          Construct a new instance that has the elements of c.
ListToVectorAdapter(java.util.Collection c, boolean copy)
          Construct a new instance that has the elements of c.
ListToVectorAdapter(int capacity)
          Construct a new instance, which is initially empty, and decorates a new ArrayList.
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 void addElement(java.lang.Object obj)
           
 int capacity()
          Return the size of the decorated list, since there's no way to get the capacity of a List or ArrayList.
 void clear()
           
 java.lang.Object clone()
          Clone this instance by cloning the decorated list.
 boolean contains(java.lang.Object elem)
           
 boolean containsAll(java.util.Collection c)
           
 void copyInto(java.lang.Object[] anArray)
           
 java.lang.Object elementAt(int index)
           
 java.util.Enumeration elements()
           
 void ensureCapacity(int minCapacity)
          If this instance is decorating an instance of ArrayList, call ensureCapacity() on it.
 boolean equals(java.lang.Object o)
           
 java.lang.Object firstElement()
           
 java.lang.Object get(int index)
           
 int hashCode()
           
 int indexOf(java.lang.Object elem)
           
 int indexOf(java.lang.Object elem, int index)
           
 void insertElementAt(java.lang.Object obj, int index)
           
 boolean isEmpty()
           
 java.lang.Object lastElement()
           
 int lastIndexOf(java.lang.Object elem)
           
 int lastIndexOf(java.lang.Object elem, int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 void removeAllElements()
           
 boolean removeElement(java.lang.Object obj)
           
 void removeElementAt(int index)
           
protected  void removeRange(int fromIndex, int toIndex)
          This really shouldn't be called, but for the sake of compatibility perform this function (it's slow though).
 boolean retainAll(java.util.Collection c)
           
 java.lang.Object set(int index, java.lang.Object element)
           
 void setElementAt(java.lang.Object obj, int index)
           
 void setSize(int newSize)
           
 int size()
           
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 void trimToSize()
          If the decorated list is an instance of ArrayList, call trimToSize() on it.
 
Methods inherited from class java.util.Vector
toString
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

LIST_TO_VECTOR_ADAPTER_FACTORY

public static final ICollectionFactory LIST_TO_VECTOR_ADAPTER_FACTORY
A collection factory that creates instances of this class.


_list

protected java.util.List _list
The list that this instance decorates. This is not final so that this instance can be cloned.


_arrayList

protected java.util.ArrayList _arrayList
If the _list is an instance of ArrayList, this field is set to the casted version of _list. This is not final so that this instance can be cloned.

Constructor Detail

ListToVectorAdapter

public ListToVectorAdapter()
Construct a new instance, which is initially empty, and decorates a new ArrayList.


ListToVectorAdapter

public ListToVectorAdapter(int capacity)
Construct a new instance, which is initially empty, and decorates a new ArrayList.


ListToVectorAdapter

public ListToVectorAdapter(java.util.Collection c)
Construct a new instance that has the elements of c. The collection will be copied so that the user is free to modify c after construction.


ListToVectorAdapter

public ListToVectorAdapter(java.util.Collection c,
                           boolean copy)
Construct a new instance that has the elements of c. If copy is true or c is not an instance of RandomAccess, the collection will be copied so that the user is free to modify c after construction.

Method Detail

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

addElement

public void addElement(java.lang.Object obj)
Overrides:
addElement in class java.util.Vector

capacity

public int capacity()
Return the size of the decorated list, since there's no way to get the capacity of a List or ArrayList.

Overrides:
capacity in class java.util.Vector

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.Vector

clone

public java.lang.Object clone()
Clone this instance by cloning the decorated list.

Overrides:
clone in class java.util.Vector

contains

public boolean contains(java.lang.Object elem)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List
Overrides:
contains in class java.util.Vector

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List
Overrides:
containsAll in class java.util.Vector

copyInto

public void copyInto(java.lang.Object[] anArray)
Overrides:
copyInto in class java.util.Vector

elementAt

public java.lang.Object elementAt(int index)
Overrides:
elementAt in class java.util.Vector

elements

public java.util.Enumeration elements()
Overrides:
elements in class java.util.Vector

ensureCapacity

public void ensureCapacity(int minCapacity)
If this instance is decorating an instance of ArrayList, call ensureCapacity() on it. Otherwise, do nothing.

Overrides:
ensureCapacity in class java.util.Vector

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.util.Vector

firstElement

public java.lang.Object firstElement()
Overrides:
firstElement in class java.util.Vector

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List
Overrides:
get in class java.util.Vector

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class java.util.Vector

indexOf

public int indexOf(java.lang.Object elem)
Specified by:
indexOf in interface java.util.List
Overrides:
indexOf in class java.util.Vector

indexOf

public int indexOf(java.lang.Object elem,
                   int index)
Overrides:
indexOf in class java.util.Vector

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Overrides:
insertElementAt in class java.util.Vector

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Overrides:
isEmpty in class java.util.Vector

lastElement

public java.lang.Object lastElement()
Overrides:
lastElement in class java.util.Vector

lastIndexOf

public int lastIndexOf(java.lang.Object elem)
Specified by:
lastIndexOf in interface java.util.List
Overrides:
lastIndexOf in class java.util.Vector

lastIndexOf

public int lastIndexOf(java.lang.Object elem,
                       int index)
Overrides:
lastIndexOf in class java.util.Vector

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class java.util.Vector

removeAllElements

public void removeAllElements()
Overrides:
removeAllElements in class java.util.Vector

removeElement

public boolean removeElement(java.lang.Object obj)
Overrides:
removeElement in class java.util.Vector

removeElementAt

public void removeElementAt(int index)
Overrides:
removeElementAt in class java.util.Vector

removeRange

protected void removeRange(int fromIndex,
                           int toIndex)
This really shouldn't be called, but for the sake of compatibility perform this function (it's slow though). If fromIndex equals toIndex, do nothing.

Overrides:
removeRange in class java.util.Vector
Throws:
java.lang.IndexOutOfBoundsException - if toIndex is greater than the size of this vector.
java.lang.IllegalArgumentException - if fromIndex is greater than toIndex.

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class java.util.Vector

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List
Overrides:
set in class java.util.Vector

setElementAt

public void setElementAt(java.lang.Object obj,
                         int index)
Overrides:
setElementAt in class java.util.Vector

setSize

public void setSize(int newSize)
Overrides:
setSize in class java.util.Vector

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Overrides:
size in class java.util.Vector

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List
Overrides:
subList in class java.util.Vector

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.Vector

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.Vector

trimToSize

public void trimToSize()
If the decorated list is an instance of ArrayList, call trimToSize() on it. Otherwise, do nothing.

Overrides:
trimToSize in class java.util.Vector