Top Description Inners Fields Constructors Methods
org.jruby.util.collections

public Class WeakValuedMap<Key, Value>

extends Object
implements Map<Key, Value>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Map
Known Direct Subclasses
org.jruby.util.collections.WeakValuedIdentityMap
Type Parameters
<Key>
key
<Value>
value
Imports
java.io.Serializable, java.lang.ref.ReferenceQueue, .WeakReference, java.util.AbstractCollection, .AbstractMap.SimpleImmutableEntry, .Collection, .Iterator, .Map, .Set, java.util.concurrent.ConcurrentHashMap

Map-like that holds its values weakly (backed by a concurrent hash map).

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
protected static class

Field Summary

Modifier and TypeField and Description
private final ReferenceQueue<Value>
private final Map<Key, WeakValuedMap.KeyedReference<Key, Value>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public boolean
containsKey(final Object
key whose presence in this map is to be tested
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(final Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public Set<Map.Entry<Key, Value>>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public Value
get(Object
the key whose associated value is to be returned
key
)

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<Key>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

protected Map<Key, WeakValuedMap.KeyedReference<Key, Value>>

Returns:

the backing store map
newMap
()

Construct the backing store map for this WeakValuedMap.

public Value
put(Key
key with which the specified value is to be associated
key
,
Value
value to be associated with the specified key
value
)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(final Map<? extends Key, ? extends Value>
mappings to be stored in this map
m
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public Value
remove(final Object
key whose mapping is to be removed from the map
key
)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Collection<Value>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

deadRefsback to summary
private final ReferenceQueue<Value> deadRefs
mapback to summary
private final Map<Key, WeakValuedMap.KeyedReference<Key, Value>> map

Constructor Detail

WeakValuedMapback to summary
public WeakValuedMap()

Method Detail

cleanReferencesback to summary
private void cleanReferences()
Annotations
@SuppressWarnings:unchecked
clearback to summary
public void clear()

Implements java.util.Map.clear.

Doc from java.util.Map.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

containsKeyback to summary
public boolean containsKey(final Object key)

Implements java.util.Map.containsKey.

Doc from java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
key:Object

key whose presence in this map is to be tested

Returns:boolean

true if this map contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(final Object value)

Implements java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Parameters
value:Object

value whose presence in this map is to be tested

Returns:boolean

true if this map maps one or more keys to the specified value

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<Key, Value>> entrySet()

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<Key, Value>>

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public Value get(Object key)

Implements java.util.Map.get.

Doc from java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

the key whose associated value is to be returned

Returns:Value

the value to which the specified key is mapped, or null if this map contains no mapping for the key

isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

Annotations
@Override
keySetback to summary
public Set<Key> keySet()

Implements java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<Key>

a set view of the keys contained in this map

Annotations
@Override
newMapback to summary
protected Map<Key, WeakValuedMap.KeyedReference<Key, Value>> newMap()

Construct the backing store map for this WeakValuedMap. It should be capable of safe concurrent read and write.

Returns:Map<Key, WeakValuedMap.KeyedReference<Key, Value>>

the backing store map

putback to summary
public Value put(Key key, Value value)

Implements java.util.Map.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:Key

key with which the specified value is to be associated

value:Value

value to be associated with the specified key

Returns:Value

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

putAllback to summary
public void putAll(final Map<? extends Key, ? extends Value> m)

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
m:Map<? extends Key, ? extends Value>

mappings to be stored in this map

Annotations
@Override
removeback to summary
public Value remove(final Object key)

Implements java.util.Map.remove.

Doc from java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

key whose mapping is to be removed from the map

Returns:Value

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
sizeback to summary
public int size()

Implements java.util.Map.size.

Doc from java.util.Map.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of key-value mappings in this map

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
valuesback to summary
public Collection<Value> values()

Implements java.util.Map.values.

Doc from java.util.Map.values.

Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<Value>

a collection view of the values contained in this map

Annotations
@Override
org.jruby.util.collections back to summary

private Class WeakValuedMap.EntrySet

extends AbstractCollection<Map.Entry<Key, Value>>
implements Set<Map.Entry<Key, Value>>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
pack-priv transient Set<Map.Entry<Key, WeakValuedMap.KeyedReference<Key, Value>>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
add(Map.Entry<Key, Value>
element to be added to this set
e
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).

public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Removes all of the elements from this set (optional operation).

public boolean
contains(Object
element whose presence in this set is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.

private Set<Map.Entry<Key, WeakValuedMap.KeyedReference<Key, Value>>>
public Iterator<Map.Entry<Key, Value>>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

public boolean
remove(Object
object to be removed from this set, if present
o
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Removes the specified element from this set if it is present (optional operation).

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

Inherited from java.util.AbstractCollection:
addAllcontainsAllisEmptyremoveAllretainAlltoArraytoArraytoString

Field Detail

entriesback to summary
pack-priv transient Set<Map.Entry<Key, WeakValuedMap.KeyedReference<Key, Value>>> entries

Constructor Detail

EntrySetback to summary
private EntrySet()

Method Detail

addback to summary
public boolean add(Map.Entry<Key, Value> e)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

Parameters
e:Map.Entry<Key, Value>

element to be added to this set

Returns:boolean

true if this set did not already contain the specified element

clearback to summary
public void clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Doc from java.util.Set.clear.

Removes all of the elements from this set (optional operation). The set will be empty after this call returns.

containsback to summary
public boolean contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

Parameters
o:Object

element whose presence in this set is to be tested

Returns:boolean

true if this set contains the specified element

getEntriesback to summary
private Set<Map.Entry<Key, WeakValuedMap.KeyedReference<Key, Value>>> getEntries()
iteratorback to summary
public Iterator<Map.Entry<Key, Value>> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Returns:Iterator<Map.Entry<Key, Value>>

an iterator over the elements in this set

removeback to summary
public boolean remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Doc from java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

Parameters
o:Object

object to be removed from this set, if present

Returns:boolean

true if this set contained the specified element

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

org.jruby.util.collections back to summary

protected Class WeakValuedMap.KeyedReference<Key, Value>

extends WeakReference<Value>
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected final Key

Constructor Summary

AccessConstructor and Description
public
KeyedReference(Value object, Key key, ReferenceQueue<? super Value> queue)

Field Detail

keyback to summary
protected final Key key

Constructor Detail

KeyedReferenceback to summary
public KeyedReference(Value object, Key key, ReferenceQueue<? super Value> queue)