org.ozoneDB.collections
Class _BaseTreeMap_SubMapImpl

java.lang.Object
  extended byorg.ozoneDB.OzoneObject
      extended byorg.ozoneDB.collections.AbstractOzoneMap
          extended byorg.ozoneDB.collections._BaseTreeMap_SubMapImpl
All Implemented Interfaces:
_BaseTreeMap_SubMap, java.util.Map, org.ozoneDB.OzoneCompatible, org.ozoneDB.OzoneCompatibleOrProxy, OzoneMap, org.ozoneDB.OzoneRemote, OzoneSortedMap, java.io.Serializable, java.util.SortedMap

public class _BaseTreeMap_SubMapImpl
extends AbstractOzoneMap
implements _BaseTreeMap_SubMap

Do not use this class directly. This should be an inner class; unfortunately ozone does not support those yet.

Implementation of subMap(Object, Object) and other map ranges. This class provides a view of a portion of the original backing map, and throws IllegalArgumentException for attempts to access beyond that range.

Author:
Eric Blake , Leo Mekenkamp (mind the anti-sp@m) (adaptation for ozone)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.ozoneDB.collections.OzoneMap
OzoneMap.Node
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  BaseTreeMap owner
          underlying BaseTreeMap.
 
Fields inherited from class org.ozoneDB.collections.AbstractOzoneMap
keys, values
 
Constructor Summary
_BaseTreeMap_SubMapImpl(BaseTreeMap owner, java.lang.Object minKey, java.lang.Object maxKey)
          Create a SubMap representing the elements between minKey (inclusive) and maxKey (exclusive).
 
Method Summary
 void clear()
          Remove all entries from this Map (optional operation).
 java.util.Comparator comparator()
           
 boolean containsKey(java.lang.Object key)
          Returns true if this contains a mapping for the given key.
 boolean containsValue(java.lang.Object value)
          Returns true if this contains at least one mapping with the given value.
 java.util.Set entrySet()
          Returns a set view of the mappings in this Map.
 java.lang.Object firstKey()
           
 java.lang.Object get(java.lang.Object key)
          Returns the value mapped by the given key.
 java.util.Map getClientMap()
          Returns a Map that contains the same entries as this persistent one; it is (by nature of the client-server enviromnent) always a 'deep' copy of this OzoneMap.
 java.util.SortedMap getClientSortedMap()
          Returns a SortedMap that contains the same entries as this persistent one; it is (by nature of the client-server enviromnent) always a 'deep' copy of this OzoneSortedMap.
 java.lang.Object getMaxKey()
           
 java.lang.Object getMinKey()
           
 BaseTreeMap getOwner()
           
 java.util.SortedMap headMap(java.lang.Object toKey)
           
 boolean keyInRange(java.lang.Object key)
          Check if "key" is in within the range bounds for this SubMap.
 java.util.Set keySet()
          Returns a set view of this map's keys.
 java.lang.Object lastKey()
           
 OzoneSortedMap ozoneHeadMap(java.lang.Object toKey)
          Basically nothing more than a typecasted HeadMap method.
 OzoneSortedMap ozoneSubMap(java.lang.Object fromKey, java.lang.Object toKey)
          Basically nothing more than a typecasted SubMap method.
 OzoneSortedMap ozoneTailMap(java.lang.Object toKey)
          Basically nothing more than a typecasted TailMap method.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the given key to the given value (optional operation).
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key if present (optional operation).
 int size()
          Returns the number of key-value mappings in the map.
 java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
           
 java.util.SortedMap tailMap(java.lang.Object fromKey)
           
 java.util.Collection values()
          Returns a collection or bag view of this map's values.
 
Methods inherited from class org.ozoneDB.collections.AbstractOzoneMap
clone, equals, hashCode, isEmpty, ozoneEntrySet, ozoneKeySet, ozoneValues, putAll, toString
 
Methods inherited from class org.ozoneDB.OzoneObject
container, database, deleteRecursive, getHandle, getObjectID, handle, onActivate, onCreate, onDelete, onPassivate, requireWriteLocking, self, setContainer, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ozoneDB.collections.OzoneMap
ozoneEntrySet, ozoneKeySet, ozoneValues, putAll
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty
 
Methods inherited from interface org.ozoneDB.OzoneCompatibleOrProxy
getObjectID
 

Field Detail

owner

