Lightweight Bartering Grid

lbg.protocol.data
Class UnlimitedCache<K extends java.lang.Comparable<? extends K>>

java.lang.Object
  extended by lbg.protocol.data.Cache<K>
      extended by lbg.protocol.data.UnlimitedCache<K>
Type Parameters:
K - The type of the entries

public class UnlimitedCache<K extends java.lang.Comparable<? extends K>>
extends Cache<K>

This class implements an unbounded cache.

Author:
Xavier Dalem

Field Summary
 
Fields inherited from class lbg.protocol.data.Cache
entries, veto
 
Constructor Summary
UnlimitedCache()
           
 
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()
           
 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
 
Methods inherited from class lbg.protocol.data.Cache
getCacheHit, getMetadata, getVeto, has, hasVetoOn, isEmpty, remove, setVeto, size, vetoSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnlimitedCache

public UnlimitedCache()
Method Detail

add

public Metadata<K> add(K entry,
                       Metadata<K> meta)
Description copied from class: Cache
Adds an entry to the cache. Setting meta data for an existing entry doesn't replace the existing metadata. Either Cache.getMetadata(Comparable) and modify it or Cache.remove(Comparable) then add it back.

Specified by:
add in class Cache<K extends java.lang.Comparable<? extends K>>
Parameters:
entry - The entry to add
meta - Metadata concerning this entry
Returns:
The metadata for the entry that was removed, if the cache implementation has a finite capacity and had to make room.

canAdd

public boolean canAdd(Metadata<K>[] entries,
                      boolean mindVeto)
Description copied from class: Cache
Checks if the cache can hold all entries. The check is based on the current veto, as this method returns true if all entries not in the veto can be stored in the remaining space.

Specified by:
canAdd in class Cache<K extends java.lang.Comparable<? extends K>>
Parameters:
entries - The entries that would be added
mindVeto - 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
Returns:
true if all entries can potentially be added.

isFull

public boolean isFull()
Specified by:
isFull in class Cache<K extends java.lang.Comparable<? extends K>>

selectForRemoval

public K selectForRemoval()
Description copied from class: Cache
Selects an entry that could be removed, but doesn't remove it yet.

Specified by:
selectForRemoval in class Cache<K extends java.lang.Comparable<? extends K>>
Returns:
The entry that could be removed, or null if none can be removed but this is normal (e.g. because the cache has no limit or is empty)

toString

public java.lang.String toString()
Returns a String representation of this cache

Overrides:
toString in class java.lang.Object

Lightweight Bartering Grid

Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.