K - The type of element this interface accepts as keys for the mapping.V - The type of element this interface accepts as values for the mapping.public interface IMapper<K,V>
IMappers are most prominently used when interfacing with layout algorithms and
GraphML. IGraph also provides the MapperRegistry
to add additional information to a graph.
Using IMapper is described in the section
Associating Data with Graph Elements.
Mappers,
Mapper| Modifier and Type | Method and Description |
|---|---|
static <K,V> IMapper<K,V> |
fromConstant(V constant)
Creates a constant mapper that will always return the
constant. |
static <K,V> IMapper<K,V> |
fromFunction(Function<K,V> getter)
Create an implementation of
IMapper that delegates getValue(java.lang.Object) getter calls to the
provided handler. |
V |
getValue(K key)
Gets the value for a given key in the mapping.
|
void |
setValue(K key,
V value)
Sets the value for a given key in the mapping.
|
static <K,V> IMapper<K,V> fromConstant(V constant)
constant.K - The type of the key to use.V - The type of the value to use.constant - The constant to return in getValue(java.lang.Object)static <K,V> IMapper<K,V> fromFunction(Function<K,V> getter)
IMapper that delegates getValue(java.lang.Object) getter calls to the
provided handler.
The implementation returned silently ignores calls to the getValue(java.lang.Object) setter.
K - The type of the key to use.V - The type of the value to use.getter - The delegate to delegate getValue(java.lang.Object) getter calls to.getter.V getValue(K key)
Setting a value for an already existing key overwrites the previous value.
It depends on the specific implementation of the mapper whether a mapping can be removed. If an implementation provides
a way to remove a mapping, that should be preferred over setting a null value. For example, Mapper
provides the Mapper.removeValue(java.lang.Object) method.
key - The key of the mapping.setValue(java.lang.Object, java.lang.Object)void setValue(K key, V value)
Setting a value for an already existing key overwrites the previous value.
It depends on the specific implementation of the mapper whether a mapping can be removed. If an implementation provides
a way to remove a mapping, that should be preferred over setting a null value. For example, Mapper
provides the Mapper.removeValue(java.lang.Object) method.
key - The key of the mapping.value - The value.getValue(java.lang.Object)