com.imagero.util
Class SortableVector

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.Vector
              extended bycom.imagero.util.SortableVector
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class SortableVector
extends java.util.Vector

SortableVector.java this Vector is not always sorted, but it can be sorted 'in place'

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SortableVector()
           
SortableVector(java.util.Collection c)
           
SortableVector(int initialCapacity)
           
SortableVector(int initialCapacity, int capacityIncrement)
           
 
Method Summary
 void add(int index, java.lang.Object element)
          overriden to set sorted to false
 boolean add(java.lang.Object o)
          overriden to set sorted to false
 boolean addAll(java.util.Collection c)
          overriden to set sorted to false
 boolean addAll(int index, java.util.Collection c)
          overriden to set sorted to false
 void addElement(java.lang.Object obj)
          overriden to set sorted to false
 java.util.Comparator getComparator()
          get actual comparator used to sort and search operations
 int indexOf(java.lang.Object elem)
          Searches for the first occurence of the given argument.
 void insertElementAt(java.lang.Object obj, int index)
          overriden to set sorted to false
 boolean isSorted()
           
 void setComparator(java.util.Comparator comparator)
          set new comparator no sorting are performed - just set sorted to false
 void sort()
          use default comparator to sort elements
 void sort(java.util.Comparator c)
          sort elements with new comparator side effect - change default comparator
 
Methods inherited from class java.util.Vector
capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
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
 

Constructor Detail

SortableVector

public SortableVector()

SortableVector

public SortableVector(java.util.Collection c)

SortableVector

public SortableVector(int initialCapacity)

SortableVector

public SortableVector(int initialCapacity,
                      int capacityIncrement)
Method Detail

add

public void add(int index,
                java.lang.Object element)
overriden to set sorted to false

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.

add

public boolean add(java.lang.Object o)
overriden to set sorted to false

Parameters:
o - element to be appended to this Vector.
Returns:
true (as per the general contract of Collection.add).

addAll

public boolean addAll(java.util.Collection c)
overriden to set sorted to false

Parameters:
c - elements to be inserted into this Vector.
Returns:
true if this Vector changed as a result of the call.

addAll

public boolean addAll(int index,
                      java.util.Collection c)
overriden to set sorted to false

Parameters:
index - index at which to insert first element from the specified collection.
c - elements to be inserted into this Vector.
Returns:
true if this Vector changed as a result of the call.

addElement

public void addElement(java.lang.Object obj)
overriden to set sorted to false

Parameters:
obj - the component to be added.
See Also:
Vector.add(Object), List

getComparator

public java.util.Comparator getComparator()
get actual comparator used to sort and search operations


indexOf

public int indexOf(java.lang.Object elem)
Searches for the first occurence of the given argument. If our vector is sorted and we have valid comparator then binarySearch is used otherwise lineare search used

Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this vector, that is, the smallest value k such that elem.equals(elementData[k]) is true; returns -1 if the object is not found.
See Also:
Object.equals(Object)

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
overriden to set sorted to false

Parameters:
obj - the component to insert.
index - where to insert the new component.
See Also:
Vector.size(), Vector.add(int, Object), List

isSorted

public boolean isSorted()
Returns:
sorted state

setComparator

public void setComparator(java.util.Comparator comparator)
set new comparator no sorting are performed - just set sorted to false


sort

public void sort()
use default comparator to sort elements


sort

public void sort(java.util.Comparator c)
sort elements with new comparator side effect - change default comparator