com.sun.grizzly.attributes
Class Attribute<T>

java.lang.Object
  extended by com.sun.grizzly.attributes.Attribute<T>

public class Attribute<T>
extends Object

Class used to define dynamic typed attributes on AttributeHolder instances. Storing attribute values in AttributeHolder has two advantage comparing to Map storage: 1) Attribute value is typed, and could be checked at compiletime. 2) Access to Attribute value, if used with IndexedAttributeHolder, could be as fast as access to array.


Constructor Summary
protected Attribute(AttributeBuilder builder, String name, NullaryFunction<T> initializer)
           
protected Attribute(AttributeBuilder builder, String name, T defaultValue)
           
 
Method Summary
 T get(AttributeHolder attributeHolder)
          Get attribute value, stored on the AttributeHolder.
 T get(AttributeStorage storage)
          Get attribute value, stored on the AttributeStorage.
 int index()
          Return attribute name, which is used as attribute key on indexed AttributeHolders.
 boolean isSet(AttributeHolder attributeHolder)
          Checks if this attribute is set on the AttributeHolder.
 boolean isSet(AttributeStorage storage)
          Checks if this attribute is set on the AttributeStorage.
 String name()
          Return attribute name, which is used as attribute key on non-indexed AttributeHolders.
 T remove(AttributeHolder attributeHolder)
          Remove attribute value, stored on the AttributeHolder.
 T remove(AttributeStorage storage)
          Remove attribute value, stored on the AttributeStorage.
 void set(AttributeHolder attributeHolder, T value)
          Set attribute value, stored on the AttributeHolder.
 void set(AttributeStorage storage, T value)
          Set attribute value, stored on the AttributeStorage.
protected  void setIndex(int index)
          Assign integer index to Attribute, to make access to its value as fast as array[index].
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

protected Attribute(AttributeBuilder builder,
                    String name,
                    T defaultValue)

Attribute

protected Attribute(AttributeBuilder builder,
                    String name,
                    NullaryFunction<T> initializer)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

get

public T get(AttributeHolder attributeHolder)
Get attribute value, stored on the AttributeHolder.

Parameters:
attributeHolder - AttributeHolder.
Returns:
attribute value

get

public T get(AttributeStorage storage)
Get attribute value, stored on the AttributeStorage.

Parameters:
storage - AttributeStorage.
Returns:
attribute value

set

public void set(AttributeHolder attributeHolder,
                T value)
Set attribute value, stored on the AttributeHolder.

Parameters:
attributeHolder - AttributeHolder.
value - attribute value to set.

set

public void set(AttributeStorage storage,
                T value)
Set attribute value, stored on the AttributeStorage.

Parameters:
storage - AttributeStorage.
value - attribute value to set.

remove

public T remove(AttributeHolder attributeHolder)
Remove attribute value, stored on the AttributeHolder.

Parameters:
attributeHolder - AttributeHolder.

remove

public T remove(AttributeStorage storage)
Remove attribute value, stored on the AttributeStorage.

Parameters:
storage - AttributeStorage.

isSet

public boolean isSet(AttributeHolder attributeHolder)
Checks if this attribute is set on the AttributeHolder. Returns true, if attribute is set, of false otherwise.

Parameters:
attributeHolder - AttributeHolder.
Returns:
true, if attribute is set, of false otherwise.

isSet

public boolean isSet(AttributeStorage storage)
Checks if this attribute is set on the AttributeStorage. Returns true, if attribute is set, of false otherwise.

Parameters:
storage - AttributeStorage.
Returns:
true, if attribute is set, of false otherwise.

name

public String name()
Return attribute name, which is used as attribute key on non-indexed AttributeHolders.

Returns:
attribute name.

index

public int index()
Return attribute name, which is used as attribute key on indexed AttributeHolders.

Returns:
attribute indexed.

setIndex

protected void setIndex(int index)
Assign integer index to Attribute, to make access to its value as fast as array[index].

Parameters:
index - attribute index.


Copyright © 2009 SUN Microsystems. All Rights Reserved.