E
- An Extendable
type where the data is to be storedT
- The type of the data to be storedpublic final class ExtendableAccessor<E extends Extendable,T>
extends java.lang.Object
Extendable
classes.
An instance of ExtendableAccessor
uses itself as the key in the Extendable.attachments()
so it's best instantiated as a static final member.
class Foo extends BaseHandler {
private static ExtendableAccessor<Link, Bar> LINK_BAR = new ExtendableAccessor<>(Bar.class);
void onLinkRemoteOpen(Event e) {
Bar bar = LINK_BAR.get(e.getLink());
if (bar == null) {
bar = new Bar();
LINK_BAR.set(e.getLink(), bar);
}
}
}
Constructor and Description |
---|
ExtendableAccessor(java.lang.Class<T> klass) |
Modifier and Type | Method and Description |
---|---|
T |
get(E e) |
void |
set(E e,
T value) |