T - The type parameter corresponding to the type parameter of the
Class used as key (getKey()).public class AdapterKey<T>
extends java.lang.Object
Class key and String role to register adapters at
and retrieve them from IAdaptables. Using an AdapterKey
instead of just a Class or TypeToken key allows to register
several adapters under the same key, serving different roles. Nevertheless,
adapters can still be accessed in a type-safe manner. To register a default
adapter for a certain Class or TypeToken key, the
DEFAULT_ROLE may be used.
Creating AdapterKeys is supported by get(Class, String) and
get(TypeToken, String), as well as get(Class) and
get(TypeToken) respectively, where the latter two will use the
DEFAULT_ROLE.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_ROLE
A default role to be used for
AdapterKeys. |
| Modifier and Type | Method and Description |
|---|---|
static AdapterKey<?> |
defaultRole()
Returns an
AdapterKey with no type key and the 'default' role,
which can only be used in adapter map bindings. |
boolean |
equals(java.lang.Object obj) |
static <T> AdapterKey<T> |
get(java.lang.Class<T> key)
Creates a new
AdapterKey for the given raw type key and the
DEFAULT_ROLE role, which can be used to retrieve an adapter from
an IAdaptable. |
static <T> AdapterKey<T> |
get(java.lang.Class<T> key,
java.lang.String role)
Creates a new
AdapterKey for the given key and role. |
static <T> AdapterKey<T> |
get(com.google.common.reflect.TypeToken<T> key)
Creates a new
AdapterKey for the given type key and the
DEFAULT_ROLE role, which can be used to retrieve an adapter from
an IAdaptable. |
static <T> AdapterKey<T> |
get(com.google.common.reflect.TypeToken<T> key,
java.lang.String role)
Creates a new
AdapterKey for the given key and role, which can be
used to retrieve an adapter from an IAdaptable. |
com.google.common.reflect.TypeToken<T> |
getKey()
Returns the key used by this
AdapterKey. |
java.lang.String |
getRole()
Returns the role used by this
AdapterKey. |
int |
hashCode() |
static AdapterKey<?> |
role(java.lang.String role)
Returns an
AdapterKey with no type key and the given role, which
can only be used in adapter map bindings. |
java.lang.String |
toString() |
public static final java.lang.String DEFAULT_ROLE
AdapterKeys.get(Class),
Constant Field Valuespublic com.google.common.reflect.TypeToken<T> getKey()
AdapterKey.public java.lang.String getRole()
AdapterKey.public static <T> AdapterKey<T> get(java.lang.Class<T> key, java.lang.String role)
AdapterKey for the given key and role.T - The adapter type.key - The key to use for the newly created AdapterKey. May
not be null.role - The role to use for the newly created AdapterKey. May
not be null.AdapterKey for the given key and role.public static <T> AdapterKey<T> get(com.google.common.reflect.TypeToken<T> key, java.lang.String role)
AdapterKey for the given key and role, which can be
used to retrieve an adapter from an IAdaptable.T - The adapter type.key - The key to use for the newly created AdapterKey. May
not be null.role - The role to use for the newly created AdapterKey. May
not be null.AdapterKey for the given key and role.public static <T> AdapterKey<T> get(java.lang.Class<T> key)
AdapterKey for the given raw type key and the
DEFAULT_ROLE role, which can be used to retrieve an adapter from
an IAdaptable.T - The adapter type.key - The key to use for the newly created AdapterKey. May
not be null.AdapterKey for the given key and role.get(Class, String)public static <T> AdapterKey<T> get(com.google.common.reflect.TypeToken<T> key)
AdapterKey for the given type key and the
DEFAULT_ROLE role, which can be used to retrieve an adapter from
an IAdaptable.T - The adapter type.key - The key to use for the newly created AdapterKey. May
not be null.AdapterKey for the given key and role.get(TypeToken, String)public static AdapterKey<?> defaultRole()
AdapterKey with no type key and the 'default' role,
which can only be used in adapter map bindings. See AdapterMap.public static AdapterKey<?> role(java.lang.String role)
AdapterKey with no type key and the given role, which
can only be used in adapter map bindings. See AdapterMap.role - The role to use.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright (c) 2014 itemis AG and others. All rights reserved.