util
Class SmartVector

java.lang.Object
  |
  +--util.SmartVector

public class SmartVector
extends Object

SmartVector is an enhanced container of java objects. Basic use is similar to a Vector, e.g. add, remove, get, size. In addition, you can access the date an object was added to the SmartVector, the date of last access, and the number of accesses. Furthermore, you can query the N last accessed objects, the N most frequently accessed objects, or the N least frequently accessed objects.

See Also:
Vector

Constructor Summary
SmartVector()
          Creates a new SmartVector instance.
 
Method Summary
 Object add(Object oItem)
          Adds an object to the SmartVector if it does not already exist in the SmartVector.
 boolean contains(Object oItem)
          Returns true if this Smart Vector contains the object, otherwise returns false.
 Enumeration elements()
          Returns an enumeration of the components of this SmartVector
 Object get(int iIndex)
          Returns the object at index iIndex.
 int getAccessCount(Object oItem)
          Returns the number of times an object was accessed.
 Date getAccessDate(Object oItem)
          Returns the date the object was last accessed.
 Date getCreateDate(Object oItem)
          Returns the date the object was first added to the SmartVector.
 String getInfo(Object oItem)
          Returns a string representation of an object in the SmartVector, including the dates of creation and last access (in milliseconds), and the access count.
 Object getLast()
          Returns the last accessed object in the SmartVector.
 Vector getLast(int iNumber)
          Returns a Vector with iNumber elements, where the ith element has been accessed more recently than the i+1th element.
 int getLexicoRank(Object oItem)
           
 Vector getLexicoSorted()
          Returns a Vector of the elements in this SmartVector with the elements in lexicographical order.
 Object getMost()
          Returns the most accessed object in the SmartVector.
 Vector getMost(int iNumber)
          Returns a Vector with iNumber elements, where the ith element has been accessed at least as many times as the i+1th element.
static void main(String[] sArgsv)
          Tests this SmartVector.
 Object remove(Object oItem)
          Removes an object from the SmartVector if it exists.
 int size()
          Returns the number of objects in this.
 String toString()
          Returns the String representation of this.
 Object touch(Object oItem)
          If the object is in SmartVector, Touch updates the access date to the current date, and increments the access count by one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SmartVector

public SmartVector()
Creates a new SmartVector instance.
Method Detail

add

public Object add(Object oItem)
Adds an object to the SmartVector if it does not already exist in the SmartVector. The object starts out with its access date and creation date as the current date, and an access count of 0.
Parameters:
oItem - an Object value
Returns:
an Object value

contains

public boolean contains(Object oItem)
Returns true if this Smart Vector contains the object, otherwise returns false.
Parameters:
oItem - an Object value
Returns:
a boolean value

remove

public Object remove(Object oItem)
Removes an object from the SmartVector if it exists. The corresponding entries for access count, access date, and create date are removed as well. If the object does not exist, then throws NoSuchElementException
Parameters:
oItem - an Object value
Returns:
an Object value

touch

public Object touch(Object oItem)
If the object is in SmartVector, Touch updates the access date to the current date, and increments the access count by one. If the object is not found, then Touch returns null. Touch should be called when an object is accessed externally.
Parameters:
oItem - an Object value
Returns:
an Object value

size

public int size()
Returns the number of objects in this.
Returns:
an int value

get

public Object get(int iIndex)
Returns the object at index iIndex. If iIndex is not valid, returns null.
Parameters:
iIndex - an int value
Returns:
an Object value

getAccessCount

public int getAccessCount(Object oItem)
Returns the number of times an object was accessed. If the object is not in SmartVector, throws NoSuchElementException.
Parameters:
oItem - an Object value
Returns:
an int value

getAccessDate

public Date getAccessDate(Object oItem)
Returns the date the object was last accessed. If the object is not in SmartVector, then throws NoSuchElementException
Parameters:
oItem - an Object value
Returns:
a Date value

getCreateDate

public Date getCreateDate(Object oItem)
Returns the date the object was first added to the SmartVector. If the object is not in SmartVector, then throws NoSuchElementException.
Parameters:
oItem - an Object value
Returns:
a Date value

getLexicoRank

public int getLexicoRank(Object oItem)

getMost

public Vector getMost(int iNumber)
Returns a Vector with iNumber elements, where the ith element has been accessed at least as many times as the i+1th element. getMost(1) returns a Vector that contains the most accessed element in the SmartVector, while getMost(3) returns the top three. If the SmartVector is empty, then this returns null
Parameters:
iNumber - an int value
Returns:
a Vector value
See Also:
#getLeast(int)

getMost

public Object getMost()
Returns the most accessed object in the SmartVector. If the SmartVector is empty, then this returns null.
Returns:
an Object value

getLast

public Vector getLast(int iNumber)
Returns a Vector with iNumber elements, where the ith element has been accessed more recently than the i+1th element. For example, getLast(1) returns a Vector that contains the last accessed element.
Parameters:
iNumber - an int value
Returns:
a Vector value

getLast

public Object getLast()
Returns the last accessed object in the SmartVector. If the SmartVector is empty, then this returns null.
Returns:
an Object value

getInfo

public String getInfo(Object oItem)
Returns a string representation of an object in the SmartVector, including the dates of creation and last access (in milliseconds), and the access count. If the object is not found, throws NoSuchElementException.
Parameters:
oItem - an Object value
Returns:
a String value

elements

public Enumeration elements()
Returns an enumeration of the components of this SmartVector
Returns:
an Enumeration value

getLexicoSorted

public Vector getLexicoSorted()
Returns a Vector of the elements in this SmartVector with the elements in lexicographical order.
Returns:
a Vector value

toString

public String toString()
Returns the String representation of this.
Overrides:
toString in class Object
Returns:
a String value

main

public static void main(String[] sArgsv)
Tests this SmartVector.
Parameters:
sArgsv[] - a String value