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>

public class ListBackedMap<T,K,V> extends AbstractMap<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
     );
 
  • Constructor Details

    • ListBackedMap

      public ListBackedMap(List<T> list, BiFunction<K,V,T> keyValueToElement, Function<T,K> elementToKey, Function<T,V> elementToValue)
      Construct with a backing List
      Parameters:
      list - The backing List instance.
      keyValueToElement - The BiFunction to provide the list elements.
      elementToKey - The Function to provide the map's key.
      elementToValue - The Function to provide the map's value.
  • Method Details