com.pega.pegarules.pub.util
Class HashStringMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by com.pega.pegarules.pub.util.HashStringMap
All Implemented Interfaces:
StringMap, java.util.Map

public class HashStringMap
extends java.util.AbstractMap
implements StringMap

Simplest implementation of the StringMap interface, using a java.util.HashMap internally. This implementation requires that both the name and value String instances be non-null, but imposes no other restrictions.

Version:
$Revision: 5030 $ $Date: 2010-06-09 09:50:47 -0400 (Wed, 09 Jun 2010) $
Author:
John van der Meer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String VERSION
           
 
Constructor Summary
HashStringMap()
          Default constructor.
HashStringMap(int initialCapacity)
          Constructs an empty HashStringMap with the specified initial capacity and the default load factor (0.75).
HashStringMap(java.util.Map aMap)
          'Copy' constructor.
 
Method Summary
 void clear()
          Removes all associations from the collection.
 boolean containsKey(java.lang.Object aName)
          Identifies whether there is an association for the specified name.
 boolean containsValue(java.lang.Object aValue)
          Identifies whether 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 instance.
 boolean equals(java.lang.Object aObject)
          Compares the specified object with this map for equality.
 int estimateInternalStringSize()
           
 java.lang.Object get(java.lang.Object aName)
          Identifies the value, if any, that is associated with the specified name.
 java.lang.String getKeyString(ClassDefinition aClassDef)
          Deprecated. this method should only be used internally
 java.lang.String getKeyString(ClassDefinition aClassDef, java.lang.String aAspect)
          Returns a string representation of the key values of this map, assuming that this map represents the key properties for an instance.
 java.util.List<java.lang.String> getKeyStrings(ClassDefinition aClassDef, java.lang.String aAspect, boolean aUseInsId)
           
 java.util.List<java.lang.String> getKeyStrings(ClassDefinition aClassDef, java.lang.String aUpperCaseClassName, java.lang.String aAspect, boolean aUseInsId)
           
 java.lang.String getString(java.lang.String aName)
          Identifies the value, if any, that is associated with the specified name.
 int hashCode()
          Returns the hash code value for this instance, which will be the hashCode value of the underlying java.util.HashMap.
 boolean isEmpty()
          Inicates whether this map contains no name-value associations.
 java.util.Set keySet()
          Returns a set view of the keys (names) contained in this instance.
 java.lang.Object put(java.lang.Object aName, java.lang.Object aValue)
          Associates the specified value with the specified name in this instance, provided that they are both String instances.
 void putAll(java.util.Map aMap)
          Copies all conforming mappings from the specified Map to this instance.
 void putString(java.lang.String aName, java.lang.String aValue)
          Associates the specified value with the specified name in this instance.
 java.lang.Object remove(java.lang.Object aName)
          Removes any association for this name from this instance.
 void remove(java.lang.String aName)
          Removes any association for this name from this instance.
 int size()
          Returns the number of name-value mappings in this instance.
 java.lang.String toString()
          Returns a string representation of this map.
 java.lang.String toStringUpper()
          Returns a string representation of this map with all keys and values converted to upper cases.
 java.util.Collection values()
          Returns a collection view of the values contained in this instance.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT

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

VERSION

public static final java.lang.String VERSION
Constructor Detail

HashStringMap

public HashStringMap()
Default constructor.


HashStringMap

public HashStringMap(int initialCapacity)
Constructs an empty HashStringMap with the specified initial capacity and the default load factor (0.75).

Parameters:
initialCapacity - the initial capacity.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is negative.

HashStringMap

public HashStringMap(java.util.Map aMap)
'Copy' constructor. Ignores mappings in the arguemtn for which the key or value is not a String.

Parameters:
aMap - the Map to be copied
Method Detail

clear

public void clear()
Removes all associations from the collection.

Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.AbstractMap

getString

public java.lang.String getString(java.lang.String aName)
Identifies the value, if any, that is associated with the specified name.

Specified by:
getString in interface StringMap
Parameters:
aName - name whose associated value is to be returned
Returns:
the String value associated with the specified name, or null if this instance includes no association for this name

putString

public void putString(java.lang.String aName,
                      java.lang.String aValue)
Associates the specified value with the specified name in this instance. Any previous association for this name is replaced.

Specified by:
putString in interface StringMap
Parameters:
aName - name with which the specified value is to be associated
aValue - value to be associated with the specified name
Throws:
java.lang.NullPointerException - if either argument is null

remove

public void remove(java.lang.String aName)
Removes any association for this name from this instance.

Parameters:
aName - name to be removed from this instance

containsKey

