serp.util
Class ReferenceMap
java.lang.Object
|
+--serp.util.ReferenceMap
- All Implemented Interfaces:
- Map
- public class ReferenceMap
- extends Object
- implements Map
A map whose keys and values can be stored as weak or soft
references. This class is similar to the ReferenceMap
type found in the Jakart Commons Collections project, but is more
flexible because it allows null values, it can inherit the strategy
of any other map type, and it allows any key or value to have any
reference type (see put(Object,int,Object,int)
.
Expired values are removed from the map before any mutator methods;
removing before accessor methods can lead to
ConcurrentModificationException
s. Thus, the following methods may
produce results which include key/value pairs that have expired:
size
isEmpty
containsKey
keySet.size,contains,isEmpty
entrySet.size,contains,isEmpty
values.size,contains,isEmpty
By default, all methods are delegated to the internal map provided at
construction. Thus, the ordering, etc of the given map will be preserved;
however, the hashing algorithm cannot be duplicated. A special case is
made for the IdentityMap
's hashing, which is supported.
Performance is similar to that of the internal map instance.
Field Summary |
static int |
HARD
Hard reference marker. |
static int |
SOFT
Soft reference marker. |
static int |
WEAK
Weak reference marker. |
Constructor Summary |
ReferenceMap()
Equivalent to ReferenceMap (ReferenceMap.HARD,
ReferenceMap.HARD) . |
ReferenceMap(int defaultKeyType,
int defaultValueType)
Equivalent to ReferenceMap (defaultKeyType, defaultValueType,
new HashMap ()) . |
ReferenceMap(int defaultKeyType,
int defaultValueType,
Map map)
Construct a ReferenceMap with the given interal default key and value
reference types, and have it use the given map for storage. |
Methods inherited from interface java.util.Map |
hashCode |
HARD
public static final int HARD
- Hard reference marker.
SOFT
public static final int SOFT
- Soft reference marker.
WEAK
public static final int WEAK
- Weak reference marker.
ReferenceMap
public ReferenceMap()
- Equivalent to
ReferenceMap (ReferenceMap.HARD,
ReferenceMap.HARD)
.
ReferenceMap
public ReferenceMap(int defaultKeyType,
int defaultValueType)
- Equivalent to
ReferenceMap (defaultKeyType, defaultValueType,
new HashMap ())
.
ReferenceMap
public ReferenceMap(int defaultKeyType,
int defaultValueType,
Map map)
- Construct a ReferenceMap with the given interal default key and value
reference types, and have it use the given map for storage. The
map will be cleared. It should not be accessed in any way after being
given to this constructor; this map will 'inherit' its behavior,
however. For example, if the given map is a
LinkedHashMap
,
the values
method of this map will return values in
insertion order.
clear
public void clear()
- Specified by:
clear
in interface Map
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interface Map
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interface Map
entrySet
public Set entrySet()
- Specified by:
entrySet
in interface Map
equals
public boolean equals(Object other)
- Specified by:
equals
in interface Map
- Overrides:
equals
in class Object
get
public Object get(Object key)
- Specified by:
get
in interface Map
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface Map
keySet
public Set keySet()
- Specified by:
keySet
in interface Map
put
public Object put(Object key,
Object value)
- Specified by:
put
in interface Map
put
public Object put(Object key,
int keyType,
Object value,
int valueType)
- Set the given key, while specifying the key and value reference types.
putAll
public void putAll(Map map)
- Specified by:
putAll
in interface Map
remove
public Object remove(Object key)
- Specified by:
remove
in interface Map
size
public int size()
- Specified by:
size
in interface Map
values
public Collection values()
- Specified by:
values
in interface Map
toString
public String toString()
- Overrides:
toString
in class Object
Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.