Package org.zkoss.zul

## Class ListModelMap<K,​V>

- java.lang.Object
- - org.zkoss.zul.AbstractListModel<java.util.Map.Entry<K,​V>>
  - - org.zkoss.zul.ListModelMap<K,​V>

- All Implemented Interfaces:
    `java.io.Serializable`, `java.util.Map<K,​V>`, `Pageable`, `Selectable<java.util.Map.Entry<K,​V>>`, `Sortable<java.util.Map.Entry<K,​V>>`, `ListModel<java.util.Map.Entry<K,​V>>`, `PageableModel`
  Direct Known Subclasses:
    `ListModelMapProxy`

      public class ListModelMap<K,​V>
      extends AbstractListModel<java.util.Map.Entry<K,​V>>
      implements Sortable<java.util.Map.Entry<K,​V>>, java.util.Map<K,​V>, java.io.Serializable

  This is the `ListModel` as a `Map` to be used with `Listbox`. Add or remove the contents of this model as a List would cause the associated Listbox to change accordingly.

  Author:
    Henri Chen
  See Also:
    `ListModel`, `ListModelList`, `ListModelMap`, Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.zkoss.zul.AbstractListModel

      `AbstractListModel.DefaultSelectionControl<E>`

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.util.Map<K,​V>` | `_map` |

    - ### Fields inherited from class org.zkoss.zul.AbstractListModel

      `_selection`

    - ### Fields inherited from interface org.zkoss.zul.PageableModel

      `INTERNAL_EVENT`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ListModelMap()` | Constructor.
    `ListModelMap​(int initialCapacity)` | Constructor.
    `ListModelMap​(int initialCapacity, float loadFactor)` | Constructor.
    `ListModelMap​(java.util.Map<? extends K,​? extends V> map)` | Constructor.
    `ListModelMap​(java.util.Map<K,​V> map, boolean live)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `clear()` |
    `java.lang.Object` | `clone()` |
    `boolean` | `containsKey​(java.lang.Object key)` |
    `boolean` | `containsValue​(java.lang.Object value)` |
    `java.util.Set<java.util.Map.Entry<K,​V>>` | `entrySet()` |
    `boolean` | `equals​(java.lang.Object o)` |
    `protected void` | `fireSelectionEvent​(java.util.Map.Entry<K,​V> e)` | Selectable's implementor use only.
    `V` | `get​(java.lang.Object key)` |
    `java.util.Map.Entry<K,​V>` | `getElementAt​(int j)` | Returns the entry (Map.Entry) at the specified index.
    `java.util.Map<K,​V>` | `getInnerMap()` | Get the inner real Map.
    `int` | `getSize()` | Returns the length of the list.
    `java.lang.String` | `getSortDirection​(java.util.Comparator<java.util.Map.Entry<K,​V>> cmpr)` | Returns the sort direction of this model for the given comparator.
    `int` | `hashCode()` |
    `int` | `indexOf​(java.lang.Object o)` | Returns the index of the specified object based on the entry (Map.Entry).
    `int` | `indexOfKey​(java.lang.Object o)` | Returns the index of the specified object based on the key.
    `boolean` | `isEmpty()` |
    `java.util.Set<K>` | `keySet()` |
    `V` | `put​(K key, V o)` |
    `void` | `putAll​(java.util.Map<? extends K,​? extends V> c)` |
    `protected void` | `readSelection​(java.io.ObjectInputStream s)` | Reads back `AbstractListModel._selection`.
    `V` | `remove​(java.lang.Object key)` |
    `int` | `size()` |
    `void` | `sort()` | Sort the data model by default or assigned comparator.
    `void` | `sort​(java.util.Comparator<java.util.Map.Entry<K,​V>> cmpr, boolean ascending)` | Sorts the data.
    `java.lang.String` | `toString()` |
    `java.util.Collection<V>` | `values()` |
    `protected void` | `writeSelection​(java.io.ObjectOutputStream s)` | Writes `AbstractListModel._selection`.

    - ### Methods inherited from class org.zkoss.zul.AbstractListModel

      `addListDataListener, addPagingEventListener, addToSelection, clearSelection, fireEvent, getActivePage, getListDataListeners, getPageCount, getPageSize, getSelection, getSelectionControl, getTotalSize, isMultiple, isSelected, isSelectionEmpty, newEmptySelection, removeAllSelection, removeFromSelection, removeListDataListener, removePagingEventListener, retainAllSelection, setActivePage, setMultiple, setPageSize, setSelection, setSelectionControl`

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

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

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

      `compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

