iitb.con.util
Class KeyList<K extends java.lang.Comparable<K>,V>

java.lang.Object
  extended by iitb.con.util.KeyList<K,V>

public class KeyList<K extends java.lang.Comparable<K>,V>
extends java.lang.Object

KeyList is a generic key-value pair list. The values are inserted and removed based on the key. It differs from the HashMap structure by maintaining it as a list and uses binary search to add and retrieve the objects.


Nested Class Summary
static class KeyList.Entry<K extends java.lang.Comparable<K>,V>
          Generic class for key-value pair data
 
Constructor Summary
KeyList()
           
 
Method Summary
 boolean add(K key, V value)
          Adds to the list
 V get(K key)
          Gets the value object for the specified key, if it matches.
 V getNext(K key)
          Gets the next value object of the specified key for nearest match.
 V getPrev(K key)
          Gets the previous value object of the specified key for nearest match.
 boolean remove(K key)
          Removes from the list
 int size()
          Returns the list size
 void sort()
          Sorts the key list
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyList

public KeyList()
Method Detail

add

public boolean add(K key,
                   V value)
Adds to the list

Parameters:
key - key that used to add
value - value object
Returns:
true on success

get

public V get(K key)
Gets the value object for the specified key, if it matches. If the key does not match, it returns NULL.

Parameters:
key - key to retrieve the object
Returns:
value object

getNext

public V getNext(K key)
Gets the next value object of the specified key for nearest match. If there is not exact key match, the nearest match - the index returned by the binary search on unsuccessful is used as the match. If it matches with last key, then the last value object itself returned.

Parameters:
key - key to retrieve the object
Returns:
value object

getPrev

public V getPrev(K key)
Gets the previous value object of the specified key for nearest match. If there is not exact key match, the nearest match - the index returned by the binary search on unsuccessful is used as the match. If it matches with first key, then the first value object itself returned.

Parameters:
key - key to retrieve the object
Returns:
value object

remove

public boolean remove(K key)
Removes from the list

Parameters:
key - key that used to remove the value object

size

public int size()
Returns the list size

Returns:
list size

sort

public void sort()
Sorts the key list