com.j2r
Class FiFoRemainingMemoryStrategy

java.lang.Object
  extended by com.j2r.FiFoRemainingMemoryStrategy
All Implemented Interfaces:
MapManagerStrategy

public class FiFoRemainingMemoryStrategy
extends java.lang.Object
implements MapManagerStrategy


Constructor Summary
FiFoRemainingMemoryStrategy(ManagedMap map, int requiredFreeMemoryMb)
          Creates a new instance with the specified storage.
FiFoRemainingMemoryStrategy(ManagedMap map, int requiredFreeMemoryMb, int maxMem)
          Creates a new instance with the specified storage.
FiFoRemainingMemoryStrategy(ManagedMap map, long requiredFreeMemoryBytes, long maxMemBytes)
          Creates a new instance with the specified storage.
 
Method Summary
 void clear()
          Clears all elements.
 java.lang.Object clone()
          Creates a shallow copy of this object, preserving the internal structure by copying only references.
 void decrease(int index, java.lang.Object key)
          Removes the element with the specified key or index.
 void freshenSequence(java.lang.Object key, java.lang.Object value)
          Freshens the sequence of the element value if value is not null.
 java.lang.Object get(int index)
          Returns the key at the specified index.
 ManagedMap getManagedMap()
           
 void increase(java.lang.Object key, java.lang.Object prevValue, java.lang.Object newValue)
          Stores the provided key/value pair.
 int indexOf(java.lang.Object key)
          Returns the index of the specified key.
 java.util.Iterator iterator()
          Returns a key iterator.
 int lastIndexOf(java.lang.Object key)
          Returns the last index of the specified key.
 void removeManagedMap()
           
 java.util.List sequence()
          Returns the ordered sequence of keys.
 void setManagedMap(ManagedMap managedMap)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FiFoRemainingMemoryStrategy

public FiFoRemainingMemoryStrategy(ManagedMap map,
                                   int requiredFreeMemoryMb)
Creates a new instance with the specified storage. When the map size is growing to be bigger then the given size the first in element will be first out so that the size never gets bigger then the given size.

Parameters:
requiredFreeMemoryMb - int is the memory ammount in Megabyte required to be present for instance processing after the last cache update.

FiFoRemainingMemoryStrategy

public FiFoRemainingMemoryStrategy(ManagedMap map,
                                   int requiredFreeMemoryMb,
                                   int maxMem)
Creates a new instance with the specified storage. When the map size is growing to be bigger then the given size the first in element will be first out so that the size never gets bigger then the given size.

Parameters:
requiredFreeMemoryMb - int is the memory ammount in Megabyte required to be present for instance processing after the last cache update.

FiFoRemainingMemoryStrategy

public FiFoRemainingMemoryStrategy(ManagedMap map,
                                   long requiredFreeMemoryBytes,
                                   long maxMemBytes)
Creates a new instance with the specified storage. When the map size is growing to be bigger then the given size the first in element will be first out so that the size never gets bigger then the given size.

Parameters:
requiredFreeMemoryMb - int is the memory ammount in Megabyte required to be present for instance processing after the last cache update.
Method Detail

sequence

public java.util.List sequence()
Returns the ordered sequence of keys. This method is meant to be used for retrieval of Key / Value pairs in e.g. Velocity:
 ## $table contains a sequenced map
 #foreach ($key in $table.sequence())
 <TR>
 <TD>Key: $key</TD>
 </TD>Value: $table.get($key)</TD>
 </TR>
 #end
 

Specified by:
sequence in interface MapManagerStrategy
Returns:
The ordered list of keys.

clear

public void clear()
Clears all elements.

Specified by:
clear in interface MapManagerStrategy

clone

public java.lang.Object clone()
Creates a shallow copy of this object, preserving the internal structure by copying only references. The keys, values, and sequence are not clone()'d.

Specified by:
clone in interface MapManagerStrategy
Overrides:
clone in class java.lang.Object
Returns:
A clone of this instance.

freshenSequence

public void freshenSequence(java.lang.Object key,
                            java.lang.Object value)
Freshens the sequence of the element value if value is not null.

Specified by:
freshenSequence in interface MapManagerStrategy
Parameters:
key - The key whose sequence to freshen.
value - The value whose existance to check before removing the old key sequence.

get

public java.lang.Object get(int index)
Returns the key at the specified index.

Specified by:
get in interface MapManagerStrategy

indexOf

public int indexOf(java.lang.Object key)
Returns the index of the specified key.

Specified by:
indexOf in interface MapManagerStrategy

iterator

public java.util.Iterator iterator()
Returns a key iterator.

Specified by:
iterator in interface MapManagerStrategy

lastIndexOf

public int lastIndexOf(java.lang.Object key)
Returns the last index of the specified key.

Specified by:
lastIndexOf in interface MapManagerStrategy

increase

public void increase(java.lang.Object key,
                     java.lang.Object prevValue,
                     java.lang.Object newValue)
Stores the provided key/value pair. Freshens the sequence of existing elements.

Specified by:
increase in interface MapManagerStrategy
Parameters:
key - The key to the provided value.
value - The value to store.

decrease

public final void decrease(int index,
                           java.lang.Object key)
Removes the element with the specified key or index.

Specified by:
decrease in interface MapManagerStrategy
Parameters:
index - The index of the object to remove, or UNKNOWN_INDEX if not known.
key - The Map key of the object to remove.

getManagedMap

public ManagedMap getManagedMap()
Specified by:
getManagedMap in interface MapManagerStrategy

setManagedMap

public void setManagedMap(ManagedMap managedMap)
Specified by:
setManagedMap in interface MapManagerStrategy

removeManagedMap

public void removeManagedMap()
Specified by:
removeManagedMap in interface MapManagerStrategy