org.zkoss.zul
Class ListModelMap<K,V>

java.lang.Object
  extended by org.zkoss.zul.AbstractListModel<Map.Entry<K,V>>
      extended by org.zkoss.zul.ListModelMap<K,V>
All Implemented Interfaces:
Serializable, Map<K,V>, Selectable<Map.Entry<K,V>>, Sortable<Map.Entry<K,V>>, ListModel<Map.Entry<K,V>>

public class ListModelMap<K,V>
extends AbstractListModel<Map.Entry<K,V>>
implements Sortable<Map.Entry<K,V>>, Map<K,V>, 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 interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Map<K,V> _map
           
 
Constructor Summary
ListModelMap()
          Constructor.
ListModelMap(int initialCapacity)
          Constructor.
ListModelMap(int initialCapacity, float loadFactor)
          Constructor.
ListModelMap(Map<? extends K,? extends V> map)
          Constructor.
ListModelMap(Map<K,V> map, boolean live)
          Constructor.
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 boolean equals(Object o)
           
 V get(Object key)
           
 Map.Entry<K,V> getElementAt(int j)
          Returns the entry (Map.Entry) at the specified index.
 Map<K,V> getInnerMap()
          Get the inner real Map.
 int getSize()
          Returns the length of the list.
 int hashCode()
           
 int indexOf(Object o)
          Returns the index of the specified object based on the entry (Map.Entry).
 int indexOfKey(Object o)
          Returns the index of the specified object based on the key.
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V o)
           
 void putAll(Map<? extends K,? extends V> c)
           
 V remove(Object key)
           
 int size()
           
 void sort(Comparator<Map.Entry<K,V>> cmpr, boolean ascending)
          Sorts the data.
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class org.zkoss.zul.AbstractListModel
addListDataListener, addSelection, clearSelection, fireEvent, getSelection, removeAllSelection, removeListDataListener, removeSelection, retainAllSelection
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_map

protected Map<K,V> _map
Constructor Detail

ListModelMap

public ListModelMap(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 hanle it. Instead, modify it thru this object.
Since:
2.4.0

ListModelMap

public ListModelMap()
Constructor.


ListModelMap

public ListModelMap(Map<? extends K,? extends V> map)
Constructor. It mades a copy of the specified map (i.e., not live).


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 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<Map.Entry<K,V>>

getElementAt

public Map.Entry<K,V> getElementAt(int j)
Returns the entry (Map.Entry) at the specified index.

Specified by:
getElementAt in interface ListModel<Map.Entry<K,V>>

clear

public void clear()
Specified by:
clear in interface Map<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>

equals

public boolean equals(Object o)
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

put

public V put(K key,
             V o)
Specified by:
put in interface Map<K,V>

indexOfKey

public int indexOfKey(Object o)
Returns the index of the specified object based on the key.

Parameters:
o - the key to look for

indexOf

public int indexOf(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(Map<? extends K,? extends V> c)
Specified by:
putAll in interface Map<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>

sort

public void sort(Comparator<Map.Entry<K,V>> cmpr,
                 boolean ascending)
Sorts the data.

Specified by:
sort in interface Sortable<Map.Entry<K,V>>
Parameters:
cmpr - the comparator.
ascending - whether to sort in the ascending order. It is ignored since this implementation uses cmprt to compare.


Copyright © 2011. All Rights Reserved.