Package org.zkoss.zul

## Class ListModelArray<E>

- java.lang.Object
- - org.zkoss.zul.AbstractListModel<E>
  - - org.zkoss.zul.ListModelArray<E>

- All Implemented Interfaces:
    `java.io.Serializable`, `Pageable`, `Selectable<E>`, `Sortable<E>`, `ListModel<E>`, `PageableModel`
  Direct Known Subclasses:
    `ListModelArrayProxy`

      public class ListModelArray<E>
      extends AbstractListModel<E>
      implements Sortable<E>, java.io.Serializable

  This is the `ListModel` as an Object array to be used with `Listbox`. Change the contents of this model as an Object array would cause the associated Listbox to change accordingly.

  The class implements the `Selectable` interface, updating the selection status after sorted. (since 6.0.0)

  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>`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.lang.Object[]` | `_array` |

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

      `_selection`

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

      `INTERNAL_EVENT`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ListModelArray​(int size)` | Constructor.
    `ListModelArray​(E[] array)` | Constructor.
    `ListModelArray​(E[] array, boolean live)` | Constructor
    `ListModelArray​(java.util.List<? extends E> list)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `java.lang.Object` | `clone()` |
    `boolean` | `equals​(java.lang.Object o)` |
    `protected void` | `fireSelectionEvent​(E e)` | Selectable's implementor use only.
    `E` | `get​(int index)` | Get the value of this ListModelArray at specified index.
    `E` | `getElementAt​(int j)` | Returns the value at the specified index.
    `java.lang.Object[]` | `getInnerArray()` | Get the inner real Object[].
    `int` | `getSize()` | Returns the length of the list.
    `java.lang.String` | `getSortDirection​(java.util.Comparator<E> cmpr)` | Returns the sort direction of this model for the given comparator.
    `int` | `hashCode()` |
    `int` | `indexOf​(java.lang.Object elm)` | Returns the index of the specified element.
    `boolean` | `notifyChange​(E element)` | Notifies a change of the same element to trigger an event of `ListDataEvent.CONTENTS_CHANGED`.
    `void` | `set​(int index, E value)` | Change content of the Array at specified index.
    `void` | `sort()` | Sort the data model by default or assigned comparator.
    `void` | `sort​(java.util.Comparator<E> cmpr, boolean ascending)` | Sorts the data.
    `java.lang.String` | `toString()` |

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

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

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

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

- - ### Field Detail

    - #### _array

          protected java.lang.Object[] _array

  - ### Constructor Detail

    - #### ListModelArray

          public ListModelArray​(E[] array,
                                boolean live)

      Constructor
      Parameters:
        `array` - the array to represent
        `live` - whether to have a 'live' `ListModel` on top of the specified array. If false, the content of the specified array is copied. If true, this object is a 'facade' of the specified array, i.e., when you add or remove items from this `ListModelArray`, the inner "live" array would be changed accordingly. However, it is not a good idea to modify `array` 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

    - #### ListModelArray

          public ListModelArray​(E[] array)

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

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

    - #### ListModelArray

          public ListModelArray​(int size)

      Constructor.
      Parameters:
        `size` - the array size.

    - #### ListModelArray

          public ListModelArray​(java.util.List<? extends E> list)

      Constructor. It mades a copy of the specified list (i.e., not live).
      Since:
        2.4.1

  - ### Method Detail

    - #### get

          public E get​(int index)

      Get the value of this ListModelArray at specified index.
      Parameters:
        `index` - the array index to be get value.

    - #### set

          public void set​(int index,
                          E value)

      Change content of the Array at specified index.
      Parameters:
        `index` - the array index to be set the new value.

    - #### getInnerArray

          public java.lang.Object[] getInnerArray()

      Get the inner real Object[].
      Since:
        2.4.0

    - #### indexOf

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

      Returns the index of the specified element.

    - #### notifyChange

          public boolean notifyChange​(E element)

      Notifies a change of the same element to trigger an event of `ListDataEvent.CONTENTS_CHANGED`.
      Parameters:
        `element` -
      Returns:
        true if the element exists
      Since:
        8.0.0

    - #### getSize

          public int getSize()

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

    - #### getElementAt

          public E getElementAt​(int j)

      Description copied from interface: `ListModel`
      Returns the value at the specified index.
      Specified by:
        `getElementAt` in interface `ListModel<E>`

    - #### sort

          public void sort​(java.util.Comparator<E> cmpr,
                           boolean ascending)

      Sorts the data.
      Specified by:
        `sort` in interface `Sortable<E>`
      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<E>`
      See Also:
        `Sortable.sort(Comparator, boolean)`

    - #### getSortDirection

          public java.lang.String getSortDirection​(java.util.Comparator<E> 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<E>`

    - #### equals

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

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

    - #### hashCode

          public int hashCode()

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

    - #### toString

          public java.lang.String toString()

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

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `AbstractListModel<E>`

    - #### fireSelectionEvent

          protected void fireSelectionEvent​(E 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<E>`
      Parameters:
        `e` - selected object.