com.plumtree.openfoundation.util
Class XPSortedDictionary

java.lang.Object
  extended bycom.plumtree.openfoundation.util.XPSortedDictionary
All Implemented Interfaces:
IXPDictionary

public class XPSortedDictionary
extends java.lang.Object
implements IXPDictionary

Implements a collection of key-value mappings, maintained in order of the keys, which should be all of the same type (e.g. String or Integer). The implementation depends on java.util.TreeMap, which notes: All keys inserted into the map must implement the Comparable interface. Furthermore, all such keys must be mutually comparable: k1.compareTo(k2) must not throw a ClassCastException for any elements k1 and k2 in the map.


Constructor Summary
XPSortedDictionary()
          Constructs a new, empty XPSortedDictionary, sorted according to the keys' natural order.
XPSortedDictionary(java.util.TreeMap treeMap)
          Takes the Red-Black tree based implementation of the SortedMap interface.This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on which constructor is used.
 
Method Summary
 void Clear()
          Removes all mappings from this TreeMap.
 boolean ContainsKey(java.lang.Object key)
          Returns if the input key exists in this IXPDictionary.
 boolean ContainsValue(java.lang.Object _value)
          Returns true if this map maps one or more keys to the specified value.
 java.lang.Object GetElement(java.lang.Object key)
          Return the object mapped to this key, or null if the key is not present in this XPSortedDictionary instance.
 IXPEnumerator GetElements()
          Returns an enumeration of the Elements in this IXPDictionary.
 IXPDictionaryEnumerator GetEnumerator()
          Returns IXPDictionaryEnumerator for this dictionary.
 IXPEnumerator GetKeys()
          Returns an enumeration of the keys in this IXPDictionary.
 int GetSize()
          Returns the number of entries (dinstint keys) in this dictionary.
 java.util.Map GetUnderlyingObject()
           
 boolean IsEmpty()
          Returns true if this map contains no key-value mappings.
 java.lang.Object PutElement(java.lang.Object key, java.lang.Object _value)
          Store an object in this XPSortedDictionary instance.
 java.lang.Object RemoveElement(java.lang.Object key)
          Removes the key (and its corresponding value) from this dictionary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPSortedDictionary

public XPSortedDictionary()
Constructs a new, empty XPSortedDictionary, sorted according to the keys' natural order. All keys inserted into the map must implement the IXPComparable interface. Furthermore, all such keys must be mutually comparable: k1.compareTo(k2) must not throw a XPClassCastException for any elements k1 and k2 in the map. If the user attempts to put a key into the map that violates this constraint (for example, the user attempts to put a string key into a map whose keys are integers), the put(Object key, Object value) call will throw a XPClassCastException.


XPSortedDictionary

public XPSortedDictionary(java.util.TreeMap treeMap)
Takes the Red-Black tree based implementation of the SortedMap interface.This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on which constructor is used.

Parameters:
treeMap - Red-Black tree based TreeMap.
Method Detail

Clear

public void Clear()
Removes all mappings from this TreeMap.


ContainsKey

public boolean ContainsKey(java.lang.Object key)
Description copied from interface: IXPDictionary
Returns if the input key exists in this IXPDictionary.

Specified by:
ContainsKey in interface IXPDictionary
Parameters:
key - to be verified in the IXPDictionary.
Returns:
true if Key exists in this IXPDictionary or false if not.

ContainsValue

public boolean ContainsValue(java.lang.Object _value)
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 (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the Map size for most implementations of Map.

Parameters:
_value - value whose presence in this Map is to be tested.
Returns:
true if a mapping to value exists; false otherwise.

GetElements

public IXPEnumerator GetElements()
Description copied from interface: IXPDictionary
Returns an enumeration of the Elements in this IXPDictionary.

Specified by:
GetElements in interface IXPDictionary
Returns:
an IXPEnumerator over the elements of this dictionary.

GetKeys

public IXPEnumerator GetKeys()
Description copied from interface: IXPDictionary
Returns an enumeration of the keys in this IXPDictionary. The general contract for the keys method is that an IXPEnumerator object is returned that will generate all the keys for which this IXPDictionary contains entries.

Specified by:
GetKeys in interface IXPDictionary
Returns:
an enumeration of the keys in this dictionary.

GetEnumerator

public IXPDictionaryEnumerator GetEnumerator()
Returns IXPDictionaryEnumerator for this dictionary.

Specified by:
GetEnumerator in interface IXPDictionary
Returns:
IXPDictionaryEnumerator

GetElement

public java.lang.Object GetElement(java.lang.Object key)
Return the object mapped to this key, or null if the key is not present in this XPSortedDictionary instance.

Specified by:
GetElement in interface IXPDictionary
Parameters:
key - a key in this dictionary. null if the key is not mapped to any value in this dictionary.
Returns:
the value to which the key is mapped in this dictionary;

IsEmpty

public boolean IsEmpty()
Returns true if this map contains no key-value mappings.

This implementation returns size() == 0.

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

PutElement

public java.lang.Object PutElement(java.lang.Object key,
                                   java.lang.Object _value)
Store an object in this XPSortedDictionary instance. All keys must implement IComparable and be inter-comparable to determine the order. Caution: the Java version throws XPClassCastException on an incompatible key, while the .NET version throws XPIllegalArgumentException. This should be resolved to XPIllegalArgumentException.

Specified by:
PutElement in interface IXPDictionary
Parameters:
key - key with which the specified value is to be associated.
_value - value to be associated with the specified key.
Returns:
original value for the key, if any.
Throws:
XPClassCastException - if the key is of a type which is not comparable with the pre-existing keys in the map.

RemoveElement

public java.lang.Object RemoveElement(java.lang.Object key)
Description copied from interface: IXPDictionary
Removes the key (and its corresponding value) from this dictionary. This method does nothing if the key is not in this dictionary.

Specified by:
RemoveElement in interface IXPDictionary
Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this dictionary, or null if the key did not have a mapping.

GetSize

public int GetSize()
Description copied from interface: IXPDictionary
Returns the number of entries (dinstint keys) in this dictionary.

Specified by:
GetSize in interface IXPDictionary
Returns:
the number of keys in this dictionary.

GetUnderlyingObject

public java.util.Map GetUnderlyingObject()


Copyright 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.