|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlbg.protocol.data.Cache<K>
lbg.protocol.data.SlottedLRUCache<K>
K
- The type of the entriespublic class SlottedLRUCache<K extends java.lang.Comparable<? extends K>>
This class implements a cache of a size bounded in number of entries.
Field Summary |
---|
Fields inherited from class lbg.protocol.data.Cache |
---|
entries, veto |
Constructor Summary | |
---|---|
SlottedLRUCache(int capacity)
|
Method Summary | |
---|---|
Metadata<K> |
add(K entry,
Metadata<K> meta)
Adds an entry to the cache. |
boolean |
canAdd(Metadata<K>[] entries,
boolean mindVeto)
Checks if the cache can hold all entries. |
boolean |
isFull()
|
Metadata<K> |
remove(K entry)
Removes an entry from the cache. |
K |
selectForRemoval()
Selects an entry that could be removed, but doesn't remove it yet. |
java.lang.String |
toString()
Returns a String representation of this cache |
java.lang.String |
toStringDetailled()
|
Methods inherited from class lbg.protocol.data.Cache |
---|
getCacheHit, getMetadata, getVeto, has, hasVetoOn, isEmpty, setVeto, size, vetoSize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SlottedLRUCache(int capacity)
Method Detail |
---|
public Metadata<K> add(K entry, Metadata<K> meta) throws VetoException, java.lang.IllegalStateException
If the cache is full, an entry will be evicted if possible. If the entry was already present, it is updated as having been used recently (i.e. put on top of the LRU queue).
Setting meta data for an existing entry doesn't replace the existing
metadata. Either Cache.getMetadata(Comparable)
and modify it or
remove(Comparable)
then add it back.
add
in class Cache<K extends java.lang.Comparable<? extends K>>
entry
- The entry to addmeta
- Metadata concerning this entry
VetoException
- if one entry should be popped but all are veto'ed
java.lang.IllegalStateException
public boolean canAdd(Metadata<K>[] entries, boolean mindVeto)
Cache
canAdd
in class Cache<K extends java.lang.Comparable<? extends K>>
entries
- The entries that would be addedmindVeto
- true if the current veto should be taken into
account. If false, it will be considered that the veto could
be removed before actually inserting the data. In the latter case,
adding without clearing the veto could fail even if the method returns
true
public boolean isFull()
isFull
in class Cache<K extends java.lang.Comparable<? extends K>>
public Metadata<K> remove(K entry) throws VetoException
Cache
remove
in class Cache<K extends java.lang.Comparable<? extends K>>
entry
- The entry to remove
VetoException
- if the entry is veto'edpublic K selectForRemoval() throws VetoException
Cache
selectForRemoval
in class Cache<K extends java.lang.Comparable<? extends K>>
VetoException
- If the veto prevents removal of any entrypublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringDetailled()
|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.