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 onAttributeHolderinstances. Storing attribute values inAttributeHolderhas 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 protectedAttribute(AttributeBuilder builder, String name, int index, NullaryFunction<T> initializer)protectedAttribute(AttributeBuilder builder, String name, int index, T defaultValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget(AttributeHolder attributeHolder)Get attribute value, stored on theAttributeHolder.Tget(AttributeStorage storage)Get attribute value, stored on theAttributeStorage.intindex()Return attribute name, which is used as attribute key on indexedAttributeHolders.booleanisSet(AttributeHolder attributeHolder)Checks if this attribute is set on theAttributeHolder.booleanisSet(AttributeStorage storage)Checks if this attribute is set on theAttributeStorage.Stringname()Return attribute name, which is used as attribute key on non-indexedAttributeHolders.Tpeek(AttributeHolder attributeHolder)Get attribute value, stored on theAttributeHolder, the difference fromget(org.glassfish.grizzly.attributes.AttributeHolder)is that default value orNullaryFunctionwon't be invoked.Tpeek(AttributeStorage storage)Get attribute value, stored on theAttributeStorage, the difference fromget(AttributeStorage)is that default value orNullaryFunctionwon't be invoked.Tremove(AttributeHolder attributeHolder)Remove attribute value, stored on theAttributeHolder.Tremove(AttributeStorage storage)Remove attribute value, stored on theAttributeStorage.voidset(AttributeHolder attributeHolder, T value)Set attribute value, stored on theAttributeHolder.voidset(AttributeStorage storage, T value)Set attribute value, stored on theAttributeStorage.StringtoString()
-
-
-
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 orNullaryFunctionwon'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 orNullaryFunctionwon'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-indexedAttributeHolders.- Returns:
- attribute name.
-
index
public int index()
Return attribute name, which is used as attribute key on indexedAttributeHolders.- Returns:
- attribute indexed.
-
-