com.sas.collection
Class Dictionary

com.sas.collection.Dictionary
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, CollectionInterface, com.sas.collection.ContentsChangedSource, DictionaryInterface, StaticCollectionInterface, StaticDictionaryInterface, ComponentInterface, com.sas.DeepClonable, LinkPropertiesInterface, ModelInterface, com.sas.PublicClonable, com.sas.util.Countable, com.sas.util.Enumerable, com.sas.util.EventGateInterface, ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener

public class Dictionary
implements DictionaryInterface, com.sas.DeepClonable

A Dictionary stores and retrieves values by a key. This class is an implementation of com.sas.collection.DictionaryInterface This class uses a Hashtable internally but provides a more consistent interface as well as event notification of changes to the dictionary.

See Also:
Serialized Form

Field Summary
static java.lang.String RB_KEY
           
protected  java.util.Hashtable table
           
 
Fields inherited from class com.sas.collection.BaseCollection
allContentsChangedListeners, mappingObject
 
Constructor Summary
Dictionary()
          Default Constructor.
Dictionary(int initialCapacity)
          Constructs a new, empty Dictionary with the specified initial capacity and default load factor.
Dictionary(int initialCapacity, float loadFactor)
          Constructs a new, empty Dictionary with the specified initial capacity and the specified load factor.
Dictionary(java.lang.String data)
          Constructs a new dictionary populated with elements parsed from a string.
 
Method Summary
 void add(java.lang.Object item)
          Add an item to this dictionary.
 void addItems(java.util.Enumeration items)
          Add all elements of an enumeration to this dictionary.
 java.lang.Object clone()
          Clone a Dictionary
 java.lang.Object clone(com.sas.DeepCloneSupport support, boolean deeply)
          Clone this object using a deep copy.
 boolean contains(java.lang.Object item)
          Test the existence of an object in this dictionary.
 boolean containsKey(java.lang.Object key)
          Test the existence of an key in a dictionary.
 int count()
          Returns the number of key/value pairs in this dictionary.
 int count(java.lang.Object value)
          Count the number of times the value exists in this dictionary.
 int countKey(java.lang.Object key)
          Count the number of times the given key is used in this dictionary.
 void dumpComponent()
          Prints the object.
 java.lang.Object get(java.lang.Object key)
          Fetch the item corresponding to a key.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 java.util.Enumeration getItems()
          Return an enumeration of all the items.
 java.lang.Object getKey(java.lang.Object item)
          Get the key corrsponding to an item.
 java.util.Enumeration getKeys()
          Return an Enumeration of all the keys in this dictionary.
 java.util.Enumeration getKeys(java.lang.Object item)
          Return an Enumeration of all the keys for a given item.
 boolean remove(java.lang.Object item)
          Remove an item from this dictionary.
 void removeAll()
          Remove all items from this collection.
 int removeAll(java.lang.Object item)
          Remove an item from this collection.
 void removeAt(java.lang.Object key)
          Remove the item corresponding to the specified key.
 void set(java.lang.Object key, java.lang.Object item)
          Put an item into this dictionary, possibly replacing a previous item that was there by the same key.
 java.lang.String toString()
          Convert this dictionary to a single string.
 java.lang.String toString(char delimiter, char separator, boolean alwaysQuote)
          Convert this dictionary to a single string.
 
Methods inherited from class com.sas.collection.BaseCollection
addContentsChangedListener, anyContentsChangedListeners, apply, disableEvents, enableEvents, enableEvents, fireContentsChanged, map, removeContentsChangedListener, unmap
 
Methods inherited from class com.sas.Component
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, detachModel, detachView, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getLinkInfo, getModelInterface, getRequiredInterfaces, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setDefaultValues, setLinkInfo, setModelInterface, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject
 
Methods inherited from interface com.sas.collection.StaticCollectionInterface
apply
 
Methods inherited from interface com.sas.collection.ContentsChangedSource
addContentsChangedListener, removeContentsChangedListener
 
Methods inherited from interface com.sas.beans.PropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

table

protected java.util.Hashtable table
Constructor Detail

Dictionary

public Dictionary()
Default Constructor. The default dictionary uses the same initialCapacity and loadFactor as a default Hashtable