public boolean containsKey(java.lang.Object aName)
Identifies whether there is an association for the specified name.

Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class java.util.AbstractMap
Parameters:
aName - name whose presence is to be tested
Returns:
true when this instance includes an association for this name

containsValue

public boolean containsValue(java.lang.Object aValue)
Identifies whether this map maps one or more keys to the specified value.

Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class java.util.AbstractMap
Parameters:
aValue - value whose presence is to be tested
Returns:
true when this instance associates this value with at least one name

entrySet

public java.util.Set entrySet()
Returns a set view of the mappings contained in this instance.

Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class java.util.AbstractMap
Returns:
a set view of the mappings in this instance

equals

public boolean equals(java.lang.Object aObject)
Compares the specified object with this map for equality.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.util.AbstractMap
Parameters:
aObject -
Returns:
true when this instance is equivalent to the specified object

get

public java.lang.Object get(java.lang.Object aName)
Identifies the value, if any, that is associated with the specified name.

Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.AbstractMap
Parameters:
aName - name whose associated value is to be returned
Returns:
the value associated with the specified name, or null if this instance includes no association for this name

hashCode

public int hashCode()
Returns the hash code value for this instance, which will be the hashCode value of the underlying java.util.HashMap.

Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class java.util.AbstractMap
Returns:
the hash code value for this instance

isEmpty

public boolean isEmpty()
Inicates whether this map contains no name-value associations.

Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class java.util.AbstractMap
Returns:
true when this instance contains no name-value associations

keySet

public java.util.Set keySet()
Returns a set view of the keys (names) contained in this instance.

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class java.util.AbstractMap
Returns:
a set view of the keys in this instance

put

public java.lang.Object put(java.lang.Object aName,
                            java.lang.Object aValue)
Associates the specified value with the specified name in this instance, provided that they are both String instances. Any previous association for this name is replaced.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.AbstractMap
Parameters:
aName - name with which the specified value is to be associated
aValue - value to be associated with the specified name
Returns:
previous association for this name, or null if there was none
Throws:
java.lang.ClassCastException - if either argument is not a String
java.lang.NullPointerException - if either argument is null

putAll

public void putAll(java.util.Map aMap)
Copies all conforming mappings from the specified Map to this instance. Entries in the specified Map are ignored if the key is not a String or if the value does not identify a String.

Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class java.util.AbstractMap
Parameters:
aMap - the Map to be copied

remove

public java.lang.Object remove(java.lang.Object aName)
Removes any association for this name from this instance.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.AbstractMap
Parameters:
aName - name to be removed from this instance
Returns:
previous association for this name, or null if there was none

size

public int size()
Returns the number of name-value mappings in this instance.

Specified by:
size in interface java.util.Map
Overrides:
size in class java.util.AbstractMap
Returns:
number of mappings

values

public java.util.Collection values()
Returns a collection view of the values contained in this instance.

Specified by:
values in interface java.util.Map
Overrides:
values in class java.util.AbstractMap
Returns:
a collection view of the values in this instance

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).

This implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.

Specified by:
toString in interface StringMap
Overrides:
toString in class java.util.AbstractMap
Returns:
a String representation of this map.

getKeyStrings

public java.util.List<java.lang.String> getKeyStrings(ClassDefinition aClassDef,
                                                      java.lang.String aUpperCaseClassName,
                                                      java.lang.String aAspect,
                                                      boolean aUseInsId)

getKeyStrings

public java.util.List<java.lang.String> getKeyStrings(ClassDefinition aClassDef,
                                                      java.lang.String aAspect,
                                                      boolean aUseInsId)

getKeyString

public java.lang.String getKeyString(ClassDefinition aClassDef)
Deprecated. this method should only be used internally

Returns a string representation of the key values of this map, assuming that this map represents the key properties for an instance.

Parameters:
aClassDef - the class of the rule represented by the keys
Returns:
a String representation of this map's keys

getKeyString

public java.lang.String getKeyString(ClassDefinition aClassDef,
                                     java.lang.String aAspect)
Returns a string representation of the key values of this map, assuming that this map represents the key properties for an instance.

This method should only be used internally by PegaRULES.

Parameters:
aClassDef - the class of the rule represented by the keys
aAspect - the aspect of the rule
Returns:
a String representation of this map's keys

toStringUpper

public java.lang.String toStringUpper()
Returns a string representation of this map with all keys and values converted to upper cases. 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).

This implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.

Returns:
an upper-cased String representation of this map.

estimateInternalStringSize

public int estimateInternalStringSize()


Copyright © 2012 Pegasystems Inc. All Rights Reserved.