|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.util.LookupTable<K,V>
public class LookupTable<K extends Comparable<K>,V>
A lookup table.
A lookup table is very similar to a map. The main difference is that to get a value from a map, you need to specify exactly a key that the map holds. To get a value from a lookup table, though, all you need to have is a key that is at least as great as the key for the first entry in the table. The value returned for any key, K, is the value found in the entry whose key is less than or equal to K. The entries in a lookup table are sorted in ascending order of the entries' keys. The definition of "ascending" depends on the comparator used to construct the table.
A classic use of a lookup table is a table of marginal income tax rates. Your marginal tax rate is given by the entry whose income is less than or equal to your own.
The keys of this table may be any object that implements the
Comparable
interface. Examples of common key types
are numbers, strings, and dates. Via the use of
generics, this
table is type safe.
CVS Info:
$Revision: 161 $ |
$Date: 2006-12-15 11:48:34 -0700 (Fri, 15 Dec 2006) $ |
$Author: btruitt $ |
Constructor Summary | |
---|---|
LookupTable()
Creates a new, empty table, sorted according to the keys' natural order. |
|
LookupTable(Comparator<? super K> c)
Constructs a new, empty table, sorted according to the given comparator. |
Method Summary | |
---|---|
void |
clear()
Removes all entries from this table. |
LookupTable<K,V> |
clone()
Returns a shallow copy of this lookup table. |
boolean |
containsKey(K key)
Returns true if this table contains an entry whose key is key . |
boolean |
containsValue(V value)
Returns true if this table contains one or more entries whose value is value . |
boolean |
equals(Object o)
Returns true if o is equal to this table. |
V |
get(K key)
Returns the value associated with the first key that is less than or equal to key . |
SortedSet<K> |
getKeySet()
Returns this table's set of keys. |
SortedSet<K> |
getKeySetFor(V value)
Returns the set of keys under which value is stored. |
int |
hashCode()
Returns a hash code value for this table. |
V |
put(K key,
V value)
Puts the given key / value pair into this table. |
void |
putAll(Map<K,V> map)
Copies all the mappings from map into this table. |
V |
remove(K key)
Removes the entry whose key is key from this table, if present. |
int |
removeValue(V value)
Removes all entries in this table whose value is value . |
int |
size()
Returns the number of entries in this table. |
SortedMap<K,V> |
toMap()
Returns this table in the form of a sorted map. |
String |
toString()
Returns a text representation of this table. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LookupTable()
public LookupTable(Comparator<? super K> c)
c
- the comparator that will be used to sort this map. A null
value indicates that the keys' natural ordering should be used.Method Detail |
---|
public void clear()
public V put(K key, V value)
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
key
.public void putAll(Map<K,V> map)
map
into this table.
map
- a source of key / value pairs.public V remove(K key)
key
from this table, if present.
key
- the key whose entry should be removed from this table.
key
, or
null if this table had no entry for key
.public int removeValue(V value)
value
.
value
- the value to be removed entirely from this table.
public boolean containsKey(K key)
key
.
key
- a key that may be present in this table.
key
.public boolean containsValue(V value)
value
.
value
- a value that may be present in this table.
value
.public V get(K key)
key
. The keys of this table are ordered according
to the compartor specified during the construction of this table.
If no comparator was so specified, then the keys are in their
natural order.
A return value of null means either that key
is less
than the first key in this table, or that the greatest key that is
not greater than key
maps to a value of null.
key
- the key for which a value is sought.
key
.public SortedSet<K> getKeySet()
public SortedSet<K> getKeySetFor(V value)
value
is stored.
value
- a value that might be stored in this table.
value
is stored.public int size()
public SortedMap<K,V> toMap()
public String toString()
(key1.toString, value1.toString) ... (keyN.toString, valueN.toString)
toString
in class Object
public LookupTable<K,V> clone()
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this table.
See AbstractMap.equals(Object)
for a
description on how the comparison is performed.
equals
in class Object
public int hashCode()
AbstractMap.hashCode()
for a
description on how the comparison is performed.
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |