T - Indicates the data type of the item (key) that the unique id is mapped to.public class UidKeyTranslator<T> extends Object
Uid to user-defined objects and 'translate'
from one to the other format. This is useful when an application uses unique ids that require
different data types in certain contexts. Use the addToDictionary(Map) method to add
specifications for this format to the translator's dictionary.| Modifier and Type | Field and Description |
|---|---|
protected Map<Uid,T> |
dictionary
A map of unique ids to a user-defined data type.
|
| Constructor and Description |
|---|
UidKeyTranslator()
Creates a new instance.
|
UidKeyTranslator(Map<Uid,T> map)
Creates a new instance, calling
addToDictionary(Map) for the provided map. |
| Modifier and Type | Method and Description |
|---|---|
void |
addToDictionary(Map<Uid,T> map)
Adds a UID-key map to the dictionary.
|
T |
fromUid(Uid uid)
Returns the key that is mapped to this unique id.
|
Map<T,?> |
fromUidMap(Map<Uid,?> map)
Accepts a map of unique ids to values and returns a new map which replaces the unique ids
with the keys from the dictionary.
|
String |
toString() |
Uid |
toUid(T key)
Returns the unique id that is mapped to this key.
|
Map<Uid,?> |
toUidMap(Map<T,Object> map)
Accepts a map of keys to values and returns a new map which replaces the keys with the unique
ids from the dictionary.
|
public UidKeyTranslator()
public UidKeyTranslator(Map<Uid,T> map) throws UidKeyTranslatorException
addToDictionary(Map) for the provided map.map - The values to add to the dictionary.UidKeyTranslatorException - when the map contains invalid keys or values.public void addToDictionary(Map<Uid,T> map) throws UidKeyTranslatorException
map - The values to add to the dictionary.UidKeyTranslatorException - when the map contains invalid keys or values.public T fromUid(Uid uid) throws UidKeyTranslatorException
uid - The uid to translate.UidKeyTranslatorException - when the provided uid is not in the dictionary.public Map<T,?> fromUidMap(Map<Uid,?> map) throws UidKeyTranslatorException
map - Map of Uid -> value.UidKeyTranslatorException - when a provided uid is not in the dictionary.public Uid toUid(T key) throws UidKeyTranslatorException
key - The key to translate to Uid.UidKeyTranslatorException - when the provided key is not in the dictionary.public Map<Uid,?> toUidMap(Map<T,Object> map) throws UidKeyTranslatorException
map - Map of Key -> value.UidKeyTranslatorException - when the provided key is not in the dictionary.Copyright © 2015 Cooking Fox. All rights reserved.