Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jtemporal
Class PublishedSortedMap  view PublishedSortedMap download PublishedSortedMap.java

java.lang.Object
  extended byjtemporal.PublishedSortedMap
All Implemented Interfaces:
java.util.Map, java.util.SortedMap

class PublishedSortedMap
extends java.lang.Object
implements java.util.SortedMap

Decorates a SortedMap allowing a single third object to subscribe to updates. That's more efficient in terms of performance than using events and listeners. If you need events and multiple listener, you need to create an intermediate map subscriber class, which creates and dispatches the events.
This class is optimized for the jtemporal use, that's why the class is not public (also some methods not used by JTemporal are not implemented). However with minimal changes, this class can become generic.

Version:
$Id$

Nested Class Summary
private  class PublishedSortedMap.KeySet
           
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
private  java.util.SortedMap map
           
private  MapSubscriber subscriber
           
 
Constructor Summary
PublishedSortedMap(java.util.SortedMap decoratedMap, MapSubscriber sub)
           
 
Method Summary
 void clear()
          Internaly, instead caling clear(); this method iterates and removes all the elements one by one.
 java.util.Comparator comparator()
          Returns the comparator used in sorting this map, or null if it is the keys' natural ordering.
 boolean containsKey(java.lang.Object key)
          Returns true if this contains a mapping for the given key.
 boolean containsValue(java.lang.Object value)
          Returns true if this contains at least one mapping with the given value.
 java.util.Set entrySet()
          Returns a set view of the mappings in this Map.
 boolean equals(java.lang.Object o)
          Compares the specified object with this map for equality.
private  void firePut(java.lang.Object key, java.lang.Object value)
           
private  void fireRemoved(java.lang.Object key)
           
 java.lang.Object firstKey()
          Returns the first (lowest sorted) key in the map.
 java.lang.Object get(java.lang.Object key)
          Returns the value mapped by the given key.
 java.util.SortedMap getDecoratedMap()
           
 MapSubscriber getSubscriber()
           
 int hashCode()
          Returns the hash code for this map.
 java.util.SortedMap headMap(java.lang.Object toKey)
          Returns a view of the portion of the map strictly less than toKey.
 boolean isEmpty()
          Returns true if the map contains no mappings.
 java.util.Set keySet()
          Returns a set view of the keys in this Map.
 java.lang.Object lastKey()
          Returns the last (highest sorted) key in the map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the given key to the given value (optional operation).
 void putAll(java.util.Map t)
          Copies all entries of the given map to this one (optional operation).
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key if present (optional operation).
 int size()
          Returns the number of key-value mappings in the map.
 java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
          Returns a view of the portion of the map greater than or equal to fromKey, and strictly less than toKey.
 java.util.SortedMap tailMap(java.lang.Object fromKey)
          Returns a view of the portion of the map greater than or equal to fromKey.
 java.util.Collection values()
          Returns a collection (or bag) view of the values in this Map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private final java.util.SortedMap map

subscriber

private final MapSubscriber subscriber
Constructor Detail

PublishedSortedMap

public PublishedSortedMap(java.util.SortedMap decoratedMap,
                          MapSubscriber sub)
Method Detail

getDecoratedMap

public java.util.SortedMap getDecoratedMap()

getSubscriber

public MapSubscriber getSubscriber()

firePut

private void firePut(java.lang.Object key,
                     java.lang.Object value)

fireRemoved

private void fireRemoved(java.lang.Object key)

comparator

public java.util.Comparator comparator()
Description copied from interface: java.util.SortedMap
Returns the comparator used in sorting this map, or null if it is the keys' natural ordering.

Specified by:
comparator in interface java.util.SortedMap

firstKey

public java.lang.Object firstKey()
Description copied from interface: java.util.SortedMap
Returns the first (lowest sorted) key in the map.

Specified by:
firstKey in interface java.util.SortedMap

lastKey

public java.lang.Object lastKey()
Description copied from interface: java.util.SortedMap
Returns the last (highest sorted) key in the map.

Specified by:
lastKey in interface java.util.SortedMap

