org.javasimon
Class AttributesSupport

java.lang.Object
  extended by org.javasimon.AttributesSupport
All Implemented Interfaces:
HasAttributes

final class AttributesSupport
extends Object
implements HasAttributes

Attributes implementation that creates attributes map lazily. Is synchronized to ensure thread-safety.

Since:
3.4
Author:
Richard "Virgo" Richter

Field Summary
private  Map<String,Object> attributes
           
 
Constructor Summary
AttributesSupport()
           
 
Method Summary
 Object getAttribute(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
<T> T
getAttribute(String name, Class<T> clazz)
          Returns the value of the named attribute typed to the specified class, or null if no attribute of the given name exists.
 Iterator<String> getAttributeNames()
          Returns an Iterator containing the names of the attributes available to this Simon.
 Map<String,Object> getCopyAsSortedMap()
          Returns copy of attributes as a sorted map, this can be used further for operations like toString.
 void removeAttribute(String name)
          Removes an attribute from this Simon.
 void setAttribute(String name, Object value)
          Stores an attribute in this Simon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

private Map<String,Object> attributes
Constructor Detail

AttributesSupport

AttributesSupport()
Method Detail

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: HasAttributes
Stores an attribute in this Simon. Attributes can be used to store any custom objects.

Specified by:
setAttribute in interface HasAttributes
Parameters:
name - a String specifying the name of the attribute
value - the Object to be stored

getAttribute

public Object getAttribute(String name)
Description copied from interface: HasAttributes
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Specified by:
getAttribute in interface HasAttributes
Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

getAttribute

public <T> T getAttribute(String name,
                          Class<T> clazz)
Description copied from interface: HasAttributes
Returns the value of the named attribute typed to the specified class, or null if no attribute of the given name exists.

Specified by:
getAttribute in interface HasAttributes
Parameters:
name - a String specifying the name of the attribute
Returns:
the value of the attribute typed to T, or null if the attribute does not exist

removeAttribute

public void removeAttribute(String name)
Description copied from interface: HasAttributes
Removes an attribute from this Simon.

Specified by:
removeAttribute in interface HasAttributes
Parameters:
name - a String specifying the name of the attribute to remove

getAttributeNames

public Iterator<String> getAttributeNames()
Description copied from interface: HasAttributes
Returns an Iterator containing the names of the attributes available to this Simon. This method returns an empty Iterator if the Simon has no attributes available to it.

Specified by:
getAttributeNames in interface HasAttributes
Returns:
an Iterator of strings containing the names of the Simon's attributes

getCopyAsSortedMap

public Map<String,Object> getCopyAsSortedMap()
Description copied from interface: HasAttributes
Returns copy of attributes as a sorted map, this can be used further for operations like toString.

Specified by:
getCopyAsSortedMap in interface HasAttributes
Returns:
copy of attributes as a sorted map


Copyright © 2013. All Rights Reserved.