Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.1.0 E18814-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.util
Class AbstractKeyBasedMap

`java.lang.Object
com.tangosol.util.Base
com.tangosol.util.AbstractKeyBasedMap`

All Implemented Interfaces:
  java.util.Map

Direct Known Subclasses:
  AbstractKeySetBasedMap, CacheStoreMap.ReadWriteMap, PartitionSplittingBackingMap, PartitionSplittingBackingMap.MaskedPartitionMap, ReadWriteBackingMap.EvictingBackupMap, SimpleOverflowMap, SimpleSerializationMap

      public abstract class AbstractKeyBasedMap

extends Base
implements java.util.Map

AbstractKeyBasedMap is a base class for Map implementations. The primary difference between the `AbstractMap` abstract class and this abstract class is this: that AbstractMap requires a sub-class to provide an Entry Set implementation, while AbstractKeyBasedMap requires a read-only sub-class to implement only get() and iterateKeys(), and a read-write sub-class to additionally implement only put() and remove().

Read-only implementations must implement `iterateKeys()` and `get(Object)`. Read/write implementations must additionally implement `put(Object, Object)` and `remove(Object)`. A number of the methods have implementations provided, but are extremely inefficient for Maps that contain large amounts of data, including `clear()`, `containsKey(Object)`, `size()` (and by extension `isEmpty()`). Furthermore, if any of a number of method implementations has any cost of returning an "old value", such as is done by the `put(java.lang.Object, java.lang.Object)` and `remove(Object)` methods, then the `putAll(java.util.Map)` and `removeBlind(Object)` methods should also be implemented.

Author:
  2005.07.13 cp

Nested Class Summary
`class` | `AbstractKeyBasedMap.EntrySet` A set of entries backed by this map.
`protected class` | `AbstractKeyBasedMap.KeySet` A set of keys backed by this map.
`protected class` | `AbstractKeyBasedMap.ValuesCollection` A Collection of values backed by this map.

Nested classes/interfaces inherited from interface java.util.Map
`java.util.Map.Entry`

Constructor Summary
`AbstractKeyBasedMap()`

Method Summary
`void` | `clear()` Clear all key/value mappings.
`protected java.lang.Object` | `clone()` Returns a shallow copy of this `AbstractKeyBasedMap` instance; the keySet, entrySet and values collections are not cloned or copied to (shared by) the clone.
`boolean` | `containsKey(java.lang.Object oKey)` Returns `true` if this map contains a mapping for the specified key.
`boolean` | `containsValue(java.lang.Object oValue)` Returns `true` if this Map maps one or more keys to the specified value.
`java.util.Set` | `entrySet()` Returns a set view of the mappings contained in this map.
`boolean` | `equals(java.lang.Object o)` Compares the specified object with this map for equality.
`abstract java.lang.Object` | `get(java.lang.Object oKey)` Returns the value to which this map maps the specified key.
`java.util.Map` | `getAll(java.util.Collection colKeys)` Get all the specified keys, if they are in the Map.
`int` | `hashCode()` Returns the hash code value for this Map.
`protected java.util.Set` | `instantiateEntrySet()` Factory pattern: Create a Set that represents the entries in the Map.
`protected java.util.Set` | `instantiateKeySet()` Factory pattern: Create a Set that represents the keys in the Map
`protected java.util.Collection` | `instantiateValues()` Factory pattern: Instantiate the values Collection.
`boolean` | `isEmpty()` Returns `true` if this map contains no key-value mappings.
`protected abstract java.util.Iterator` | `iterateKeys()` Create an iterator over the keys in this Map.
`java.util.Set` | `keySet()` Returns a set view of the keys contained in this map.
`java.lang.Object` | `put(java.lang.Object oKey, java.lang.Object oValue)` Associates the specified value with the specified key in this map.
`void` | `putAll(java.util.Map map)` Copies all of the mappings from the specified map to this map.
`java.lang.Object` | `remove(java.lang.Object oKey)` Removes the mapping for this key from this map if present.
`protected boolean` | `removeBlind(java.lang.Object oKey)` Removes the mapping for this key from this map if present.
`int` | `size()` Returns the number of key-value mappings in this map.
`java.lang.String` | `toString()` Returns a string representation of this Map.
`java.util.Collection` | `values()` Returns a collection view of the values contained in this map.

