Class SimpleAttributes
- java.lang.Object
-
- com.opengamma.strata.product.SimpleAttributes
-
- All Implemented Interfaces:
Attributes
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class SimpleAttributes extends Object implements Attributes, org.joda.beans.ImmutableBean, Serializable
A simple implementation of attributes.Additional attributes can be associated with a model object. This is the simplest possible implementation.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimpleAttributes
empty()
Obtains an empty instance.boolean
equals(Object obj)
<T> Optional<T>
findAttribute(AttributeType<T> type)
Finds the attribute associated with the specified type.static SimpleAttributes
from(Attributes other)
Obtains an instance from another instance, copying the attributes.ImmutableMap<AttributeType<?>,Object>
getAttributes()
Gets the attributes.ImmutableSet<AttributeType<?>>
getAttributeTypes()
Gets the attribute types that are available.int
hashCode()
static org.joda.beans.TypedMetaBean<SimpleAttributes>
meta()
The meta-bean forSimpleAttributes
.org.joda.beans.TypedMetaBean<SimpleAttributes>
metaBean()
static <T> SimpleAttributes
of(AttributeType<T> type, T value)
Obtains an instance with a single attribute.String
toString()
<T> SimpleAttributes
withAttribute(AttributeType<T> type, T value)
Returns a copy of this instance with the attribute added.SimpleAttributes
withAttributes(Attributes other)
Returns a copy of this instance with the attributes added.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.opengamma.strata.product.Attributes
containsAttribute, containsAttribute, getAttribute
-
-
-
-
Method Detail
-
empty
public static SimpleAttributes empty()
Obtains an empty instance.The
withAttribute(AttributeType, Object)
method can be used on the instance to add attributes.- Returns:
- the empty instance
-
of
public static <T> SimpleAttributes of(AttributeType<T> type, T value)
Obtains an instance with a single attribute.The
withAttribute(AttributeType, Object)
method can be used on the instance to add more attributes.- Type Parameters:
T
- the type of the attribute value- Parameters:
type
- the type providing meaning to the valuevalue
- the value- Returns:
- the instance
-
from
public static SimpleAttributes from(Attributes other)
Obtains an instance from another instance, copying the attributes.This can be used to ensure that an instance of
Attributes
contains no state apart from attributes.- Parameters:
other
- the attributes to copy from- Returns:
- the instance
-
getAttributeTypes
public ImmutableSet<AttributeType<?>> getAttributeTypes()
Description copied from interface:Attributes
Gets the attribute types that are available.See
AttributeType.captureWildcard()
for a way to capture the wildcard type.The default implementation returns an empty set (backwards compatibility prevents an abstract method for now).
- Specified by:
getAttributeTypes
in interfaceAttributes
- Returns:
- the attribute types
-
findAttribute
public <T> Optional<T> findAttribute(AttributeType<T> type)
Description copied from interface:Attributes
Finds the attribute associated with the specified type.This method obtains the specified attribute. This allows an attribute to be obtained if available.
If the attribute is not found, optional empty is returned.
- Specified by:
findAttribute
in interfaceAttributes
- Type Parameters:
T
- the type of the result- Parameters:
type
- the type to find- Returns:
- the attribute value
-
withAttribute
public <T> SimpleAttributes withAttribute(AttributeType<T> type, T value)
Description copied from interface:Attributes
Returns a copy of this instance with the attribute added.This returns a new instance with the specified attribute added. The attribute is added using
Map.put(type, value)
semantics.- Specified by:
withAttribute
in interfaceAttributes
- Type Parameters:
T
- the type of the attribute value- Parameters:
type
- the type providing meaning to the valuevalue
- the value- Returns:
- a new instance based on this one with the attribute added
-
withAttributes
public SimpleAttributes withAttributes(Attributes other)
Description copied from interface:Attributes
Returns a copy of this instance with the attributes added.This returns a new instance with the specified attributes added. The attributes are added using
Map.putAll(type, value)
semantics.- Specified by:
withAttributes
in interfaceAttributes
- Parameters:
other
- the other instance to copy from- Returns:
- an instance based on this one with the attributes from the other instance
-
meta
public static org.joda.beans.TypedMetaBean<SimpleAttributes> meta()
The meta-bean forSimpleAttributes
.- Returns:
- the meta-bean, not null
-
metaBean
public org.joda.beans.TypedMetaBean<SimpleAttributes> metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getAttributes
public ImmutableMap<AttributeType<?>,Object> getAttributes()
Gets the attributes.Attributes provide the ability to associate arbitrary information in a key-value map.
- Returns:
- the value of the property, not null
-
-