Package org.eclipse.gef.common.adapt
Class AdapterKey<T>
- java.lang.Object
-
- org.eclipse.gef.common.adapt.AdapterKey<T>
-
- Type Parameters:
T
- The type parameter corresponding to the type parameter of theClass
used as key (getKey()
).
- All Implemented Interfaces:
java.lang.Comparable<AdapterKey<T>>
public class AdapterKey<T> extends java.lang.Object implements java.lang.Comparable<AdapterKey<T>>
A pair ofClass
key andString
role to register adapters at and retrieve them fromIAdaptable
s. Using anAdapterKey
instead of just aClass
orTypeToken
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 certainClass
orTypeToken
key, theDEFAULT_ROLE
may be used.Creating
AdapterKey
s is supported byget(Class, String)
andget(TypeToken, String)
, as well asget(Class)
andget(TypeToken)
respectively, where the latter two will use theDEFAULT_ROLE
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_ROLE
A default role to be used forAdapterKey
s.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(AdapterKey<T> o)
static AdapterKey<?>
defaultRole()
Returns anAdapterKey
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(TypeToken<T> key)
Creates a newAdapterKey
for the given type key and theDEFAULT_ROLE
role, which can be used to retrieve an adapter from an IAdaptable.static <T> AdapterKey<T>
get(TypeToken<T> key, java.lang.String role)
Creates a newAdapterKey
for the given key and role, which can be used to retrieve an adapter from an IAdaptable.static <T> AdapterKey<T>
get(java.lang.Class<T> key)
Creates a newAdapterKey
for the given raw type key and theDEFAULT_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 newAdapterKey
for the given key and role.TypeToken<T>
getKey()
Returns the key used by thisAdapterKey
.java.lang.String
getRole()
Returns the role used by thisAdapterKey
.int
hashCode()
static AdapterKey<?>
role(java.lang.String role)
Returns anAdapterKey
with no type key and the given role, which can only be used in adapter map bindings.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_ROLE
public static final java.lang.String DEFAULT_ROLE
A default role to be used forAdapterKey
s.- See Also:
get(Class)
, Constant Field Values
-
-
Method Detail
-
defaultRole
public static AdapterKey<?> defaultRole()
Returns anAdapterKey
with no type key and the 'default' role, which can only be used in adapter map bindings. SeeAdapterMaps
.- Returns:
- An AdapterKey without type key, using the 'default' role.
-
get
public static <T> AdapterKey<T> get(java.lang.Class<T> key)
Creates a newAdapterKey
for the given raw type key and theDEFAULT_ROLE
role, which can be used to retrieve an adapter from an IAdaptable.- Type Parameters:
T
- The adapter type.- Parameters:
key
- The key to use for the newly createdAdapterKey
. May not benull
.- Returns:
- A new
AdapterKey
for the given key and role. - See Also:
get(Class, String)
-
get
public static <T> AdapterKey<T> get(java.lang.Class<T> key, java.lang.String role)
Creates a newAdapterKey
for the given key and role.- Type Parameters:
T
- The adapter type.- Parameters:
key
- The key to use for the newly createdAdapterKey
. May not benull
.role
- The role to use for the newly createdAdapterKey
. May not benull
.- Returns:
- A new
AdapterKey
for the given key and role.
-
get
public static <T> AdapterKey<T> get(TypeToken<T> key)
Creates a newAdapterKey
for the given type key and theDEFAULT_ROLE
role, which can be used to retrieve an adapter from an IAdaptable.- Type Parameters:
T
- The adapter type.- Parameters:
key
- The key to use for the newly createdAdapterKey
. May not benull
.- Returns:
- A new
AdapterKey
for the given key and role. - See Also:
get(TypeToken, String)
-
get
public static <T> AdapterKey<T> get(TypeToken<T> key, java.lang.String role)
Creates a newAdapterKey
for the given key and role, which can be used to retrieve an adapter from an IAdaptable.- Type Parameters:
T
- The adapter type.- Parameters:
key
- The key to use for the newly createdAdapterKey
. May not benull
.role
- The role to use for the newly createdAdapterKey
. May not benull
.- Returns:
- A new
AdapterKey
for the given key and role.
-
role
public static AdapterKey<?> role(java.lang.String role)
Returns anAdapterKey
with no type key and the given role, which can only be used in adapter map bindings. SeeAdapterMaps
.- Parameters:
role
- The role to use.- Returns:
- An AdapterKey without type key, using the given role.
-
compareTo
public int compareTo(AdapterKey<T> o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<T>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getKey
public TypeToken<T> getKey()
Returns the key used by thisAdapterKey
.- Returns:
- The key being used.
-
getRole
public java.lang.String getRole()
Returns the role used by thisAdapterKey
.- Returns:
- The role being used.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-