org.javasimon
Interface HasAttributes

All Known Subinterfaces:
Counter, Simon, Stopwatch
All Known Implementing Classes:
AbstractSimon, AttributesSupport, CounterImpl, NullCounter, NullSimon, NullStopwatch, Split, StopwatchImpl, UnknownSimon

public interface HasAttributes

Interface that declares support for arbitrary attributes that can be attached to the object (servlet style).

Since:
3.4
Author:
Richard "Virgo" Richter

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.
 

Method Detail

setAttribute

void setAttribute(String name,
                  Object value)
Stores an attribute in this Simon. Attributes can be used to store any custom objects.

Parameters:
name - a String specifying the name of the attribute
value - the Object to be stored

getAttribute

Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

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

removeAttribute

void removeAttribute(String name)
Removes an attribute from this Simon.

Parameters:
name - a String specifying the name of the attribute to remove

getAttributeNames

Iterator<String> getAttributeNames()
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.

Returns:
an Iterator of strings containing the names of the Simon's attributes

getCopyAsSortedMap

Map<String,Object> getCopyAsSortedMap()
Returns copy of attributes as a sorted map, this can be used further for operations like toString.

Returns:
copy of attributes as a sorted map

getAttribute

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

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
Since:
3.4


Copyright © 2013. All Rights Reserved.