Package org.zkoss.zul

## Class ListModelSet<E>

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

- All Implemented Interfaces:
    `java.io.Serializable`, `java.lang.Iterable<E>`, `java.util.Collection<E>`, `java.util.Set<E>`, `Pageable`, `Selectable<E>`, `Sortable<E>`, `ListModel<E>`, `PageableModel`
  Direct Known Subclasses:
    `ListModelSetProxy`

      public class ListModelSet<E>
      extends AbstractListModel<E>
      implements Sortable<E>, java.util.Set<E>, java.io.Serializable

  This is the `ListModel` as a `Set` to be used with `Listbox`. Add or remove the contents of this model as a Set 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>`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.util.Set<E>` | `_set` |

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

      `_selection`

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

      `INTERNAL_EVENT`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ListModelSet()` | Constructor.
    `ListModelSet​(int initialCapacity)` | Constructor.
    `ListModelSet​(int initialCapacity, float loadFactor)` | Constructor.
    `ListModelSet​(E[] array)` | Constructor.
    `ListModelSet​(java.util.Collection<? extends E> c)` | Constructor.
    `ListModelSet​(java.util.Set<E> set, boolean live)` | Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `add​(E o)` | This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item).
    `boolean` | `addAll​(java.util.Collection<? extends E> c)` | This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item).
    `void` | `clear()` |
    `java.lang.Object` | `clone()` |
    `boolean` | `contains​(java.lang.Object elem)` |
    `boolean` | `containsAll​(java.util.Collection<?> c)` |
    `boolean` | `equals​(java.lang.Object o)` |
    `protected void` | `fireSelectionEvent​(E e)` | Selectable's implementor use only.
    `E` | `getElementAt​(int j)` | Returns the value at the specified index.
    `java.util.Set<E>` | `getInnerSet()` | Get the inner real set.
    `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 o)` | Returns the index of the specified object, or -1 if not found.
    `boolean` | `isEmpty()` |
    `java.util.Iterator<E>` | `iterator()` |
    `boolean` | `notifyChange​(E element)` | Notifies a change of the same element to trigger an event of `ListDataEvent.CONTENTS_CHANGED`.
    `boolean` | `remove​(java.lang.Object o)` |
    `boolean` | `removeAll​(java.util.Collection<?> c)` |
    `boolean` | `retainAll​(java.util.Collection<?> c)` |
    `int` | `size()` |
    `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.Object[]` | `toArray()` |
    `<T> T[]` | `toArray​(T[] a)` |
    `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`

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

      `parallelStream, removeIf, stream, toArray`

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

      `forEach`

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

      `spliterator`

- - ### Field Detail

    - #### _set

          protected java.util.Set<E> _set

  - ### Constructor Detail

    - #### ListModelSet

          public ListModelSet​(java.util.Set<E> set,
                              boolean live)

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

    - #### ListModelSet

          public ListModelSet()

      Constructor.

    - #### ListModelSet

          public ListModelSet​(java.util.Collection<? extends E> c)

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

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

    - #### ListModelSet

          public ListModelSet​(E[] array)

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

    - #### ListModelSet

          public ListModelSet​(int initialCapacity)

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

    - #### ListModelSet

          public ListModelSet​(int initialCapacity,
                              float loadFactor)

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

  - ### Method Detail

    - #### getInnerSet

          public java.util.Set<E> getInnerSet()

      Get the inner real set.

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

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

    - #### add

          public boolean add​(E o)

      This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item). Other implementation needs one more linear search.
      Specified by:
        `add` in interface `java.util.Collection<E>`
      Specified by:
        `add` in interface `java.util.Set<E>`

    - #### addAll

          public boolean addAll​(java.util.Collection<? extends E> c)

      This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item). Other implementation needs one more linear search.
      Specified by:
        `addAll` in interface `java.util.Collection<E>`
      Specified by:
        `addAll` in interface `java.util.Set<E>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `java.util.Collection<E>`
      Specified by:
        `clear` in interface `java.util.Set<E>`

    - #### contains

          public boolean contains​(java.lang.Object elem)

      Specified by:
        `contains` in interface `java.util.Collection<E>`
      Specified by:
        `contains` in interface `java.util.Set<E>`

    - #### containsAll

          public boolean containsAll​(java.util.Collection<?> c)

      Specified by:
        `containsAll` in interface `java.util.Collection<E>`
      Specified by:
        `containsAll` in interface `java.util.Set<E>`

    - #### equals

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

      Specified by:
        `equals` in interface `java.util.Collection<E>`
      Specified by:
        `equals` in interface `java.util.Set<E>`
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `java.util.Collection<E>`
      Specified by:
        `hashCode` in interface `java.util.Set<E>`
      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `java.util.Collection<E>`
      Specified by:
        `isEmpty` in interface `java.util.Set<E>`

    - #### toString

          public java.lang.String toString()

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

    - #### iterator

          public java.util.Iterator<E> iterator()

      Specified by:
        `iterator` in interface `java.util.Collection<E>`
      Specified by:
        `iterator` in interface `java.lang.Iterable<E>`
      Specified by:
        `iterator` in interface `java.util.Set<E>`

    - #### remove

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

      Specified by:
        `remove` in interface `java.util.Collection<E>`
      Specified by:
        `remove` in interface `java.util.Set<E>`

    - #### indexOf

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

      Returns the index of the specified object, or -1 if not found.

    - #### removeAll

          public boolean removeAll​(java.util.Collection<?> c)

      Specified by:
        `removeAll` in interface `java.util.Collection<E>`
      Specified by:
        `removeAll` in interface `java.util.Set<E>`

    - #### retainAll

          public boolean retainAll​(java.util.Collection<?> c)

      Specified by:
        `retainAll` in interface `java.util.Collection<E>`
      Specified by:
        `retainAll` in interface `java.util.Set<E>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `java.util.Collection<E>`
      Specified by:
        `size` in interface `java.util.Set<E>`

    - #### toArray

          public java.lang.Object[] toArray()

      Specified by:
        `toArray` in interface `java.util.Collection<E>`
      Specified by:
        `toArray` in interface `java.util.Set<E>`

    - #### toArray

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

      Specified by:
        `toArray` in interface `java.util.Collection<E>`
      Specified by:
        `toArray` in interface `java.util.Set<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>`

    - #### 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.