protected BaseTreeMap owner
underlying BaseTreeMap.

Constructor Detail

_BaseTreeMap_SubMapImpl

public _BaseTreeMap_SubMapImpl(BaseTreeMap owner,
                               java.lang.Object minKey,
                               java.lang.Object maxKey)
Create a SubMap representing the elements between minKey (inclusive) and maxKey (exclusive). If minKey is nil, SubMap has no lower bound (headMap). If maxKey is nil, the SubMap has no upper bound (tailMap).

Parameters:
minKey - the lower bound
maxKey - the upper bound
Throws:
java.lang.IllegalArgumentException - if minKey > maxKey
Method Detail

keyInRange

public final boolean keyInRange(java.lang.Object key)
Check if "key" is in within the range bounds for this SubMap. The lower ("from") SubMap range is inclusive, and the upper ("to") bound is exclusive. Package visible for use by nested classes.

Specified by:
keyInRange in interface _BaseTreeMap_SubMap
Parameters:
key - the key to check
Returns:
true if the key is in range

clear

public void clear()
Description copied from class: AbstractOzoneMap
Remove all entries from this Map (optional operation). This default implementation calls entrySet().clear(). NOTE: If the entry set does not permit clearing, then this will fail, too. Subclasses often override this for efficiency. Your implementation of entrySet() should not call AbstractMap.clear unless you want an infinite loop.

Specified by:
clear in interface OzoneMap
Overrides:
clear in class AbstractOzoneMap
See Also:
Set.clear()

comparator

public java.util.Comparator comparator()
Specified by:
comparator in interface java.util.SortedMap

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from class: AbstractOzoneMap
Returns true if this contains a mapping for the given key. This implementation does a linear search, O(n), over the entrySet(), returning true if a match is found, false if the iteration ends. Many subclasses can implement this more efficiently.

Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class AbstractOzoneMap
Parameters:
key - the key to search for
Returns:
true if the map contains the key
See Also:
AbstractOzoneMap.containsValue(Object)

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from class: AbstractOzoneMap
Returns true if this contains at least one mapping with the given value. This implementation does a linear search, O(n), over the entrySet(), returning true if a match is found, false if the iteration ends. A match is defined as (value == null ? v == null : value.equals(v)) Subclasses are unlikely to implement this more efficiently.

Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class AbstractOzoneMap
Parameters:
value - the value to search for
Returns:
true if the map contains the value
See Also:
AbstractOzoneMap.containsKey(Object)

entrySet

public java.util.Set entrySet()
Description copied from class: AbstractOzoneMap
Returns a set view of the mappings in this Map. Each element in the set must be an implementation of Map.Entry. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods must be valid: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition is not supported via this set.

Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class AbstractOzoneMap
Returns:
the entry set
See Also:
Map.Entry

firstKey

public java.lang.Object firstKey()
Specified by:
firstKey in interface java.util.SortedMap

get

public java.lang.Object get(java.lang.Object key)
Description copied from class: AbstractOzoneMap
Returns the value mapped by the given key. Returns null if there is no mapping. However, in Maps that accept null values, you must rely on containsKey to determine if a mapping exists. This iteration takes linear time, searching entrySet().iterator() of the key. Many implementations override this method.

Specified by:
get in interface java.util.Map
Overrides:
get in class AbstractOzoneMap
Parameters:
key - the key to look up
Returns:
the value associated with the key, or null if key not in map
See Also:
AbstractOzoneMap.containsKey(Object)

headMap

public java.util.SortedMap headMap(java.lang.Object toKey)
Specified by:
headMap in interface java.util.SortedMap

keySet

public java.util.Set keySet()
Description copied from class: AbstractOzoneMap
Returns a set view of this map's keys. The set is backed by the map, so changes in one show up in the other. Modifications while an iteration is in progress produce undefined behavior. The set supports removal if entrySet() does, but does not support element addition.

This implementation creates an AbstractSet, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsKey. The set is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two sets.

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class AbstractOzoneMap
Returns:
a Set view of the keys
See Also:
Set.iterator(), AbstractOzoneMap.size(), AbstractOzoneMap.containsKey(Object), AbstractOzoneMap.values()

lastKey

public java.lang.Object lastKey()
Specified by:
lastKey in interface java.util.SortedMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from class: AbstractOzoneMap
Associates the given key to the given value (optional operation). If the map already contains the key, its value is replaced. This implementation simply throws an UnsupportedOperationException. Be aware that in a map that permits null values, a null return does not always imply that the mapping was created.

