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
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
ListModelas aMapto be used withListbox. 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>
-
-
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 voidclear()java.lang.Objectclone()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)protected voidfireSelectionEvent(java.util.Map.Entry<K,V> e)Selectable's implementor use only.Vget(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.intgetSize()Returns the length of the list.java.lang.StringgetSortDirection(java.util.Comparator<java.util.Map.Entry<K,V>> cmpr)Returns the sort direction of this model for the given comparator.inthashCode()intindexOf(java.lang.Object o)Returns the index of the specified object based on the entry (Map.Entry).intindexOfKey(java.lang.Object o)Returns the index of the specified object based on the key.booleanisEmpty()java.util.Set<K>keySet()Vput(K key, V o)voidputAll(java.util.Map<? extends K,? extends V> c)protected voidreadSelection(java.io.ObjectInputStream s)Reads backAbstractListModel._selection.Vremove(java.lang.Object key)intsize()voidsort()Sort the data model by default or assigned comparator.voidsort(java.util.Comparator<java.util.Map.Entry<K,V>> cmpr, boolean ascending)Sorts the data.java.lang.StringtoString()java.util.Collection<V>values()protected voidwriteSelection(java.io.ObjectOutputStream s)WritesAbstractListModel._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
-
-
-
-
Constructor Detail
-
ListModelMap
public ListModelMap(java.util.Map<K,V> map, boolean live)
Constructor.- Parameters:
map- the map to representlive- whether to have a 'live'ListModelon 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 thisListModelMap, the inner "live" map would be changed accordingly. However, it is not a good idea to modifymapif 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
-
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
-
getSize
public int getSize()
Description copied from interface:ListModelReturns the length of the list.
-
getElementAt
public java.util.Map.Entry<K,V> getElementAt(int j)
Returns the entry (Map.Entry) at the specified index.- Specified by:
getElementAtin interfaceListModel<K>
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
equals
public boolean equals(java.lang.Object o)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
-
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.
-
values
public java.util.Collection<V> values()
-
sort
public void sort(java.util.Comparator<java.util.Map.Entry<K,V>> cmpr, boolean ascending)
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.- Specified by:
sortin interfaceSortable<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: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<K>
-
clone
public java.lang.Object clone()
- Overrides:
clonein classAbstractListModel<java.util.Map.Entry<K,V>>
-
fireSelectionEvent
protected void fireSelectionEvent(java.util.Map.Entry<K,V> e)
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<java.util.Map.Entry<K,V>>- Parameters:
e- selected object.
-
writeSelection
protected void writeSelection(java.io.ObjectOutputStream s) throws java.io.IOExceptionDescription copied from class:AbstractListModelWritesAbstractListModel._selection.Default: write it directly. Override it if E is not serializable.
- Overrides:
writeSelectionin classAbstractListModel<java.util.Map.Entry<K,V>>- Throws:
java.io.IOException
-
readSelection
protected void readSelection(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundExceptionDescription copied from class:AbstractListModelReads backAbstractListModel._selection.Default: write it directly. Override it if E is not serializable.
- Overrides:
readSelectionin classAbstractListModel<java.util.Map.Entry<K,V>>- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-