edu.stanford.rt.credential
Class OrderedMap

java.lang.Object
  |
  +--edu.stanford.rt.credential.OrderedMap

public class OrderedMap
extends java.lang.Object

Author:
Ninghui Li, Sandra Qiu
OrderedMap maintains a map from key to values and the ordering of the keys.

Field Summary
private  java.util.HashMap dataMap
          map for the key-value pairs
private static int DEFAULT_SIZE
          defualt map capacity
private  boolean editable
          whether this map is editable
private  java.lang.Class keyClass
          key type
private  java.util.ArrayList keyList
          also stores the keys as they are added to the list, so that we can remember the ordering of the keys.
private  java.lang.Class valueClass
          value type
 
Constructor Summary
OrderedMap()
          Constructor for OrderedMap.
OrderedMap(java.lang.Class keyClass, java.lang.Class valueClass)
          Constructor for OrderedMap.
OrderedMap(int size)
          Constructor for OrderedMap.
OrderedMap(int size, java.lang.Class keyClass, java.lang.Class valueClass)
          Constructor for OrderedMap.
 
Method Summary
 boolean constainsKey(java.lang.Object key)
          Method constainsKey.
 java.lang.Object get(java.lang.Object key)
          Returns the value for the given key and returns null if there is no mapping for the given key .
 java.lang.Class getKeyClass()
          Returns the key type.
 java.lang.Class getValueClass()
          Returns the value type
 boolean isEditable()
          Returns true if the map is editable.
 java.util.Iterator keyIterator()
          Returns iterator to the list of keys in the map.
 java.util.List keyList()
          Returns an unmodifiable view of all the keys.
private  void myPut(java.lang.Object key, java.lang.Object value)
           
 void put(java.lang.Object key, java.lang.Object value)
          Method put.
 void putAll(OrderedMap map)
          Copies all the mapping entries to this map, perserving the original ordering of the entries.
 void setUneditable()
          marks this map as uneditable.
 int size()
          Returns the size of this map
 java.util.Map valueMap()
          Returns an unmodifiable view of this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyClass

private java.lang.Class keyClass
key type


valueClass

private java.lang.Class valueClass
value type


dataMap

private java.util.HashMap dataMap
map for the key-value pairs


keyList

private java.util.ArrayList keyList
also stores the keys as they are added to the list, so that we can remember the ordering of the keys.


editable

private boolean editable
whether this map is editable


DEFAULT_SIZE

private static final int DEFAULT_SIZE
defualt map capacity

See Also:
Constant Field Values
Constructor Detail

OrderedMap

public OrderedMap()
Constructor for OrderedMap. Constructs a OrderedMap object with size default to 10. Both key and value are of Object type.


OrderedMap

public OrderedMap(int size)
Constructor for OrderedMap. Constructs a OrderedMap object with given size. Both key and value are of Object type.


OrderedMap

public OrderedMap(java.lang.Class keyClass,
                  java.lang.Class valueClass)
Constructor for OrderedMap. Constructs a OrderedMap object with size default to 10. The key and value type are specified by the given keyClass and valueClass, respectively.


OrderedMap

public OrderedMap(int size,
                  java.lang.Class keyClass,
                  java.lang.Class valueClass)
Constructor for OrderedMap. Constructs a OrderedMap object with given size. The key and value type are specified by the given keyClass and valueClass, respectively.

Method Detail

constainsKey

public boolean constainsKey(java.lang.Object key)
Method constainsKey. Returns true if there is a mapping for the given key.

Parameters:
key -
Returns:
boolean

put

public void put(java.lang.Object key,
                java.lang.Object value)
         throws DomainSpecException
Method put. Add a new key-value mapping entry to the map. Exception is thrown if the map is not editable, the key is null, or the given key or value's type does not match the specified key type or value type. Exception will also be thrown if trying to add duplicated key-value pair.

Parameters:
key -
value -
Throws:
DomainSpecException

myPut

private void myPut(java.lang.Object key,
                   java.lang.Object value)
            throws DomainSpecException
DomainSpecException

putAll

public void putAll(OrderedMap map)
            throws DomainSpecException
Copies all the mapping entries to this map, perserving the original ordering of the entries. Exception is thrown when the key type or value type of the given map does not match that of this map, or when duplicated entries are detected.

DomainSpecException

setUneditable

public void setUneditable()
marks this map as uneditable.


isEditable

public boolean isEditable()
Returns true if the map is editable.


size

public int size()
Returns the size of this map


keyIterator

public java.util.Iterator keyIterator()
Returns iterator to the list of keys in the map.


get

public java.lang.Object get(java.lang.Object key)
                     throws DomainSpecException
Returns the value for the given key and returns null if there is no mapping for the given key . Exception is thrown when the type of given key does not match the specified key type of this map.

DomainSpecException

keyList

public java.util.List keyList()
Returns an unmodifiable view of all the keys.


valueMap

public java.util.Map valueMap()
Returns an unmodifiable view of this map.


getKeyClass

public java.lang.Class getKeyClass()
Returns the key type.


getValueClass

public java.lang.Class getValueClass()
Returns the value type