displayablecollections
Class DisplayableTreeMap<K,V>

java.lang.Object
  extended by java.util.Observable
      extended by displayablecollections.DisplayableTreeMap<K,V>
All Implemented Interfaces:
DisplayableMap<K,V>, DisplayableSortedMap<K,V>, java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>, java.util.SortedMap<K,V>

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

A DisplayableTreeMap encapsulates a TreeMap 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
DisplayableTreeMap()
          Constructs a new empty Map
DisplayableTreeMap(java.util.Comparator<? super K> c)
          Constructs a new empty Map according to the specified comparator
DisplayableTreeMap(java.util.Map<? extends K,? extends V> m)
          Constructs a new Map containing the same mappings as the given map, sorted according to the key's natural order
DisplayableTreeMap(java.util.SortedMap<? extends K,? extends V> s)
          Constructs a new Map containing the same elements as the specified Map, sorted according to the same ordering
 
Method Summary
 void clear()
           
 java.util.Comparator<? super K> comparator()
           
 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)
           
 K firstKey()
           
 V get(java.lang.Object key)
           
 int hashCode()
           
 java.util.SortedMap<K,V> headMap(K toKey)
          Returns a view of the portion of this sorted map whose keys are strictly less than toKey.
 boolean isEmpty()
           
 javax.swing.ListModel keyOrderedListModel()
          Create a list model for displaying the values in this map in a JList.
 java.util.Set<K> keySet()
          Returns a set view of the keys contained in this map.
 K lastKey()
           
 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()
           
 java.util.SortedMap<K,V> subMap(K fromKey, K toKey)
          Returns a view of the portion of this sorted map whose keys range from fromKey, inclusive, to toKey, exclusive.
 java.util.SortedMap<K,V> tailMap(K fromKey)
          Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey.
 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, entrySet, keySet, listModel, valueOrderedListModel, valueOrderedListModel, values
 
Methods inherited from interface java.util.SortedMap
entrySet, keySet, values
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size
 

Constructor Detail

DisplayableTreeMap

public DisplayableTreeMap()
Constructs a new empty Map


DisplayableTreeMap

public DisplayableTreeMap(java.util.Comparator<? super K> c)
Constructs a new empty Map according to the specified comparator

Parameters:
c - the comparator

DisplayableTreeMap

public DisplayableTreeMap(java.util.Map<? extends K,? extends V> m)
Constructs a new Map containing the same mappings as the given map, sorted according to the key's natural order

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

DisplayableTreeMap

public DisplayableTreeMap(java.util.SortedMap<? extends K,? extends V> s)
Constructs a new Map containing the same elements as the specified Map, sorted according to the same ordering

Parameters:
s - the Map whose elements are to be placed in the Map
Method Detail

keyOrderedListModel

public javax.swing.ListModel keyOrderedListModel()
Description copied from interface: DisplayableSortedMap
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 the order of their keys.

Specified by:
keyOrderedListModel in interface DisplayableSortedMap<K,V>

comparator

public java.util.Comparator<? super K> comparator()
Specified by:
comparator in interface java.util.SortedMap<K,V>

firstKey

public K firstKey()
Specified by:
firstKey in interface java.util.SortedMap<K,V>

headMap

public java.util.SortedMap<K,V> headMap(K toKey)
Description copied from interface: DisplayableSortedMap
Returns a view of the portion of this sorted map whose keys are strictly less than toKey. The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned map supports all optional map operations that this sorted map supports.

The sorted map returned by this method implements the DisplayableSortedMap interface to support enabling this map to notify its observers of changes made through the headMap; but the headMap itself cannot have observers of its own. Attempting to add an observer to the headMap will result in an UnsupportedOperation exception.

Specified by:
headMap in interface DisplayableSortedMap<K,V>
Specified by:
headMap in interface java.util.SortedMap<K,V>
Parameters:
toKey - - high endpoint (exclusive) of the headMap
Returns:
a view of the specified initial range of this sorted map.

lastKey

public K lastKey()
Specified by:
lastKey in interface java.util.SortedMap<K,V>

subMap

public java.util.SortedMap<K,V> subMap(K fromKey,
                                       K toKey)
Description copied from interface: DisplayableSortedMap
Returns a view of the portion of this sorted map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are equal, the returned sorted map is empty.) The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned Map supports all optional map operations that this sorted map supports.

The sorted map returned by this method implements the DisplayableSortedMap interface to support enabling this map to notify its observers of changes made through the subMap; but the subMap itself cannot have observers of its own. Attempting to add an observer to the subMap will result in an UnsupportedOperation exception.

Specified by:
subMap in interface DisplayableSortedMap<K,V>
Specified by:
subMap in interface java.util.SortedMap<K,V>
Parameters:
fromKey - - low endpoint (inclusive) of the subMap.
toKey - - high endpoint (exclusive) of the subMap.
Returns:
a view of the specified initial range of this sorted map.

tailMap

public java.util.SortedMap<K,V> tailMap(K fromKey)
Description copied from interface: DisplayableSortedMap
Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey. The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned map supports all optional map operations that this sorted map supports.

The sorted map returned by this method implements the DisplayableSortedMap interface to support enabling this map to notify its observers of changes made through the tailMap; but the tailMap itself cannot have observers of its own. Attempting to add an observer to the tailMap will result in an UnsupportedOperation exception.

Specified by:
tailMap in interface DisplayableSortedMap<K,V>
Specified by:
tailMap in interface java.util.SortedMap<K,V>
Parameters:
fromKey - - low endpoint (inclusive) of the tailMap.
Returns:
a view of the specified initial range of this sorted map.

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.