Class ListModelSet<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,Set<E>,Pageable,Selectable<E>,Sortable<E>,ListModel<E>,PageableModel
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.zul.AbstractListModel
AbstractListModel.DefaultSelectionControl<E> -
Field Summary
FieldsFields inherited from class org.zkoss.zul.AbstractListModel
_selectionFields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ListModelSet(int initialCapacity) Constructor.ListModelSet(int initialCapacity, float loadFactor) Constructor.ListModelSet(E[] array) Constructor.ListModelSet(Collection<? extends E> c) Constructor.ListModelSet(Set<E> set, boolean live) Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item).booleanaddAll(Collection<? extends E> c) This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item).voidclear()clone()booleanbooleancontainsAll(Collection<?> c) booleanprotected voidSelectable's implementor use only.getElementAt(int j) Returns the value at the specified index.Get the inner real set.intgetSize()Returns the length of the list.getSortDirection(Comparator<E> cmpr) Returns the sort direction of this model for the given comparator.inthashCode()intReturns the index of the specified object, or -1 if not found.booleanisEmpty()iterator()booleannotifyChange(E element) Notifies a change of the same element to trigger an event ofListDataEvent.CONTENTS_CHANGED.booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()voidsort()Sort the data model by default or assigned comparator.voidsort(Comparator<E> cmpr, boolean ascending) Sorts the data.Object[]toArray()<T> T[]toArray(T[] a) 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, writeSelectionMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
spliterator
-
Field Details
-
_set
-
-
Constructor Details
-
ListModelSet
Constructor- Parameters:
set- the set to representlive- whether to have a 'live'ListModelon 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 thisListModelSet, the inner "live" set would be changed accordingly. However, it is not a good idea to modifysetif it is passed to this method with live is true, sinceListboxis not smart enough to handle it. Instead, modify it thru this object.- Since:
- 2.4.0
-
ListModelSet
public ListModelSet()Constructor. -
ListModelSet
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
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 Details
-
getInnerSet
Get the inner real set. -
getSize
public int getSize()Description copied from interface:ListModelReturns the length of the list. -
getElementAt
Description copied from interface:ListModelReturns the value at the specified index.- Specified by:
getElementAtin interfaceListModel<E>
-
notifyChange
Notifies a change of the same element to trigger an event ofListDataEvent.CONTENTS_CHANGED.- Parameters:
element-- Returns:
- true if the element exists
- Since:
- 8.0.0
-
add
This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item). Other implementation needs one more linear search. -
addAll
This implementation optimized on the LinkedHashSet(which guarantees the sequence of the added item). Other implementation needs one more linear search. -
clear
public void clear() -
contains
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
equals
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty() -
toString
-
iterator
-
remove
-
indexOf
Returns the index of the specified object, or -1 if not found. -
removeAll
-
retainAll
-
size
public int size() -
toArray
-
toArray
public <T> T[] toArray(T[] a) -
sort
Sorts the data. -
sort
public void sort()Description copied from interface:SortableSort 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. -
getSortDirection
Description copied from interface:SortableReturns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".Default: "natural".
- Specified by:
getSortDirectionin interfaceSortable<E>
-
clone
- Overrides:
clonein classAbstractListModel<E>
-
fireSelectionEvent
Description copied from class:AbstractListModelSelectable'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)andAbstractListModel.setSelection(Collection).- Overrides:
fireSelectionEventin classAbstractListModel<E>- Parameters:
e- selected object.
-