org.mmbase.util
Class SortedVector

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.Vector
              extended byorg.mmbase.util.SortedVector
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class SortedVector
extends java.util.Vector

Class to store Objects in, in a Sorted manner

Version:
$Id: SortedVector.java,v 1.8 2003/03/10 11:51:12 pierre Exp $ Todo: Remove duplicate code for the binary search
Author:
Rico Jansen
See Also:
Sortable, CompareInterface, Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SortedVector()
          Create a SortedVector
SortedVector(CompareInterface cmp)
          Create a SortedVector, specifying which compare function to use.
 
Method Summary
 void addBinSorted(java.lang.Object newObject)
          Store an object in its right location, search for the location the binary (smart) way.
 void addLinSorted(java.lang.Object newObject)
          Store an object in its right location, search for the location the linear (stupid) way.
 void addSorted(java.lang.Object newObject)
          Store an object in its right location.
 void addSorted(Sortable newObject)
          Store an object in its right location.
 void addUniqueSorted(java.lang.Object newObject)
          Store an object in its right location, search for the location the binary (smart) way and only insert it if it's not in the Vector yet.
 int find(java.lang.Object newObject)
          Find an object in the SortedVector.
 boolean has(java.lang.Object newObject)
          See if an object is in the SortedVector This should be contains(Object) but that one is final.
static void main(java.lang.String[] args)
          Test the class
 void setCompare(CompareInterface cmp)
          Change the compare function the SortedVector should use.
 void Sort()
          Sort the SortedVector
static SortedVector SortVector(java.util.Vector vec)
          Sort a Vector and return a SortedVector.
static SortedVector SortVector(java.util.Vector vec, CompareInterface cmpI)
          Sort a Vector and return a SortedVector using the specified compare function.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, 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

SortedVector

public SortedVector()
Create a SortedVector


SortedVector

public SortedVector(CompareInterface cmp)
Create a SortedVector, specifying which compare function to use.

See Also:
CompareInterface
Method Detail

addSorted

public void addSorted(java.lang.Object newObject)
Store an object in its right location. This will do a linear insert until 16 elements and than switch over to binary insert.


addSorted

public void addSorted(Sortable newObject)
Store an object in its right location. This will do a linear insert until 16 elements and than switch over to binary insert.


addUniqueSorted

public void addUniqueSorted(java.lang.Object newObject)
Store an object in its right location, search for the location the binary (smart) way and only insert it if it's not in the Vector yet.


addLinSorted

public void addLinSorted(java.lang.Object newObject)
Store an object in its right location, search for the location the linear (stupid) way.


addBinSorted

public void addBinSorted(java.lang.Object newObject)
Store an object in its right location, search for the location the binary (smart) way.


has

public boolean has(java.lang.Object newObject)
See if an object is in the SortedVector This should be contains(Object) but that one is final.

See Also:
Vector

find

public int find(java.lang.Object newObject)
Find an object in the SortedVector. This uses binary search. As usual this should be a overide of an existing method but that one is final. In this case indexOf(Object,int) in Vector.

See Also:
Vector

setCompare

public void setCompare(CompareInterface cmp)
Change the compare function the SortedVector should use. This forces a (re)sort of the data.


Sort

public void Sort()
Sort the SortedVector


SortVector

public static SortedVector SortVector(java.util.Vector vec)
Sort a Vector and return a SortedVector. Note: You should make sure it are Strings or Sortables, otherwise use SortVector(Vector,CompareInterface) to specify the interface


SortVector

public static SortedVector SortVector(java.util.Vector vec,
                                      CompareInterface cmpI)
Sort a Vector and return a SortedVector using the specified compare function.


main

public static void main(java.lang.String[] args)
Test the class



MMBase build 1.7.4.20050922