org.erights.e.elib.tables
Class WeakKeyMap

java.lang.Object
  |
  +--org.erights.e.elib.tables.EMap
        |
        +--org.erights.e.elib.tables.FlexMap
              |
              +--org.erights.e.elib.tables.WeakKeyMap
All Implemented Interfaces:
EPrintable, Iteratable, Marker, PassByProxy, Persistent, Serializable

public class WeakKeyMap
extends FlexMap

Untamed: A WeakKeyMap is a FlexMap whose keys may be garbage collected.

A WeakKeyMap acts as if an external entity (ie, the garbage collector) shares access to the map and occasionally decides to remove some elements. As a result, a WeakKeyMap which isn't being changed by the program may nevertheless find itself shrinking over time. This external modifications can only occur 1) in their own turn, or 2) at the beginning of any operation that causes an enumeration.

The snapshot(), readOnly(), clone(), or diverge() of a WeakKeyMap is not weak.

XXX This class needs its own writeReplace() method.

Author:
Mark S. Miller
See Also:
java.util.WeakHashMap, Serialized Form

Field Summary
private  Class myKeyType
           
private  FlexMap myStuff
           
(package private) static long serialVersionUID
           
 
Fields inherited from class org.erights.e.elib.tables.EMap
 
Fields inherited from interface org.erights.e.elib.serial.PassByProxy
HONORARY, HONORED_NAMES
 
Fields inherited from interface org.erights.e.elib.serial.Persistent
HONORARY, HONORED_NAMES
 
Constructor Summary
WeakKeyMap()
          Enabled:
WeakKeyMap(Class keyType, Class valueType)
          Enabled:
 
Method Summary
 void __printOn(TextWriter out)
          Enabled: Does not remove garbage first, which is weird, but the other would be weirder.
 boolean contains(Object candidate)
          Enabled: Removes garbage first
 Object get(Object key, Object instead)
          Enabled: Does not remove garbage first, but cannot retrieve garbage since the key cannot be supplied.
 Object getKeys(Class type)
          Enabled: Removes garbage first
 Object getValues(Class type)
          Enabled: Does *not* remove garbage first, which is dangerous.
 Class keyType()
          Enabled: Does not remove garbage first
 void put(Object key, Object value, boolean strict)
          Enabled: Does not remove garbage first.
 void removeAll()
          Enabled: Does not remove garbage first
 void removeKey(Object key, boolean strict)
          Enabled: Does not remove garbage first.
 int size()
          Enabled: Does *not* remove garbage first, but affected when garbage is removed.
 Class valueType()
          Enabled: Does not remove garbage first
 
Methods inherited from class org.erights.e.elib.tables.FlexMap
__optUncall, clone, domain, fromColumns, fromPairs, fromTypes, fromTypes, interning, interning, make, make, put, putAll, putAll, readOnly, removeKey, removeKeys, removeKeys, snapshot
 
Methods inherited from class org.erights.e.elib.tables.EMap
and, butNot, diverge, diverge, extract, get, getKeys, getPair, getPair, getValues, intersects, iterate, maps, optExtract, or, or, printOn, sortKeys, sortKeys, sortValues, sortValues, toString, with, without
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID

myKeyType

private final Class myKeyType

myStuff

private final FlexMap myStuff
Constructor Detail

WeakKeyMap

public WeakKeyMap(Class keyType,
                  Class valueType)
Enabled:


WeakKeyMap

public WeakKeyMap()
Enabled:

Method Detail

size

public int size()
Enabled: Does *not* remove garbage first, but affected when garbage is removed.

Specified by:
size in class EMap

contains

public boolean contains(Object candidate)
Enabled: Removes garbage first

Overrides:
contains in class EMap

getKeys

public Object getKeys(Class type)
Enabled: Removes garbage first

Specified by:
getKeys in class EMap

getValues

public Object getValues(Class type)
Enabled: Does *not* remove garbage first, which is dangerous.

When used in concert with getKeys, be sure to call getKeys first and hold on to the result when calling getValues, so that none of the keys will be become garbage between the two operations.

Or, better yet, just call getPair(), which is safe on all kinds of maps.

Specified by:
getValues in class EMap

keyType

public Class keyType()
Enabled: Does not remove garbage first

Specified by:
keyType in class EMap

valueType

public Class valueType()
Enabled: Does not remove garbage first

Specified by:
valueType in class EMap

get

public Object get(Object key,
                  Object instead)
Enabled: Does not remove garbage first, but cannot retrieve garbage since the key cannot be supplied.

Specified by:
get in class EMap
Parameters:
key - nullOk;
instead - nullOk;
Returns:
nullOk;
See Also:
org.erights.e.elib.ref.Ref#isSettled

put

public void put(Object key,
                Object value,
                boolean strict)
Enabled: Does not remove garbage first.

WeakKeyMap doesn't support strict=true.

Specified by:
put in class FlexMap
See Also:
org.erights.e.elib.ref.Ref#isSettled

removeKey

public void removeKey(Object key,
                      boolean strict)
Enabled: Does not remove garbage first.

WeakKeyMap doesn't support strict=true.

Specified by:
removeKey in class FlexMap
Parameters:
key - the key to remove

removeAll

public void removeAll()
Enabled: Does not remove garbage first

Specified by:
removeAll in class FlexMap

__printOn

public void __printOn(TextWriter out)
               throws IOException
Enabled: Does not remove garbage first, which is weird, but the other would be weirder.

Specified by:
__printOn in interface EPrintable
Overrides:
__printOn in class FlexMap
IOException


comments?