org.erights.e.elib.tables
Class WeakValueMap

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

public class WeakValueMap
extends FlexMap

Untamed: A WeakValueMap is FlexMap whose values may be garbage collected.

A WeakValueMap 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 WeakValueMap 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 WeakValueMap is not weak.

BUG: For some unfathomable reason, the actual values never seem to get collected, even though WeakValue by itself, when tested, seems to work fine.

XXX This class needs its own writeReplace() method.

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

Field Summary
private  FlexMap myStuff
           
private  Class myValueType
           
(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
WeakValueMap()
          Enabled:
WeakValueMap(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.
 Object get(Object key, Object instead)
          Enabled: Does not remove garbage first, except for the value itself if it has been collected.
 Object getKeys(Class type)
          Enabled: Does *not* remove garbage first, which is dangerous.
 Object getValues(Class type)
          Enabled: Removes garbage first
 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, contains, 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

myValueType

private final Class myValueType

myStuff

private final FlexMap myStuff
Constructor Detail

WeakValueMap

public WeakValueMap(Class keyType,
                    Class valueType)
Enabled:


WeakValueMap

public WeakValueMap()
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

getKeys

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

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

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

Specified by:
getKeys in class EMap

getValues

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

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, except for the value itself if it has been collected.

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.

WeakValueMap 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.

WeakValueMap 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?