|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--iglu.util.ValueSortedMap
Holds an mapping between objects and their values, ordered by value.
This class is similar to SortedMap
except
the objects are sorted by their values, rather than by the
keys themselves.
This class is intended for use with objects that receive a value from a complex computation, such as document/query similarity.
If you need to sort objects by some method other than an external
value, use TreeSet
or TreeMap
and create a custom Comparator
. This class does not implement
SortedMap
because it does not have an explicit
Comparator
.
Note that this implementation is not synchronized.
If multiple threads access a map concurrently, and at least one of
the threads modifies the map structurally, it must be synchronized
externally. (A structural modification is any operation
that adds or deletes one or more mappings; merely changing the value
associated with an existing key is not a structural
modification.) This is typically accomplished by synchronizing on some
object that naturally encapsulates the map. If no
such object exists, the map should be "wrapped" using the
Collections.synchronizedMap
method. This is
best done at creation time, to prevent accidental unsynchronized
access to the map:
Map m = Collections.synchronizedMap(new ValueSortedMap(...));
This map keeps cached, sorted vectors of the elements in both forward and backward order. This is to speed up multiple accesses to the iterator functions.
TermVector
,
SortedMap
,
TreeSet
,
TreeMap
,
Serialized FormField Summary | |
static ValueSortedMap |
EMPTY
An empty map, for use when you don't want to do anthing to the vector. |
protected java.util.Vector |
forwardSortedVector
|
protected java.util.Vector |
reverseSortedVector
|
protected java.util.HashMap |
storedItems
|
Fields inherited from class java.util.AbstractMap |
|
Constructor Summary | |
ValueSortedMap()
Constructs an empty map. |
|
ValueSortedMap(java.util.Map map)
Constructs a new map from an existing mapping. |
Method Summary | |
void |
clear()
Removes all mappings from this map. |
private void |
clearSorts()
Removes the cached sort vectors in preparation for a change. |
java.lang.Object |
clone()
Creates a shallow clone of the object. |
boolean |
containsKey(java.lang.Object key)
Returns true if the specified key is in the mapping. |
java.util.Set |
entrySet()
Returns an unordered set of all items in the map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which this map maps the specified key. |
double |
getDouble(java.lang.Object key)
Returns the value to which this map maps the specified key. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
java.util.Iterator |
iterator()
Returns an unordered iterator over the set. |
java.util.Iterator |
keyIterator()
Returns an iterator for the keys contained in this map. |
java.util.Set |
keySet()
Returns a set view of the keys contained in this map. |
void |
linearlyScale()
Linearly scales the values in the map. |
static void |
main(java.lang.String[] args)
Runs some tests on this class. |
void |
normalize()
Normalizes the values in the map, so that its length (as a vector) is 1. |
java.lang.Object |
put(java.lang.Object key,
double value)
Adds an item and its value to the map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Adds an item and its value to the map. |
void |
putAll(java.util.Map map)
Copies all of the mappings from the specified map to this one. |
int |
rankOrder(java.lang.Object key)
Returns the ordered position of this key in the map. |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present. |
java.util.Iterator |
reverseKeyIterator()
Returns an iterator over the objects in reverse key order. |
void |
scaleBy(double n)
Scales all terms of the map by the given value. |
int |
size()
Returns the number of elements in this map. |
void |
subtract(java.util.Set subItems)
Performs a set difference on the list of items. |
static void |
test()
Runs some tests on this class. |
java.lang.String |
toString()
Returns a string representation of this map. |
void |
truncateTo(int numItems)
Truncates this map to the given length. |
Methods inherited from class java.util.AbstractMap |
containsValue, equals, hashCode, values |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.util.HashMap storedItems
protected java.util.Vector forwardSortedVector
protected java.util.Vector reverseSortedVector
public static final ValueSortedMap EMPTY
Constructor Detail |
public ValueSortedMap()
public ValueSortedMap(java.util.Map map)
Method Detail |
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public boolean isEmpty()
true
if this map contains no key-value mappings.
isEmpty
in interface java.util.Map
isEmpty
in class java.util.AbstractMap
public java.util.Set entrySet()
Map.entry
objects.
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.AbstractMap
public double getDouble(java.lang.Object key)
Number
,
returns 0.
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.AbstractMap
public java.lang.Object put(java.lang.Object key, double value)
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
putAll
in class java.util.AbstractMap
public void truncateTo(int numItems)
numItems
items, ordered by value, are kept.
public void subtract(java.util.Set subItems)
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
private void clearSorts()
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in class java.util.AbstractMap
public java.util.Iterator iterator()
public java.util.Iterator keyIterator()
get()
or getDouble()
methods.
This iterator does not support the remove operation, even
though it might appear to support it.
public java.util.Iterator reverseKeyIterator()
public java.lang.String toString()
toString
in class java.util.AbstractMap
public void normalize()
Number
.
If this is not true, only the items that map to a Number
will be nomalized. Everything else will have its value set to zero.
public void scaleBy(double n)
Number
.
If this is not true, only the items that map to a Number
will be scaled. Everything else will have its value set to zero.
public void linearlyScale()
public int rankOrder(java.lang.Object key)
public java.lang.Object clone()
clone
in class java.util.AbstractMap
public static void test()
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |