Skip to content

Adding, getting and removing attributes

Elliot Ford edited this page Apr 7, 2015 · 11 revisions

What is an AttributeContainer?

An AttributeContainer (API docs) is a store for attributes. An Entity is an AttributeContainer although the container is useful on its own. JALSE offers a default implementation of AttributeContainer, DefaultAttributeContainer, which can also be used to create your own Entity implementation.

AttributeContainer container = new DefaultAttributeContainer();

AttributeContainer uses a attribute name with an AttributeType or NamedAttributeType for a unique key (see Creating an AttributeType). When attributes are added, changed or move they trigger listener events (see Creating an AttributeListener).

Adding attributes

Adding an attribute assigns a value to the name and type key. This will replace the previously associated value.

String previous = container.addAttribute("username", Attributes.STRING_TYPE, "Ellzord");

or

Optional<String> optPrevious = container.addOptAttribute("username", Attributes.STRING_TYPE, "Ellzord");

There are NamedAttributeType equivalents: container.addAttribute(NamedAttributeType, Object) and container.addOptAttribute(NamedAttributeType, Object).

Getting attributes

Removing attributes

Using multiple attributes

Clone this wiki locally