Constructor Detail

### AbstractKeyBasedMap

    public AbstractKeyBasedMap()

Method Detail

### clear

    public void clear()

  Clear all key/value mappings.
  Specified by:
    `clear` in interface `java.util.Map`

### containsKey

    public boolean containsKey(java.lang.Object oKey)

  Returns `true` if this map contains a mapping for the specified key.
  Specified by:
    `containsKey` in interface `java.util.Map`
  Parameters:
    `oKey` - key whose presence in this map is to be tested.
  Returns:
    `true` if this map contains a mapping for the specified key, `false` otherwise.

### containsValue

    public boolean containsValue(java.lang.Object oValue)

  Returns `true` if this Map maps one or more keys to the specified value.
  Specified by:
    `containsValue` in interface `java.util.Map`
  Parameters:
    `oValue` - value whose presence in this map is to be tested.
  Returns:
    `true` if this Map maps one or more keys to the specified value, `false` otherwise

### entrySet

    public java.util.Set entrySet()

  Returns a set view of the mappings contained in this map. Each element in the returned set is an `AbstractKeyBasedMap.EntrySet.Entry`. 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 by the iterator's own `remove` operation, or by 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 is not expected to support the `add` or `addAll` operations.
  Specified by:
    `entrySet` in interface `java.util.Map`
  Returns:
    a set view of the mappings contained in this map

### get

    public abstract java.lang.Object get(java.lang.Object oKey)

  Returns the value to which this map maps the specified key.
  Specified by:
    `get` in interface `java.util.Map`
  Parameters:
    `oKey` - the key object
  Returns:
    the value to which this map maps the specified key, or null if the map contains no mapping for this key
  See Also:
    `Map.containsKey(Object)`

### isEmpty

    public boolean isEmpty()

  Returns `true` if this map contains no key-value mappings.
  Specified by:
    `isEmpty` in interface `java.util.Map`
  Returns:
    `true` if this map contains no key-value mappings

### keySet

    public java.util.Set 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 is not expected to support the add or `addAll` operations.
  Specified by:
    `keySet` in interface `java.util.Map`
  Returns:
    a set view of the keys contained in this map

### put

    public java.lang.Object put(java.lang.Object oKey,
                                java.lang.Object oValue)

  Associates the specified value with the specified key in this map.
  Specified by:
    `put` in interface `java.util.Map`
  Parameters:
    `oKey` - key with which the specified value is to be associated
    `oValue` - value to be associated with the specified key
  Returns:
    previous value associated with specified key, or `null` if there was no mapping for key

### putAll

    public void putAll(java.util.Map map)

  Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of calling `put(java.lang.Object, java.lang.Object)` on this map once for each mapping in the passed map. The behavior of this operation is unspecified if the passed map is modified while the operation is in progress.
  Specified by:
    `putAll` in interface `java.util.Map`
  Parameters:
    `map` - the Map containing the key/value pairings to put into this Map

### remove

    public java.lang.Object remove(java.lang.Object oKey)

  Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.
  Specified by:
    `remove` in interface `java.util.Map`
  Parameters:
    `oKey` - key whose mapping is to be removed from the map
  Returns:
    previous value associated with specified key, or `null` if there was no mapping for key. A `null` return can also indicate that the map previously associated `null` with the specified key, if the implementation supports `null` values.

### size

    public int size()

  Returns the number of key-value mappings in this map.
  Specified by:
    `size` in interface `java.util.Map`
  Returns:
    the number of key-value mappings in this map

