com.vaadin.flow.data.provider.
Class KeyMapper<V>
- java.lang.Object
-
- com.vaadin.flow.data.provider.KeyMapper<V>
-
Type Parameters:
V
- the type of mapped objectsAll Implemented Interfaces:
public class KeyMapper<V> extends Object implements DataKeyMapper<V>
KeyMapper
is the simple two-way map for generating textual keys for objects and retrieving the objects later with the key.Since:
1.0.
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description KeyMapper()
Constructs a new mapper with trivial
identifierGetter
KeyMapper(ValueProvider<V,Object> identifierGetter)
Constructs a new mapper.
-
Method Summary
All Methods Modifier and Type Method and Description boolean
containsKey(String key)
Checks if the given key is mapped to an object.
protected String
createKey()
Creates a key for a new item.
V
get(String key)
Retrieves object with the key.
boolean
has(V o)
Check whether this key mapper contains the given data object.
String
key(V o)
Gets key for an object.
void
refresh(V dataObject)
Updates any existing mappings of given data object.
void
remove(V removeobj)
Removes object from the mapper.
void
removeAll()
Removes all objects from the mapper.
void
setIdentifierGetter(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.
-
KeyMapper
public KeyMapper()
Constructs a new mapper with trivial
identifierGetter
-
-
Method Detail
-
key
public String key(V o)
Gets key for an object.
Specified by:
key
in 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
-
has
public boolean has(V o)
Description copied from interface:
DataKeyMapper
Check whether this key mapper contains the given data object.
Specified by:
has
in interfaceDataKeyMapper<V>
Parameters:
o
- the data object to checkReturns:
true
if the given data object is contained in this key mapper,false
otherwise
-
get
public V get(String key)
Retrieves object with the key.
Specified by:
get
in 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:
remove
in interfaceDataKeyMapper<V>
Parameters:
removeobj
- the object to be removed.
-
removeAll
public void removeAll()
Removes all objects from the mapper.
Specified by:
removeAll
in interfaceDataKeyMapper<V>
-
containsKey
public boolean containsKey(String key)
Checks if the given key is mapped to an object.
Parameters:
key
- the key to checkReturns:
true
if the key is currently mapped,false
otherwise
-
refresh
public void refresh(V dataObject)
Description copied from interface:
DataKeyMapper
Updates 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:
refresh
in interfaceDataKeyMapper<V>
Parameters:
dataObject
- the data object to update
-
setIdentifierGetter
public void setIdentifierGetter(ValueProvider<V,Object> identifierGetter)
Description copied from interface:
DataKeyMapper
Takes identifier getter into use and updates existing mappings
Specified by:
setIdentifierGetter
in 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.
-
-