- - ### Field Detail

    - #### _map

          protected java.util.Map<K,​V> _map

  - ### Constructor Detail

    - #### ListModelMap

          public ListModelMap​(java.util.Map<K,​V> map,
                              boolean live)

      Constructor.
      Parameters:
        `map` - the map to represent
        `live` - whether to have a 'live' `ListModel` on top of the specified map. If false, the content of the specified map is copied. If true, this object is a 'facade' of the specified map, i.e., when you add or remove items from this `ListModelMap`, the inner "live" map would be changed accordingly. However, it is not a good idea to modify `map` if it is passed to this method with live is true, since `Listbox` is not smart enough to handle it. Instead, modify it thru this object.
      Since:
        2.4.0

    - #### ListModelMap

          public ListModelMap()

      Constructor.

    - #### ListModelMap

          public ListModelMap​(java.util.Map<? extends K,​? extends V> map)

      Constructor. It makes a copy of the specified map (i.e., not live).

      Notice that if the data is static or not shared, it is better to use `ListModelMap(map, true)` instead, since making a copy is slower.

    - #### ListModelMap

          public ListModelMap​(int initialCapacity)

      Constructor.
      Parameters:
        `initialCapacity` - the initial capacity for this ListModelMap.

    - #### ListModelMap

          public ListModelMap​(int initialCapacity,
                              float loadFactor)

      Constructor.
      Parameters:
        `initialCapacity` - the initial capacity for this ListModelMap.
        `loadFactor` - the loadFactor to increase capacity of this ListModelMap.

  - ### Method Detail

    - #### getInnerMap

          public java.util.Map<K,​V> getInnerMap()

      Get the inner real Map.

    - #### getSize

          public int getSize()

      Description copied from interface: `ListModel`
      Returns the length of the list.
      Specified by:
        `getSize` in interface `ListModel<K>`

    - #### getElementAt

          public java.util.Map.Entry<K,​V> getElementAt​(int j)

      Returns the entry (Map.Entry) at the specified index.
      Specified by:
        `getElementAt` in interface `ListModel<K>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `java.util.Map<K,​V>`

    - #### containsKey

          public boolean containsKey​(java.lang.Object key)

      Specified by:
        `containsKey` in interface `java.util.Map<K,​V>`

    - #### containsValue

          public boolean containsValue​(java.lang.Object value)

      Specified by:
        `containsValue` in interface `java.util.Map<K,​V>`

    - #### entrySet

          public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()

      Specified by:
        `entrySet` in interface `java.util.Map<K,​V>`

    - #### equals

          public boolean equals​(java.lang.Object o)

      Specified by:
        `equals` in interface `java.util.Map<K,​V>`
      Overrides:
        `equals` in class `java.lang.Object`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### get

          public V get​(java.lang.Object key)

      Specified by:
        `get` in interface `java.util.Map<K,​V>`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `java.util.Map<K,​V>`
      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `java.util.Map<K,​V>`

    - #### keySet

          public java.util.Set<K> keySet()

      Specified by:
        `keySet` in interface `java.util.Map<K,​V>`

    - #### put

          public V put​(K key,
                       V o)

      Specified by:
        `put` in interface `java.util.Map<K,​V>`

    - #### indexOfKey

          public int indexOfKey​(java.lang.Object o)

      Returns the index of the specified object based on the key.
      Parameters:
        `o` - the key to look for

    - #### indexOf

          public int indexOf​(java.lang.Object o)

      Returns the index of the specified object based on the entry (Map.Entry).
      Parameters:
        `o` - the object to look for. It must be an instance of Map.Entry.

    - #### putAll

          public void putAll​(java.util.Map<? extends K,​? extends V> c)

      Specified by:
        `putAll` in interface `java.util.Map<K,​V>`

    - #### remove

          public V remove​(java.lang.Object key)

      Specified by:
        `remove` in interface `java.util.Map<K,​V>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `java.util.Map<K,​V>`

    - #### values

          public java.util.Collection<V> values()

      Specified by:
        `values` in interface `java.util.Map<K,​V>`

    - #### sort

          public void sort​(java.util.Comparator<java.util.Map.Entry<K,​V>> cmpr,
                           boolean ascending)

      Sorts the data.
      Specified by:
        `sort` in interface `Sortable<K>`
      Parameters:
        `cmpr` - the comparator.
        `ascending` - whether to sort in the ascending order. It is ignored since this implementation uses cmpr to compare.

    - #### sort

          public void sort()

      Description copied from interface: `Sortable`
      Sort the data model by default or assigned comparator. Notice that the default implementation does nothing, the model which implements Sortable need to implement this method.
      Specified by:
        `sort` in interface `Sortable<K>`
      See Also:
        `Sortable.sort(Comparator, boolean)`

    - #### getSortDirection

          public java.lang.String getSortDirection​(java.util.Comparator<java.util.Map.Entry<K,​V>> cmpr)

      Description copied from interface: `Sortable`
      Returns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".

      Default: "natural".

      Specified by:
        `getSortDirection` in interface `Sortable<K>`

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `AbstractListModel<java.util.Map.Entry<K,​V>>`

    - #### fireSelectionEvent

          protected void fireSelectionEvent​(java.util.Map.Entry<K,​V> e)

      Description copied from class: `AbstractListModel`
      Selectable's implementor use only.

      Fires a selection event for component to scroll into view. The override subclass must put the index0 of `AbstractListModel.fireEvent(int, int, int)` as the view index to scroll. By default, the value -1 is assumed which means no scroll into view.

      The method is invoked when both methods are invoked. `AbstractListModel.addToSelection(Object)` and `AbstractListModel.setSelection(Collection)`.

      Overrides:
        `fireSelectionEvent` in class `AbstractListModel<java.util.Map.Entry<K,​V>>`
      Parameters:
        `e` - selected object.

    - #### writeSelection

          protected void writeSelection​(java.io.ObjectOutputStream s)
                                 throws java.io.IOException

      Description copied from class: `AbstractListModel`
      Writes `AbstractListModel._selection`.

      Default: write it directly. Override it if E is not serializable.

      Overrides:
        `writeSelection` in class `AbstractListModel<java.util.Map.Entry<K,​V>>`
      Throws:
        `java.io.IOException`

    - #### readSelection

          protected void readSelection​(java.io.ObjectInputStream s)
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException

      Description copied from class: `AbstractListModel`
      Reads back `AbstractListModel._selection`.

      Default: write it directly. Override it if E is not serializable.

      Overrides:
        `readSelection` in class `AbstractListModel<java.util.Map.Entry<K,​V>>`
      Throws:
        `java.io.IOException`
        `java.lang.ClassNotFoundException`