Package org.glassfish.grizzly.attributes
Class Attribute<T>
- java.lang.Object
-
- org.glassfish.grizzly.attributes.Attribute<T>
-
- Type Parameters:
T
-
public final class Attribute<T> extends Object
Class used to define dynamic typed attributes onAttributeHolder
instances. Storing attribute values inAttributeHolder
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 withIndexedAttributeHolder
, could be as fast as access to array.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Attribute(AttributeBuilder builder, String name, int index, NullaryFunction<T> initializer)
protected
Attribute(AttributeBuilder builder, String name, int index, T defaultValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
get(AttributeHolder attributeHolder)
Get attribute value, stored on theAttributeHolder
.T
get(AttributeStorage storage)
Get attribute value, stored on theAttributeStorage
.int
index()
Return attribute name, which is used as attribute key on indexedAttributeHolder
s.boolean
isSet(AttributeHolder attributeHolder)
Checks if this attribute is set on theAttributeHolder
.boolean
isSet(AttributeStorage storage)
Checks if this attribute is set on theAttributeStorage
.String
name()
Return attribute name, which is used as attribute key on non-indexedAttributeHolder
s.T
peek(AttributeHolder attributeHolder)
Get attribute value, stored on theAttributeHolder
, the difference fromget(org.glassfish.grizzly.attributes.AttributeHolder)
is that default value orNullaryFunction
won't be invoked.T
peek(AttributeStorage storage)
Get attribute value, stored on theAttributeStorage
, the difference fromget(AttributeStorage)
is that default value orNullaryFunction
won't be invoked.T
remove(AttributeHolder attributeHolder)
Remove attribute value, stored on theAttributeHolder
.T
remove(AttributeStorage storage)
Remove attribute value, stored on theAttributeStorage
.void
set(AttributeHolder attributeHolder, T value)
Set attribute value, stored on theAttributeHolder
.void
set(AttributeStorage storage, T value)
Set attribute value, stored on theAttributeStorage
.String
toString()
-
-
-
Constructor Detail
-
Attribute
protected Attribute(AttributeBuilder builder, String name, int index, T defaultValue)
-
Attribute
protected Attribute(AttributeBuilder builder, String name, int index, NullaryFunction<T> initializer)
-
-
Method Detail
-
peek
public T peek(AttributeHolder attributeHolder)
Get attribute value, stored on theAttributeHolder
, the difference fromget(org.glassfish.grizzly.attributes.AttributeHolder)
is that default value orNullaryFunction
won't be invoked.- Parameters:
attributeHolder
-AttributeHolder
.- Returns:
- attribute value
-
peek
public T peek(AttributeStorage storage)
Get attribute value, stored on theAttributeStorage
, the difference fromget(AttributeStorage)
is that default value orNullaryFunction
won't be invoked.- Parameters:
storage
-AttributeStorage
.- Returns:
- attribute value
-
get
public T get(AttributeHolder attributeHolder)
Get attribute value, stored on theAttributeHolder
.- Parameters:
attributeHolder
-AttributeHolder
.- Returns:
- attribute value
-
get
public T get(AttributeStorage storage)
Get attribute value, stored on theAttributeStorage
.- Parameters:
storage
-AttributeStorage
.- Returns:
- attribute value
-
set
public void set(AttributeHolder attributeHolder, T value)
Set attribute value, stored on theAttributeHolder
.- Parameters:
attributeHolder
-AttributeHolder
.value
- attribute value to set.
-
set
public void set(AttributeStorage storage, T value)
Set attribute value, stored on theAttributeStorage
.- Parameters:
storage
-AttributeStorage
.value
- attribute value to set.
-
remove
public T remove(AttributeHolder attributeHolder)
Remove attribute value, stored on theAttributeHolder
.- Parameters:
attributeHolder
-AttributeHolder
.- Returns:
- the previous value associated with the attribute
-
remove
public T remove(AttributeStorage storage)
Remove attribute value, stored on theAttributeStorage
.- Parameters:
storage
-AttributeStorage
.
-
isSet
public boolean isSet(AttributeHolder attributeHolder)
Checks if this attribute is set on theAttributeHolder
. 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 theAttributeStorage
. 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-indexedAttributeHolder
s.- Returns:
- attribute name.
-
index
public int index()
Return attribute name, which is used as attribute key on indexedAttributeHolder
s.- Returns:
- attribute indexed.
-
-