com.sun.sgs.impl.util
Class BindingKeyedMapImpl<V>

java.lang.Object
  extended by java.util.AbstractMap<String,V>
      extended by com.sun.sgs.impl.util.BindingKeyedMapImpl<V>
Type Parameters:
V - the type for the map's values
All Implemented Interfaces:
BindingKeyedMap<V>, Serializable, Map<String,V>

public class BindingKeyedMapImpl<V>
extends AbstractMap<String,V>
implements BindingKeyedMap<V>, Serializable

An implementation of a persistent Map that uses service bindings in the data service to store key/value pairs. This map does not permit null keys or values.

Note: This map is parameterized by value type only. A String is the only valid key type for a BindingKeyedMap.

A value is stored in the data service using its associated key (a String) as a suffix to the keyPrefix specified during construction. All values must implement Serializable. If a value implements Serializable, but does not implement ManagedObject, the value will be wrapped in an instance of ManagedSerializable when storing it in the data service. Note: users of this map must use this map's APIs to avoid leaking wrappers for non-managed, serializable objects.

Instances of BindingKeyedMap as well as its associated iterators are serializable, but not managed, objects.

See Also:
Serialized Form

Nested Class Summary
(package private) static class BindingKeyedMapImpl.ValueIterator<V>
          An iterator over the values in the tree.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
BindingKeyedMapImpl(String keyPrefix)
          Constructs an instance with the specified keyPrefix.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 boolean containsKey(Object key)
          
 boolean containsValue(Object value)
          Returns true if this map maps one or more keys to the specified value.
 Set<Map.Entry<String,V>> entrySet()
          
 V get(Object key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for this key.
 String getKeyPrefix()
          Returns the key prefix for this map.
 boolean isEmpty()
          
 Set<String> keySet()
          
 V put(String key, V value)
          Associates the specified value with the specified key in this map.
 boolean putOverride(String key, V value)
          Associates the specified key with the specified value, and returns true if the key was previously mapped.
 V remove(Object key)
          Removes the mapping for key from this map if it is present, and returns the value to which the key was previously mapped, or null if this map contains no mapping for this key.
 boolean removeOverride(String key)
          Removes the specified key and associated value from the map, and returns true if the key was previously mapped.
 int size()
          Returns the number of key-value mappings in this map.
 Collection<V> values()
          
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, putAll
 

Constructor Detail

BindingKeyedMapImpl

BindingKeyedMapImpl(String keyPrefix)
Constructs an instance with the specified keyPrefix.

Parameters:
keyPrefix - a key prefix
Throws:
IllegalArgumentException - if keyPrefix is empty
Method Detail

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface Map<String,V>
Overrides:
isEmpty in class AbstractMap<String,V>

put

public V put(String key,
             V value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the previous value is replaced by the specified value.

Specified by:
put in interface BindingKeyedMap<V>
Specified by:
put in interface Map<String,V>
Overrides:
put in class AbstractMap<String,V>
Parameters:
key - a key
value - a value
Returns:
the previous value associated with key, or null if there was no such mapping

get

public V get(Object key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for this key.

Specified by:
get in interface BindingKeyedMap<V>
Specified by:
get in interface Map<String,V>
Overrides:
get in class AbstractMap<String,V>
Parameters:
key - a key
Returns:
the value to which the specified key is mapped, or null if there is no such mapping

containsKey

public boolean containsKey(Object key)

Specified by:
containsKey in interface Map<String,V>
Overrides:
containsKey in class AbstractMap<String,V>

containsValue

public boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. Values that have been removed from the data manager will be ignored.

Specified by:
containsValue in interface BindingKeyedMap<V>
Specified by:
containsValue in interface Map<String,V>
Overrides:
containsValue in class AbstractMap<String,V>
Parameters:
value - value whose presence in this map is to be tested
Returns:
true if this map maps one or more keys to the specified value

remove

public V remove(Object key)
Removes the mapping for key from this map if it is present, and returns the value to which the key was previously mapped, or null if this map contains no mapping for this key.

Specified by:
remove in interface BindingKeyedMap<V>
Specified by:
remove in interface Map<String,V>
Overrides:
remove in class AbstractMap<String,V>
Parameters:
key - a key
Returns:
the value to which the specified key was previously mapped, or null if there is no such mapping

clear

public void clear()
Removes all mappings from this map. This operation may be expensive because all of the map entries need to be traversed.

Specified by:
clear in interface BindingKeyedMap<V>
Specified by:
clear in interface Map<String,V>
Overrides:
clear in class AbstractMap<String,V>

size

public int size()
Returns the number of key-value mappings in this map. This operation may be expensive because all of the map entries may need to be traversed to determine the map's size.

Specified by:
size in interface BindingKeyedMap<V>
Specified by:
size in interface Map<String,V>
Overrides:
size in class AbstractMap<String,V>
Returns:
the number of key-value mappings in this map

entrySet

public Set<Map.Entry<String,V>> entrySet()

Specified by:
entrySet in interface Map<String,V>
Specified by:
entrySet in class AbstractMap<String,V>

keySet

public Set<String> keySet()

Specified by:
keySet in interface Map<String,V>
Overrides:
keySet in class AbstractMap<String,V>

values

public Collection<V> values()

Specified by:
values in interface Map<String,V>
Overrides:
values in class AbstractMap<String,V>

getKeyPrefix

public String getKeyPrefix()
Returns the key prefix for this map.

Specified by:
getKeyPrefix in interface BindingKeyedMap<V>
Returns:
the key prefix for this map

putOverride

public boolean putOverride(String key,
                           V value)
Associates the specified key with the specified value, and returns true if the key was previously mapped. This method will not throw ObjectNotFoundException if the key was previously mapped to a ManagedObject that has been removed from the DataManager.

Specified by:
putOverride in interface BindingKeyedMap<V>
Parameters:
key - a key
value - a value
Returns:
true if the key was previously mapped, and false otherwise

removeOverride

public boolean removeOverride(String key)
Removes the specified key and associated value from the map, and returns true if the key was previously mapped. This method will not throw ObjectNotFoundException if the key was previously mapped to a ManagedObject that has been removed from the DataManager.

Specified by:
removeOverride in interface BindingKeyedMap<V>
Parameters:
key - a key
Returns:
true if the key was previously mapped, and false otherwise

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved