|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--anthill.util.MapList
This class implements a HashList, which is a combination of a HashMap and a doubly linked list. The linked listed is always in sorted order according to the least recently used (LRU) scheme.
Nested Class Summary | |
protected class |
MapList.Entry
The Entry class is an inner class used to link objects stored in the map into a list. |
Nested classes inherited from class java.util.Map |
Map.Entry |
Field Summary | |
protected Map |
map
A map mapping a key identifier to a composite Entry
object implementing a doubly linked list. |
Constructor Summary | |
MapList(int maxsize)
Instantiate a new MapList object by setting the maximum number of key, value pairs which may be contained in it. |
|
MapList(int maxsize,
int maxtime)
Instantiate a new MapList object by setting the maximum number of composite Entry objects which may be contained in it. |
Method Summary | |
Object |
add(Object key)
Add the given key to the map with null as value. |
void |
clear()
Restores the object to its initial state. |
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object val)
|
void |
end()
Close the thread. |
Set |
entrySet()
|
Object |
get(Object key)
Gets the value associated with the specified key .
|
Object |
getHeadKey()
The key of head in the list, which can be used to remove the head from the list; suitable for implementing an LRU policy. |
int |
getMaxsize()
Return the maximum size of the current site. |
int |
getMaxtime()
Return the maximum size of the current site. |
boolean |
isEmpty()
|
ArrayList |
keyList()
|
Set |
keySet()
|
Object |
put(Object key,
Object value)
Add the key, value pair to the map. |
void |
putAll(Map t)
|
Object |
remove(Object key)
Removes the specify key and its associated value from the map list. |
Object[] |
removeChunck(int elemToRemove)
Removes the specify number of elements from the head of the linked list and also from the map. |
void |
run()
Periodically cleans up the staled elements in the map. |
void |
setMaxsize(int maxsize)
Modify the maximum size of this MapList .
|
void |
setMaxtime(int maxtime)
Modify the maximum time of this MapList . |
int |
size()
Returns the number of key-value mappings in this map. |
Collection |
values()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Field Detail |
protected Map map
Entry
object implementing a doubly linked list.
Constructor Detail |
public MapList(int maxsize, int maxtime)
Entry
objects which may be contained in it.
maxsize
- maximum number of pair objects which may
be contained in this MapList. If zero, there is no upper
limit to the the size.maxtime
- maximum numberpublic MapList(int maxsize)
maxsize
- Maximum number of objects which may be contained in
this MapList. If zero, there is no upper limit to the the size.Method Detail |
public boolean isEmpty()
isEmpty
in interface Map
public boolean containsKey(Object key)
containsKey
in interface Map
public boolean containsValue(Object val)
containsValue
in interface Map
public void putAll(Map t)
putAll
in interface Map
public void clear()
clear
in interface Map
public ArrayList keyList()
public Set keySet()
keySet
in interface Map
public Collection values()
values
in interface Map
public Set entrySet()
entrySet
in interface Map
public Object add(Object key)
null
as value.
key
- key with which to associate null.
public Object put(Object key, Object value)
key, value
pair to the map.
put
in interface Map
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
null
if there was no mapping for key. A null
return can also
indicate that the map previously associated null
with the
specified key, if the implementation supports null
values.public Object get(Object key)
value
associated with the specified key
.
This method moves the accessed object to the tail of the linked listed enforcing the LRU policy for elements in the Map. This means that for every access to a given key, its element is moved to the tail of the list. This is because the most recent keys will appear at the tail part of the list, while the least recently used keys will appear at the head part of the list. Hence elements should be removed from the head of the list in order to reclaim memory consumed by the key item.
get
in interface Map
key
- key whose associated value is to be returned.
public Object remove(Object key)
remove
in interface Map
key
- The key whose assoicated value should be removed
from the map list.
public Object getHeadKey()
public Object[] removeChunck(int elemToRemove)
elemToRemove
- The number of elements to be removed.public int size()
size
in interface Map
public void setMaxsize(int maxsize)
MapList
.
If this MapList contains more elements than the
new maximum size, removes the additional elements.
maxsize
- the new maximum sizepublic int getMaxsize()
public void setMaxtime(int maxtime)
MapList
.
maxtime
- the new maximum timepublic int getMaxtime()
public void run()
run
in interface Runnable
public void end()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |