org.dasein.attributes
Class AttributeMap

java.lang.Object
  extended by org.dasein.util.PseudoMap<String,Object>
      extended by org.dasein.attributes.AttributeMap
All Implemented Interfaces:
Serializable, Map<String,Object>

public class AttributeMap
extends PseudoMap<String,Object>
implements Serializable

An immutable mapping of attribute names to values. The main value of this class over a straight Map is that it is immutable and that it constrains keys as strings. It is therefore very useful as storage for object attributes so that you may return the full mapping from method calls without doing any copying.

This class was originally developed for the Simplicis Content Management System in 2003 and moved into an Open Source library in 2006.

Last modified: $Date: 2006/05/03 05:12:49 $

Version:
$Revision: 1.3 $
Author:
George Reese
See Also:
Serialized Form

Nested Class Summary
static class AttributeMap.AmapEntry
           
static class AttributeMap.AttributeWrapper<T>
           
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
AttributeMap()
          Constructs an empty attribute map.
AttributeMap(Map<String,? extends Object> map)
          Constructs an attribute map that is copied from the specified mapping.
AttributeMap(Map<String,? extends Object> map1, Map<String,? extends Object> map2)
          Constructs an attribute map that is copied from two different mappings.
 
Method Summary
 Iterator<String> attributes()
           
 boolean containsKey(Object attr)
           
 boolean containsValue(Object val)
           
 Set<Map.Entry<String,Object>> entrySet()
           
 boolean equals(Object ob)
          Compares the selected object.
 Object get(Object attr)
           
 Object getAttribute(String attr)
          Deprecated. this is an old method, not sure why it had to be added
 int hashCode()
           
 boolean isEmpty()
           
 Set<String> keySet()
           
 int size()
           
 String toString()
          Converts this mapping into a human-readable string.
 Collection<Object> values()
           
 
Methods inherited from class org.dasein.util.PseudoMap
clear, put, putAll, remove
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeMap

public AttributeMap()
Constructs an empty attribute map. Note that because this class is immutable, the resulting mapping is forever empty.


AttributeMap

public AttributeMap(Map<String,? extends Object> map)
Constructs an attribute map that is copied from the specified mapping.

Parameters:
map - the mapping to copy

AttributeMap

public AttributeMap(Map<String,? extends Object> map1,
                    Map<String,? extends Object> map2)
Constructs an attribute map that is copied from two different mappings. This constructor is useful when trying to add to an existing mapping. You will generally pass an existing mapping as the first argument and any new values as the second argument.

Parameters:
map1 - the existing mapping values
map2 - the new values you wish to add to the original
Method Detail

attributes

public Iterator<String> attributes()
Returns:
the name of all attributes in this map

containsKey

public boolean containsKey(Object attr)
Specified by:
containsKey in interface Map<String,Object>
Parameters:
attr - the name of the attribute being validated
Returns:
true if the mapping contains the specified attribute

containsValue

public boolean containsValue(Object val)
Specified by:
containsValue in interface Map<String,Object>
Parameters:
val - the name of the value being checked
Returns:
true if the specified value is in this mapping

entrySet

public Set<Map.Entry<String,Object>> entrySet()
Specified by:
entrySet in interface Map<String,Object>
Returns:
a set containing all mapping entries

equals

public boolean equals(Object ob)
Compares the selected object. This attribute map is considered equal to another if and only if they have the same set of keys with the same exact values.

Specified by:
equals in interface Map<String,Object>
Overrides:
equals in class Object

get

public Object get(Object attr)
Specified by:
get in interface Map<String,Object>
Parameters:
attr - the name of the attribute to retrieve
Returns:
any value associated the specified attribute name

getAttribute

public Object getAttribute(String attr)
Deprecated. this is an old method, not sure why it had to be added

This method just calls get(Object).

Parameters:
attr - the name of the desired attribute
Returns:
the value associated with the specified attribute name

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<String,Object>
Overrides:
hashCode in class Object
Returns:
the hash code

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<String,Object>
Returns:
true if this mapping is empty

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,Object>
Returns:
the list of mapping attribute names

size

public int size()
Specified by:
size in interface Map<String,Object>
Returns:
the number of elements in this mapping

values

public Collection<Object> values()
Specified by:
values in interface Map<String,Object>
Returns:
all values in this mapping

toString

public String toString()
Converts this mapping into a human-readable string.

Overrides:
toString in class Object
Returns:
a human-readable string of key-value pairs


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.