### values

    public java.util.Collection 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 is not expected to support the add or `addAll` operations.
  Specified by:
    `values` in interface `java.util.Map`
  Returns:
    a Collection view of the values contained in this map

### getAll

    public java.util.Map getAll(java.util.Collection colKeys)

  Get all the specified keys, if they are in the Map. For each key that is in the cache, that key and its corresponding value will be placed in the map that is returned by this method. The absence of a key in the returned map indicates that it was not in the cache, which may imply (for caches that can load behind the scenes) that the requested data could not be loaded.
  Parameters:
    `colKeys` - a collection of keys that may be in the named cache
  Returns:
    a Map of keys to values for the specified keys passed in `colKeys`

### iterateKeys

    protected abstract java.util.Iterator iterateKeys()

  Create an iterator over the keys in this Map. The Iterator must support remove() if the Map supports removal.
  Returns:
    a new instance of an Iterator over the keys in this Map

### removeBlind

    protected boolean removeBlind(java.lang.Object oKey)

  Removes the mapping for this key from this map if present. This method exists to allow sub-classes to optmiize remove functionalitly for situations in which the original value is not required.
  Parameters:
    `oKey` - key whose mapping is to be removed from the map
  Returns:
    true iff the Map changed as the result of this operation

### equals

    public boolean equals(java.lang.Object o)

  Compares the specified object with this map for equality. Returns `true` if the given object is also a map and the two maps represent the same mappings. More formally, two maps `t1` and `t2` represent the same mappings if `t1.keySet().equals(t2.keySet())` and for every key `k` in `t1.keySet()`, `(t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k)))` . This ensures that the `equals` method works properly across different implementations of the map interface.
  Specified by:
    `equals` in interface `java.util.Map`
  Parameters:
    `o` - object to be compared for equality with this Map
  Returns:
    `true` if the specified object is equal to this Map

### hashCode

    public int hashCode()

  Returns the hash code value for this Map. The hash code of a Map is defined to be the sum of the hash codes of each entry in the Map's `entrySet()` view. This ensures that `t1.equals(t2)` implies that `t1.hashCode()==t2.hashCode()` for any two maps `t1` and `t2`, as required by the general contract of Object.hashCode.
  Specified by:
    `hashCode` in interface `java.util.Map`
  Returns:
    the hash code value for this Map
  See Also:
    `Map.Entry.hashCode()`, `Object.hashCode()`, `Object.equals(Object)`, `Map.equals(Object)`

### toString

    public java.lang.String toString()

  Returns a string representation of this Map. The string representation consists of a list of key-value mappings in the order returned by the Map's `entrySet` view's iterator, enclosed in braces (`"{}"`). Adjacent mappings are separated by the characters `", "` (comma and space). Each key-value mapping is rendered as the key followed by an equals sign (`"="`) followed by the associated value. Keys and values are converted to strings as by `String.valueOf(Object)`.
  Returns:
    a String representation of this Map

### clone

    protected java.lang.Object clone()
                              throws java.lang.CloneNotSupportedException

  Returns a shallow copy of this `AbstractKeyBasedMap` instance; the keySet, entrySet and values collections are not cloned or copied to (shared by) the clone.
  Returns:
    a shallow copy of this map
  Throws:
    `java.lang.CloneNotSupportedException`

### instantiateKeySet

    protected java.util.Set instantiateKeySet()

  Factory pattern: Create a Set that represents the keys in the Map
  Returns:
    a new instance of Set that represents the keys in the Map

### instantiateEntrySet

    protected java.util.Set instantiateEntrySet()

  Factory pattern: Create a Set that represents the entries in the Map.
  Returns:
    a new instance of Set that represents the entries in the Map

### instantiateValues

    protected java.util.Collection instantiateValues()

  Factory pattern: Instantiate the values Collection.
  Returns:
    a new instance of Collection that represents this Map's values

Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.1.0 E18814-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.