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 the `Class` used as key (`getKey()`).

All Implemented Interfaces:
  `Comparable<AdapterKey<T>>`

public class AdapterKey<T> extends Object implements Comparable<AdapterKey<T>>
A pair of `Class` key and `String` role to register adapters at and retrieve them from `IAdaptable`s. 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 `AdapterKey`s 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`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_ROLE`
A default role to be used for `AdapterKey`s.

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(AdapterKey<T> o)`
`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(Object obj)`
`static <T> AdapterKey<T>`
`get(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(TypeToken<T> key, String role)`
Creates a new `AdapterKey` for the given key and role, which can be used to retrieve an adapter from an IAdaptable.
`static <T> AdapterKey<T>`
`get(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(Class<T> key, String role)`
Creates a new `AdapterKey` for the given key and role.
`TypeToken<T>`
`getKey()`
Returns the key used by this `AdapterKey`.
`String`
`getRole()`
Returns the role used by this `AdapterKey`.
`int`
`hashCode()`
`static AdapterKey<?>`
`role(String role)`
Returns an `AdapterKey` with no type key and the given role, which can only be used in adapter map bindings.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### DEFAULT_ROLE

public static final String DEFAULT_ROLE
A default role to be used for `AdapterKey`s.

See Also:
  - `get(Class)`
  - Constant Field Values

## Method Details

### defaultRole

public static AdapterKey<?> defaultRole()
Returns an `AdapterKey` with no type key and the 'default' role, which can only be used in adapter map bindings. See `AdapterMaps`.

Returns:
  An AdapterKey without type key, using the 'default' role.

### get

public static <T> AdapterKey<T> get(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.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The key to use for the newly created `AdapterKey`. May not be `null`.
Returns:
  A new `AdapterKey` for the given key and role.
See Also:
  - `get(Class, String)`

### get

public static <T> AdapterKey<T> get(Class<T> key, String role)
Creates a new `AdapterKey` for the given key and role.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `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`.
Returns:
  A new `AdapterKey` for the given key and role.

### get

public static <T> AdapterKey<T> get(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.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The key to use for the newly created `AdapterKey`. May not be `null`.
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, String role)
Creates a new `AdapterKey` 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 created `AdapterKey`. May not be `null`.
  `role` - The role to use for the newly created `AdapterKey`. May not be `null`.
Returns:
  A new `AdapterKey` for the given key and role.

### role

public static AdapterKey<?> role(String role)
Returns an `AdapterKey` with no type key and the given role, which can only be used in adapter map bindings. See `AdapterMaps`.

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 interface `Comparable<T>`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

### getKey

public TypeToken<T> getKey()
Returns the key used by this `AdapterKey`.

Returns:
  The key being used.

### getRole

public String getRole()
Returns the role used by this `AdapterKey`.

Returns:
  The role being used.

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`