org.thewonderlemming.c4plantuml.graphml.model

## Class MappedListDecorator<M,K>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractList<E>
    - - java.util.ArrayList<M>
      - - org.thewonderlemming.c4plantuml.graphml.model.MappedListDecorator<M,K>

- Type Parameters:
    `M` - the type of data to manage.
    `K` - the type of the data key.
  All Implemented Interfaces:
    Serializable, Cloneable, Iterable<M>, Collection<M>, List<M>, RandomAccess

      public class MappedListDecorator<M,K>
      extends ArrayList<M>
      implements List<M>

  A decorator to the `List` interface, that relies on an internal `Map` to track existing data by the key `K`.

  The "raison d'être" of that class is to simplify the JAXB data model by putting properties that appear to be lists and managing the add/replace feature internally and at the same location.

  Author:
    thewonderlemming
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<K,M>` | `dataLookup` The lookup map that maps the data to its key.

    - ### Fields inherited from class java.util.AbstractList

      `modCount`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MappedListDecorator(Class<M> modelType, List<M> model, Function<M,K> getModelId)` Default constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(int index, M element)`
    `boolean` | `add(M e)`
    `boolean` | `addAll(Collection<? extends M> c)`
    `boolean` | `addAll(int index, Collection<? extends M> c)`
    `void` | `addOrReplaceData(M model)` Adds or replaces the given `model`, given that its key `K` is not yet registered in the current mapping or not.
    `void` | `clear()`
    `boolean` | `contains(Object o)`
    `boolean` | `containsAll(Collection<?> c)`
    `boolean` | `equals(Object o)`
    `M` | `get(int index)`
    `int` | `hashCode()`
    `int` | `indexOf(Object o)`
    `boolean` | `isEmpty()`
    `Iterator<M>` | `iterator()`
    `int` | `lastIndexOf(Object o)`
    `ListIterator<M>` | `listIterator()`
    `ListIterator<M>` | `listIterator(int index)`
    `M` | `remove(int index)`
    `boolean` | `remove(Object o)`
    `boolean` | `removeAll(Collection<?> c)`
    `boolean` | `retainAll(Collection<?> c)`
    `M` | `set(int index, M element)`
    `int` | `size()`
    `List<M>` | `subList(int fromIndex, int toIndex)`
    `Object[]` | `toArray()`
    `<T> T[]` | `toArray(T[] a)`

    - ### Methods inherited from class java.util.ArrayList

      `clone, ensureCapacity, forEach, removeIf, removeRange, replaceAll, sort, spliterator, trimToSize`

    - ### Methods inherited from class java.util.AbstractCollection

      `toString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.List

      `replaceAll, sort, spliterator`

    - ### Methods inherited from interface java.util.Collection

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Field Detail

    - #### dataLookup

          protected final transient Map<K,M> dataLookup

      The lookup map that maps the data to its key. It is protected for testing purposes.

  - ### Constructor Detail

    - #### MappedListDecorator

          public MappedListDecorator(Class<M> modelType,
                                     List<M> model,
                                     Function<M,K> getModelId)

      Default constructor.
      Parameters:
        `modelType` - the type of the model to manage.
        `model` - the decorated model list.
        `getModelId` - a function that provides a model key of type `K` given a model of type `M`.

  - ### Method Detail

    - #### add

          public void add(int index,
                          M element)

      Specified by:
        `add` in interface `List<M>`
      Overrides:
        `add` in class `ArrayList<M>`

    - #### add

          public boolean add(M e)

      Specified by:
        `add` in interface `Collection<M>`
      Specified by:
        `add` in interface `List<M>`
      Overrides:
        `add` in class `ArrayList<M>`

    - #### addAll

          public boolean addAll(Collection<? extends M> c)

      Specified by:
        `addAll` in interface `Collection<M>`
      Specified by:
        `addAll` in interface `List<M>`
      Overrides:
        `addAll` in class `ArrayList<M>`

    - #### addAll

          public boolean addAll(int index,
                                Collection<? extends M> c)

      Specified by:
        `addAll` in interface `List<M>`
      Overrides:
        `addAll` in class `ArrayList<M>`

    - #### addOrReplaceData

          public void addOrReplaceData(M model)

      Adds or replaces the given `model`, given that its key `K` is not yet registered in the current mapping or not.
      Parameters:
        `model` - the model to add or update.

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<M>`
      Specified by:
        `clear` in interface `List<M>`
      Overrides:
        `clear` in class `ArrayList<M>`

    - #### contains

          public boolean contains(Object o)

      Specified by:
        `contains` in interface `Collection<M>`
      Specified by:
        `contains` in interface `List<M>`
      Overrides:
        `contains` in class `ArrayList<M>`

    - #### containsAll

          public boolean containsAll(Collection<?> c)

      Specified by:
        `containsAll` in interface `Collection<M>`
      Specified by:
        `containsAll` in interface `List<M>`
      Overrides:
        `containsAll` in class `AbstractCollection<M>`

    - #### equals

          public boolean equals(Object o)

      Specified by:
        `equals` in interface `Collection<M>`
      Specified by:
        `equals` in interface `List<M>`
      Overrides:
        `equals` in class `AbstractList<M>`

    - #### get

          public M get(int index)

      Specified by:
        `get` in interface `List<M>`
      Overrides:
        `get` in class `ArrayList<M>`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `Collection<M>`
      Specified by:
        `hashCode` in interface `List<M>`
      Overrides:
        `hashCode` in class `AbstractList<M>`

    - #### indexOf

          public int indexOf(Object o)

      Specified by:
        `indexOf` in interface `List<M>`
      Overrides:
        `indexOf` in class `ArrayList<M>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Collection<M>`
      Specified by:
        `isEmpty` in interface `List<M>`
      Overrides:
        `isEmpty` in class `ArrayList<M>`

    - #### iterator

          public Iterator<M> iterator()

      Specified by:
        `iterator` in interface `Iterable<M>`
      Specified by:
        `iterator` in interface `Collection<M>`
      Specified by:
        `iterator` in interface `List<M>`
      Overrides:
        `iterator` in class `ArrayList<M>`

    - #### lastIndexOf

          public int lastIndexOf(Object o)

      Specified by:
        `lastIndexOf` in interface `List<M>`
      Overrides:
        `lastIndexOf` in class `ArrayList<M>`

    - #### listIterator

          public ListIterator<M> listIterator()

      Specified by:
        `listIterator` in interface `List<M>`
      Overrides:
        `listIterator` in class `ArrayList<M>`

    - #### listIterator

          public ListIterator<M> listIterator(int index)

      Specified by:
        `listIterator` in interface `List<M>`
      Overrides:
        `listIterator` in class `ArrayList<M>`

    - #### remove

          public M remove(int index)

      Specified by:
        `remove` in interface `List<M>`
      Overrides:
        `remove` in class `ArrayList<M>`

    - #### remove

          public boolean remove(Object o)

      Specified by:
        `remove` in interface `Collection<M>`
      Specified by:
        `remove` in interface `List<M>`
      Overrides:
        `remove` in class `ArrayList<M>`

    - #### removeAll

          public boolean removeAll(Collection<?> c)

      Specified by:
        `removeAll` in interface `Collection<M>`
      Specified by:
        `removeAll` in interface `List<M>`
      Overrides:
        `removeAll` in class `ArrayList<M>`

    - #### retainAll

          public boolean retainAll(Collection<?> c)

      Specified by:
        `retainAll` in interface `Collection<M>`
      Specified by:
        `retainAll` in interface `List<M>`
      Overrides:
        `retainAll` in class `ArrayList<M>`

    - #### set

          public M set(int index,
                       M element)

      Specified by:
        `set` in interface `List<M>`
      Overrides:
        `set` in class `ArrayList<M>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Collection<M>`
      Specified by:
        `size` in interface `List<M>`
      Overrides:
        `size` in class `ArrayList<M>`

    - #### subList

          public List<M> subList(int fromIndex,
                                 int toIndex)

      Specified by:
        `subList` in interface `List<M>`
      Overrides:
        `subList` in class `ArrayList<M>`

    - #### toArray

          public Object[] toArray()

      Specified by:
        `toArray` in interface `Collection<M>`
      Specified by:
        `toArray` in interface `List<M>`
      Overrides:
        `toArray` in class `ArrayList<M>`

    - #### toArray

          public <T> T[] toArray(T[] a)

      Specified by:
        `toArray` in interface `Collection<M>`
      Specified by:
        `toArray` in interface `List<M>`
      Overrides:
        `toArray` in class `ArrayList<M>`

Copyright © 2020. All rights reserved.