|
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>
K
- The type of the keys for the entriespublic abstract class Cache<K extends java.lang.Comparable<? extends K>>
An abstract cache.
A Cache does not actually store entries. Rather, it stores identifiers for these entries along with Metadata that could be useful for implementing classes. In the following, we will consider that the identifiers are the actual entries (and they could be, depending on what you store).
Additionnally, a Cache can have a veto on a set of entries, which means that, no matter what, they will never me removed from the cache (and never be candidate for removal). The veto, however, does not guarantee that the entries are present in cache, just that if they were present when the veto was set, or were added after it was set, they are still there. Consequently, there is no bound on the veto size.
Field Summary | |
---|---|
protected java.util.Map<K,Metadata<K>> |
entries
All entries know by this cache, including veto'ed ones |
protected java.util.Set<K> |
veto
A list of veto'ed entries |
Constructor Summary | |
---|---|
Cache()
|
Method Summary | |
---|---|
abstract Metadata<K> |
add(K entry,
Metadata<K> meta)
Adds an entry to the cache. |
abstract boolean |
canAdd(Metadata<K>[] entries,
boolean mindVeto)
Checks if the cache can hold all entries. |
float |
getCacheHit(K[] entries)
Get the cache hit that inserting a set of entries would yield. |
Metadata<K> |
getMetadata(K entry)
|
K[] |
getVeto(K[] a)
|
boolean |
has(K entry)
|
boolean |
hasVetoOn(K candidate)
Is this entry veto'ed ? |
boolean |
isEmpty()
|
abstract boolean |
isFull()
|
Metadata<K> |
remove(K entry)
Removes an entry from the cache. |
abstract K |
selectForRemoval()
Selects an entry that could be removed, but doesn't remove it yet. |
void |
setVeto(K[] veto)
Sets a set of entries as non-removable. |
int |
size()
Returns the number of entries currently known by this cache. |
int |
vetoSize()
Returns the number of elements in the veto. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Set<K extends java.lang.Comparable<? extends K>> veto
protected java.util.Map<K extends java.lang.Comparable<? extends K>,Metadata<K extends java.lang.Comparable<? extends K>>> entries
Constructor Detail |
---|
public Cache()
Method Detail |
---|
public final void setVeto(K[] veto)
veto
- The new veto set (null to clear current veto)public final K[] getVeto(K[] a)
public final boolean hasVetoOn(K candidate)
candidate
- The entry to check
public final int vetoSize()
getVeto(Comparable[])
public abstract Metadata<K> add(K entry, Metadata<K> meta) throws VetoException
getMetadata(Comparable)
and modify it or
remove(Comparable)
then add it back.
entry
- The entry to addmeta
- Metadata concerning this entry
VetoException
- If the Veto prevents adding this entry in any waypublic abstract boolean canAdd(Metadata<K>[] entries, boolean mindVeto)
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 Metadata<K> remove(K entry) throws VetoException
entry
- The entry to remove
VetoException
- if the entry is veto'edpublic abstract K selectForRemoval() throws VetoException
VetoException
- If the veto prevents removal of any entrypublic abstract boolean isFull()
public final boolean isEmpty()
public final boolean has(K entry)
public final Metadata<K> getMetadata(K entry)
public final float getCacheHit(K[] entries)
The cache hit is defined by (number of candidate entries already in the cache) / (total number of candidate entries). It is thus comprised between 0 and 1 inclusive.
entries
- The entries that would be inserted.
public final int size()
This is not linked to any metric that could be used in a subclass to bound the cache.
|
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.