See Also:
Hashtable

Dictionary

public Dictionary(int initialCapacity,
                  float loadFactor)
Constructs a new, empty Dictionary with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the internal hashtable.
loadFactor - a number between 0.0 and 1.0 which determines how full this dictionary can get before the internal structure is extended. The default is 0.75.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero.

Dictionary

public Dictionary(int initialCapacity)
Constructs a new, empty Dictionary with the specified initial capacity and default load factor.

Parameters:
initialCapacity - the initial capacity of the hashtable.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero.
See Also:
Dictionary(int, float)

Dictionary

public Dictionary(java.lang.String data)
Constructs a new dictionary populated with elements parsed from a string.

Parameters:
data - a string of key=value pairs, separated by commas. Boolean and number objects are recognized and parsed into appropriate Boolean, Integer, Long, or Double objects (for either the key or the value); everything else is parsed into a String or Character. For example, new AssociationList("A=1,two=2,3=true") results in an dictionary with three values. The keys are "A", "two", and the Integer 3, and the corresponding values are the Integer 1, the Integer 2, and Boolean.TRUE.
Throws:
java.lang.IllegalArgumentException - if the data string is invalid
See Also:
StringToDictionaryInterfaceTransform
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

add

public void add(java.lang.Object item)
Add an item to this dictionary. The item is also used as the key, as in set(item, item), so as to minimize conflicts with preexisting items.

Specified by:
add in interface CollectionInterface
Parameters:
item - an object to add to this dictionary

addItems

public void addItems(java.util.Enumeration items)
Add all elements of an enumeration to this dictionary. This will perform a set(item, item) for each element of the enumeration.

Specified by:
addItems in interface CollectionInterface
Parameters:
items - an Enumeration of items to add to this dictionary

removeAll

public void removeAll()
Remove all items from this collection.

Specified by:
removeAll in interface CollectionInterface

contains

public boolean contains(java.lang.Object item)
Test the existence of an object in this dictionary. The dictionary keys are not searched, only the values.

Specified by:
contains in interface StaticCollectionInterface
Overrides:
contains in class BaseCollection
Parameters:
item - the item to search for.
Returns:
true if and only if the item exists.
See Also:
StaticCollectionInterface.contains(java.lang.Object)

containsKey

public boolean containsKey(java.lang.Object key)
Test the existence of an key in a dictionary.

Specified by:
containsKey in interface StaticDictionaryInterface
Parameters:
key - the key to search for
Returns:
true if and only if an item with the specified key exists in this dictionary.

count

public int count()
Returns the number of key/value pairs in this dictionary.

Specified by:
count in interface com.sas.util.Countable
Specified by:
count in class BaseCollection
Returns:
the number of key/value pairs in this dictionary.

countKey

public int countKey(java.lang.Object key)
Count the number of times the given key is used in this dictionary.

Parameters:
key - the key to count
Returns:
the number of times the key appears in this dictionary. For a Dictionary, this count is always 1 or 0.

count

public int count(java.lang.Object value)
Count the number of times the value exists in this dictionary.

Parameters:
value - a value to count
Returns:
the number of times the value exists in this dictionary

dumpComponent

public void dumpComponent()
Prints the object.

Specified by:
dumpComponent in interface ComponentInterface
Overrides:
dumpComponent in class Component
See Also:
ComponentInterface.dumpComponent()

get

public java.lang.Object get(java.lang.Object key)
Fetch the item corresponding to a key.

Specified by:
get in interface StaticDictionaryInterface
Parameters:
key - the Object key with which the item was added to this dictionary.
Returns:
the item in this collection which corresponds to the given key. There may be only one item per key. Note that this method does not return null to indicate that an item does not exists. Rather, if there is no such key, this dictionary throws a NoSuchElementException. This is because a com.sas.collection.Dictionary may contains null values for either the key or the value items, so you would not know if a return value of null meant the key does not exists or the key exists but is associated with the null value.
Throws:
java.util.NoSuchElementException - when there is no entry for the specified key. (Note that null is a valid value for a key.)

getItems

public java.util.Enumeration getItems()
Return an enumeration of all the items. The items are not returned in any specific order.

