displayablecollections
Class DisplayableHashMap<K,V>

java.lang.Object
  extended by java.util.Observable
      extended by displayablecollections.DisplayableHashMap<K,V>
All Implemented Interfaces:
DisplayableMap<K,V>, java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>
Direct Known Subclasses:
DisplayableLinkedHashMap

public class DisplayableHashMap<K,V>
extends java.util.Observable
implements java.lang.Cloneable, java.io.Serializable

A DisplayableHashMap encapsulates a HashMap and allows it to be displayed by a JList

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface displayablecollections.DisplayableMap
DisplayableMap.MapChangedNotification<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
DisplayableHashMap()
          Constructs a new empty Map
DisplayableHashMap(int initialCapacity)
          Constructs a new empty Map with the specified initial capacity
DisplayableHashMap(int initialCapacity, float loadFactor)
          Constructs a new empty Map with the specified initial capacity and load factor
DisplayableHashMap(java.util.Map<? extends K,? extends V> m)
          Constructs a new Map containing the mappings in the specified map
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns a set view of the mappings contained in this map.
 boolean equals(java.lang.Object o)
           
 V get(java.lang.Object key)
           
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
          Returns a set view of the keys contained in this map.
 javax.swing.ListModel listModel()
          Create a list model for displaying this map's values in a JList.
 V put(K key, V value)
           
 void putAll(java.util.Map<? extends K,? extends V> t)
           
 V remove(java.lang.Object key)
           
 int size()
           
 javax.swing.ListModel valueOrderedListModel()
          Create a list model for displaying the values in this map in a JList.
 javax.swing.ListModel valueOrderedListModel(java.util.Comparator<V> comparator)
          Create a list model for displaying the values in this map in a JList.
 java.util.Collection<V> values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface displayablecollections.DisplayableMap
addObserver, deleteObservers
 

Constructor Detail

DisplayableHashMap

public DisplayableHashMap()
Constructs a new empty Map


DisplayableHashMap

public DisplayableHashMap(int initialCapacity)
Constructs a new empty Map with the specified initial capacity

Parameters:
initialCapacity - the initial capacity

DisplayableHashMap

public DisplayableHashMap(int initialCapacity,
                          float loadFactor)
Constructs a new empty Map with the specified initial capacity and load factor

Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor

DisplayableHashMap

public DisplayableHashMap(java.util.Map<? extends K,? extends V> m)
Constructs a new Map containing the mappings in the specified map

Parameters:
m - the Map whose mappings are to be placed in the Map
Method Detail

listModel

public javax.swing.ListModel listModel()
Description copied from interface: DisplayableMap
Create a list model for displaying this map's values in a JList. The result of calling toString() is what will actually be displayed for each. There will be no necessary connection between the order of display and any order in the map, since this method can be invoked on any map implementing this interface. (The method valueOrderedListModel specified below can be used with any map if it is desired to display the values in some order based on their natural order or that induced by a specified comparator. For maps having an inherent order of keys, keyOrderedListModel can also be used to display the values in an order corresponding to the order of the keys.)

Specified by:
listModel in interface DisplayableMap<K,V>
See Also:
valueOrderedListModel() in this interface and keyOrderedListModel in DisplayableSortedMap

valueOrderedListModel

public javax.swing.ListModel valueOrderedListModel()
Description copied from interface: DisplayableMap
Create a list model for displaying the values in this map in a JList. The result of calling toString() is what will actually be displayed for each. The values will be displayed in an order determined by the natural order of the values

Specified by:
valueOrderedListModel in interface DisplayableMap<K,V>

valueOrderedListModel

public javax.swing.ListModel valueOrderedListModel(java.util.Comparator<V> comparator)
Description copied from interface: DisplayableMap
Create a list model for displaying the values in this map in a JList. The result of calling toString() is what will actually be displayed for each. The values will be displayed in an order determined by the specified comparator

Specified by:
valueOrderedListModel in interface DisplayableMap<K,V>
Parameters:
comparator - the comparator to use

clear

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

containsKey

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

containsValue

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

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Description copied from interface: DisplayableMap
Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

The set returned by this method will actually be of a class that implements DisplayableSet, and can be safely cast to this type. Any observers added to the set will be notified of changes in the map through any of the map's methods and vice versa.

Specified by:
entrySet in interface DisplayableMap<K,V>
Specified by:
entrySet in interface java.util.Map<K,V>
Returns:
a set view of the mappings contained in this map.

equals

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

get

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

hashCode

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

isEmpty

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

keySet

public java.util.Set<K> keySet()
Description copied from interface: DisplayableMap
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, `which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

The set returned by this method will actually be of a class that implements DisplayableSet, and can be safely cast to this type. Any observers added to the set will be notified of changes in the map through any of the map's methods and vice versa.

Specified by:
keySet in interface DisplayableMap<K,V>
Specified by:
keySet in interface java.util.Map<K,V>
Returns:
a set view of the keys contained in this map.

put

public V put(K key,
             V value)
Specified by:
put in interface java.util.Map<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> t)
Specified by:
putAll in interface java.util.Map<K,V>

remove

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

size

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

values

public java.util.Collection<V> values()
Returns a collection view of the values contained in this map. The collection returned by this method is immutable because, in general, there is no way to determine the key corresponding to a value that was removed, which is required when notifying observers of this map.

Specified by:
values in interface DisplayableMap<K,V>
Specified by:
values in interface java.util.Map<K,V>
Returns:
a collection view of the values contained in this map.