org.glassfish.grizzly.attributes
Class Attribute<T>

java.lang.Object
  extended by org.glassfish.grizzly.attributes.Attribute<T>

public final class Attribute<T>
extends java.lang.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 compile time. 2) Access to Attribute value, if used with IndexedAttributeHolder, could be as fast as access to array.


Constructor Summary
protected Attribute(AttributeBuilder builder, java.lang.String name, int index, NullaryFunction<T> initializer)
           
protected Attribute(AttributeBuilder builder, java.lang.String name, int index, 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.
 java.lang.String name()
          Return attribute name, which is used as attribute key on non-indexed AttributeHolders.
 T peek(AttributeHolder attributeHolder)
          Get attribute value, stored on the AttributeHolder, the difference from get(org.glassfish.grizzly.attributes.AttributeHolder) is that default value or NullaryFunction won't be invoked.
 T peek(AttributeStorage storage)
          Get attribute value, stored on the AttributeStorage, the difference from get(AttributeStorage) is that default value or NullaryFunction won't be invoked.
 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.
 java.lang.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,
                    java.lang.String name,
                    int index,
                    T defaultValue)

Attribute

protected Attribute(AttributeBuilder builder,
                    java.lang.String name,
                    int index,
                    NullaryFunction<T> initializer)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

peek

public T peek(AttributeHolder attributeHolder)
Get attribute value, stored on the AttributeHolder, the difference from get(org.glassfish.grizzly.attributes.AttributeHolder) is that default value or NullaryFunction won't be invoked.

Parameters:
attributeHolder - AttributeHolder.
Returns:
attribute value

peek

public T peek(AttributeStorage storage)
Get attribute value, stored on the AttributeStorage, the difference from get(AttributeStorage) is that default value or NullaryFunction won't be invoked.

Parameters:
storage - AttributeStorage.
Returns:
attribute value

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


Copyright © 2011 Oracle Corpration. All Rights Reserved.