Specified by:
getItems in interface com.sas.util.Enumerable
Specified by:
getItems in class BaseCollection
Returns:
an Enumeration of the elements stored in this dictionary (not the keys).
See Also:
Enumerable.getItems()

getKey

public java.lang.Object getKey(java.lang.Object item)
Get the key corrsponding to an item. Note that a dictionary may contain the same item via multiple keys. If so, this method returns one, but which one is undefined (i.e. it does not have to be the first one entered in this dictionary, or the first one as found in the getItems() or getKeys() enumerations).

Specified by:
getKey in interface StaticDictionaryInterface
Parameters:
item - the item whose key you wish to find.
Returns:
the key for the item. The key will be null if the item was added with a null key.
Throws:
java.util.NoSuchElementException - if the item does not exist in this dictionary.

getKeys

public java.util.Enumeration getKeys(java.lang.Object item)
Return an Enumeration of all the keys for a given item. The order is unspecified. If the item does not exist, a zero length array is returned.

Specified by:
getKeys in interface StaticDictionaryInterface
Parameters:
item - the item to search for
Returns:
an Enumeration of keys corresponding to the item.

getKeys

public java.util.Enumeration getKeys()
Return an Enumeration of all the keys in this dictionary.

Specified by:
getKeys in interface StaticDictionaryInterface
Returns:
an Enumeration of all keys.

remove

public boolean remove(java.lang.Object item)
Remove an item from this dictionary. If the item exists multiple times under different keys, only one occurrence is removed; it is undetermined which of the multiple occurrences will be removed.

Specified by:
remove in interface CollectionInterface
Specified by:
remove in interface DictionaryInterface
Parameters:
item - the item to remove
Returns:
true if item removed, false if not.
See Also:
removeAll(Object)

removeAll

public int removeAll(java.lang.Object item)
Remove an item from this collection. All occurrences of the item are removed.

Specified by:
removeAll in interface CollectionInterface
Parameters:
item - the item to remove
Returns:
the number of items deleted
See Also:
remove(Object)

removeAt

public void removeAt(java.lang.Object key)
Remove the item corresponding to the specified key.

Specified by:
removeAt in interface DictionaryInterface
Parameters:
key - remove the key/value pair which corresponds to this key.

set

public void set(java.lang.Object key,
                java.lang.Object item)
Put an item into this dictionary, possibly replacing a previous item that was there by the same key.

Specified by:
set in interface DictionaryInterface
Parameters:
key - the key by which the item may be retrieved later.
item - the value to put into this dictionary.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone a Dictionary

Specified by:
clone in interface CollectionInterface
Specified by:
clone in interface DictionaryInterface
Specified by:
clone in interface StaticCollectionInterface
Specified by:
clone in interface StaticDictionaryInterface
Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class BaseCollection
Returns:
a new Dictionary with the same contents as this dictionary, but no listeners. The keys and items are not cloned.
Throws:
java.lang.CloneNotSupportedException - if the clone fails.

clone

public java.lang.Object clone(com.sas.DeepCloneSupport support,
                              boolean deeply)
                       throws java.lang.CloneNotSupportedException
Clone this object using a deep copy. With this method, this class implements DeepClonable This object and all the objects it contains are cloned, preserving the same structure.

Specified by:
clone in interface com.sas.DeepClonable
Parameters:
support - a required object which keeps track of cloned objects during the deep cloning.
deeply - If true, clone recursively using the deep clone support. if false, this is equivalent to a normal clone.
Throws:
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Convert this dictionary to a single string.

Overrides:
toString in class java.lang.Object
Returns:
a string consisting of the quoted elements of this dictionary, separated by commas.

toString

public java.lang.String toString(char delimiter,
                                 char separator,
                                 boolean alwaysQuote)
Convert this dictionary to a single string.

Parameters:
delimiter - a delimiter for separating the items.
separator - a separator which appears between the keys and the values
alwaysQuote - if true, all items are quote. If false, only quote items which require quotes (such as strings containing the delimiter character, or the '\' character, etc.)
Returns:
a string consisting of the optionally quoted elements of this dictionary, separated by a delimiter.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.