size

public int size()
Description copied from interface: java.util.Map
Returns the number of key-value mappings in the map. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE.

Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Description copied from interface: java.util.Map
Returns true if the map contains no mappings.

Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: java.util.Map
Returns true if this contains a mapping for the given key.

Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: java.util.Map
Returns true if this contains at least one mapping with the given value. In other words, returns true if a value v exists where (value == null ? v == null : value.equals(v)). This usually requires linear time.

Specified by:
containsValue in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: java.util.Map
Returns the value mapped by the given key. Returns null if there is no mapping. However, in Maps that accept null values, you must rely on containsKey to determine if a mapping exists.

Specified by:
get in interface java.util.Map

equals

public boolean equals(java.lang.Object o)
Description copied from interface: java.util.Map
Compares the specified object with this map for equality. Returns true if the other object is a Map with the same mappings, that is,
o instanceof Map && entrySet().equals(((Map) o).entrySet(); This allows comparison of maps, regardless of implementation.

Specified by:
equals in interface java.util.Map

hashCode

public int hashCode()
Description copied from interface: java.util.Map
Returns the hash code for this map. This is the sum of all hashcodes for each Map.Entry object in entrySet. This allows comparison of maps, regardless of implementation, and satisfies the contract of Object.hashCode.

Specified by:
hashCode in interface java.util.Map

subMap

public java.util.SortedMap subMap(java.lang.Object fromKey,
                                  java.lang.Object toKey)
Description copied from interface: java.util.SortedMap
Returns a view of the portion of the map greater than or equal to fromKey, and strictly less than toKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of fromKey and toKey. Note that the lower endpoint is included, but the upper is not; if you want to change the inclusion or exclusion of an endpoint, pass its successor object in instead. For example, for Integers, you could request subMap(new Integer(lowlimit.intValue() + 1), new Integer(highlimit.intValue() + 1)) to reverse the inclusiveness of both endpoints.

Specified by:
subMap in interface java.util.SortedMap

headMap

public java.util.SortedMap headMap(java.lang.Object toKey)
Description copied from interface: java.util.SortedMap
Returns a view of the portion of the map strictly less than toKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of toKey. Note that the endpoint, toKey, is not included; if you want this value to be included, pass its successor object in to toKey. For example, for Integers, you could request headMap(new Integer(limit.intValue() + 1)).

Specified by:
headMap in interface java.util.SortedMap

tailMap

public java.util.SortedMap tailMap(java.lang.Object fromKey)
Description copied from interface: java.util.SortedMap
Returns a view of the portion of the map greater than or equal to fromKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of fromKey. Note that the endpoint, fromKey, is included; if you do not want this value to be included, pass its successor object in to fromKey. For example, for Integers, you could request tailMap(new Integer(limit.intValue() + 1)).

Specified by:
tailMap in interface java.util.SortedMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: java.util.Map
Associates the given key to the given value (optional operation). If the map already contains the key, its value is replaced. Be aware that in a map that permits null values, a null return does not always imply that the mapping was created.

Specified by:
put in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: java.util.Map
Removes the mapping for this key if present (optional operation). If the key is not present, this returns null. Note that maps which permit null values may also return null if the key was removed.

Specified by:
remove in interface java.util.Map

clear

public void clear()
Internaly, instead caling clear(); this method iterates and removes all the elements one by one. That allows a subscriber to receive the detail of the deletions.

Specified by:
clear in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Description copied from interface: java.util.Map
Copies all entries of the given map to this one (optional operation). If the map already contains a key, its value is replaced.

Specified by:
putAll in interface java.util.Map

keySet

public java.util.Set keySet()
Description copied from interface: java.util.Map
Returns a set view of the keys in this Map. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.

Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Description copied from interface: java.util.Map
Returns a collection (or bag) view of the values in this Map. The collection is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the collection supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Collection.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this collection.

Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Description copied from interface: java.util.Map
Returns a set view of the mappings in this Map. Each element in the set is a Map.Entry. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.

Specified by:
entrySet in interface java.util.Map