Package com.vaadin.server
Class KeyMapper<V>
- java.lang.Object
-
- com.vaadin.server.KeyMapper<V>
-
- All Implemented Interfaces:
DataKeyMapper<V>,Serializable
public class KeyMapper<V> extends Object implements DataKeyMapper<V>
KeyMapperis the simple two-way map for generating textual keys for objects and retrieving the objects later with the key.- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description KeyMapper()Constructs a new mapper with trivialidentifierGetter.KeyMapper(ValueProvider<V,Object> identifierGetter)Constructs a new mapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(String key)Checks if the given key is mapped to an object.protected StringcreateKey()Creates a key for a new item.Vget(String key)Retrieves object with the key.booleanhas(V o)Check whether this key mapper contains the given data object.Stringkey(V o)Gets key for an object.voidmerge(Set<V> objects)Merge Objects into the mapper.voidrefresh(V dataObject)Updates any existing mappings of given data object.voidremove(V removeobj)Removes object from the mapper.voidremoveAll()Removes all objects from the mapper.voidsetIdentifierGetter(ValueProvider<V,Object> identifierGetter)Takes identifier getter into use and updates existing mappings.
-
-
-
Constructor Detail
-
KeyMapper
public KeyMapper(ValueProvider<V,Object> identifierGetter)
Constructs a new mapper.- Parameters:
identifierGetter- has to return a unique key for every bean, and the returned key has to follow generalhashCode()andequals()contract, seeObject.hashCode()for details.- Since:
- 8.1
-
KeyMapper
public KeyMapper()
Constructs a new mapper with trivialidentifierGetter.
-
-
Method Detail
-
key
public String key(V o)
Gets key for an object.- Specified by:
keyin interfaceDataKeyMapper<V>- Parameters:
o- the object.- Returns:
- key for given data object
-
createKey
protected String createKey()
Creates a key for a new item.This method can be overridden to customize the keys used.
- Returns:
- new key
- Since:
- 8.1.2
-
has
public boolean has(V o)
Description copied from interface:DataKeyMapperCheck whether this key mapper contains the given data object.- Specified by:
hasin interfaceDataKeyMapper<V>- Parameters:
o- the data object to check- Returns:
trueif the given data object is contained in this key mapper,falseotherwise
-
get
public V get(String key)
Retrieves object with the key.- Specified by:
getin interfaceDataKeyMapper<V>- Parameters:
key- the name with the desired value.- Returns:
- the object with the key.
-
remove
public void remove(V removeobj)
Removes object from the mapper.- Specified by:
removein interfaceDataKeyMapper<V>- Parameters:
removeobj- the object to be removed.
-
removeAll
public void removeAll()
Removes all objects from the mapper.- Specified by:
removeAllin interfaceDataKeyMapper<V>
-
merge
public void merge(Set<V> objects)
Merge Objects into the mapper.This method will add the new objects to the mapper and remove inactive objects from it.
- Parameters:
objects- new objects set needs to be merged.- Since:
- 8.7
-
containsKey
public boolean containsKey(String key)
Checks if the given key is mapped to an object.- Parameters:
key- the key to check- Returns:
trueif the key is currently mapped,falseotherwise- Since:
- 7.7
-
refresh
public void refresh(V dataObject)
Description copied from interface:DataKeyMapperUpdates any existing mappings of given data object. The equality of two data objects is determined by the equality of their identifiers provided by the given value provider.- Specified by:
refreshin interfaceDataKeyMapper<V>- Parameters:
dataObject- the data object to update
-
setIdentifierGetter
public void setIdentifierGetter(ValueProvider<V,Object> identifierGetter)
Description copied from interface:DataKeyMapperTakes identifier getter into use and updates existing mappings.- Specified by:
setIdentifierGetterin interfaceDataKeyMapper<V>- Parameters:
identifierGetter- has to return a unique key for every bean, and the returned key has to follow generalhashCode()andequals()contract, seeObject.hashCode()for details.
-
-