Package org.jvnet.basicjaxb.lang
Class ListBackedMap<T,K,V>
java.lang.Object
java.util.AbstractMap<K,V>
org.jvnet.basicjaxb.lang.ListBackedMap<T,K,V>
- Type Parameters:
T- The type of elements in the backing list.K- The type of keys maintained by this map.V- The type of mapped values.Reference: how-to-generate-a-map-backed-by-a-list
- All Implemented Interfaces:
Map<K,V>
A
Map "view" backed by a List of key value objects where
changes to the map are reflected in the underlying list.
Example:
class CustomField
{
String key;
String value;
}
List<CustomField> list = getList();
ListBackedMap<CustomField, String, String> map =
new ListBackedMap<>
(
list,
(key, value) -> new CustomField(key, value),
CustomField::getKey,
CustomField::getValue
);
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
ListBackedMap
public ListBackedMap(List<T> list, BiFunction<K, V, T> keyValueToElement, Function<T, K> elementToKey, Function<T, V> elementToValue) Construct with a backingList- Parameters:
list- The backingListinstance.keyValueToElement- TheBiFunctionto provide the list elements.elementToKey- TheFunctionto provide the map's key.elementToValue- TheFunctionto provide the map's value.
-
-
Method Details