Specified by:
put in interface OzoneMap
Overrides:
put in class AbstractOzoneMap
Parameters:
key - the key to map
value - the value to be mapped
Returns:
the previous value of the key, or null if there was no mapping
See Also:
AbstractOzoneMap.containsKey(Object)

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from class: AbstractOzoneMap
Removes the mapping for this key if present (optional operation). This implementation iterates over the entrySet searching for a matching key, at which point it calls the iterator's remove method. It returns the result of getValue() on the entry, if found, or null if no entry is found. Note that maps which permit null values may also return null if the key was removed. If the entrySet does not support removal, this will also fail. This is O(n), so many implementations override it for efficiency.

Specified by:
remove in interface OzoneMap
Overrides:
remove in class AbstractOzoneMap
Parameters:
key - the key to remove
Returns:
the value the key mapped to, or null if not present
See Also:
Iterator.remove()

size

public int size()
Description copied from class: AbstractOzoneMap
Returns the number of key-value mappings in the map. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is implemented as entrySet().size().

Specified by:
size in interface java.util.Map
Overrides:
size in class AbstractOzoneMap
Returns:
the number of mappings
See Also:
Set.size()

subMap

public java.util.SortedMap subMap(java.lang.Object fromKey,
                                  java.lang.Object toKey)
Specified by:
subMap in interface java.util.SortedMap

tailMap

public java.util.SortedMap tailMap(java.lang.Object fromKey)
Specified by:
tailMap in interface java.util.SortedMap

values

public java.util.Collection values()
Description copied from class: AbstractOzoneMap
Returns a collection or bag view of this map's values. The collection is backed by the map, so changes in one show up in the other. Modifications while an iteration is in progress produce undefined behavior. The collection supports removal if entrySet() does, but does not support element addition.

This implementation creates an AbstractCollection, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsValue. The collection is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two collections.

Specified by:
values in interface java.util.Map
Overrides:
values in class AbstractOzoneMap
Returns:
a Collection view of the values
See Also:
Collection.iterator(), AbstractOzoneMap.size(), AbstractOzoneMap.containsValue(Object), AbstractOzoneMap.keySet()

getClientMap

public java.util.Map getClientMap()

Returns a Map that contains the same entries as this persistent one; it is (by nature of the client-server enviromnent) always a 'deep' copy of this OzoneMap. I.e. the contents of this OzoneMap instance are always copied to the client by use of serialization.

Specified by:
getClientMap in interface OzoneMap

getClientSortedMap

public java.util.SortedMap getClientSortedMap()

Returns a SortedMap that contains the same entries as this persistent one; it is (by nature of the client-server enviromnent) always a 'deep' copy of this OzoneSortedMap. I.e. the contents of this OzoneSortedMap instance are always copied to the client by use of serialization.

Specified by:
getClientSortedMap in interface OzoneSortedMap

getMinKey

public java.lang.Object getMinKey()
Specified by:
getMinKey in interface _BaseTreeMap_SubMap

getMaxKey

public java.lang.Object getMaxKey()
Specified by:
getMaxKey in interface _BaseTreeMap_SubMap

getOwner

public BaseTreeMap getOwner()
Specified by:
getOwner in interface _BaseTreeMap_SubMap

ozoneHeadMap

public OzoneSortedMap ozoneHeadMap(java.lang.Object toKey)

Basically nothing more than a typecasted HeadMap method. Because subsets are also OzoneSortedMaps, this method is provided to do away with the need for a typecast.

Specified by:
ozoneHeadMap in interface OzoneSortedMap

ozoneSubMap

public OzoneSortedMap ozoneSubMap(java.lang.Object fromKey,
                                  java.lang.Object toKey)

Basically nothing more than a typecasted SubMap method. Because subsets are also OzoneSortedMaps, this method is provided to do away with the need for a typecast.

Specified by:
ozoneSubMap in interface OzoneSortedMap

ozoneTailMap

public OzoneSortedMap ozoneTailMap(java.lang.Object toKey)

Basically nothing more than a typecasted TailMap method.

Because subsets are also OzoneSortedMaps, this method is provided to do away with the need for a typecast.

Specified by:
ozoneTailMap in interface OzoneSortedMap


Copyright © 2004 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.