com.sibvisions.util
Class ChangedHashtable<K,V>

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<K,V>
          extended by com.sibvisions.util.ChangedHashtable<K,V>
Type Parameters:
K - the key class
V - the value class
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class ChangedHashtable<K,V>
extends Hashtable<K,V>

The ChangedHashtable is a synchronized Hashtable which tracks changes to keys and values. Synchronized means that the operations are synchronized themselve.

The changes are available as key/value list, for other operations.

See Also:
Serialized Form

Constructor Summary
ChangedHashtable()
           
 
Method Summary
 void clear()
          Clears this hashtable so that it contains no keys.
 void clearChanges()
          Clears the list of changed mappings.
 List<Map.Entry<K,V>> getChanges(Class<? extends V>... pValueType)
          Gets the tracked changes of this Hashtable but return only the values with a specified class type.
 List<Map.Entry<K,V>> getLastChanges()
          Gets the last tracked changes of this Hashtable but return only the values with a specified class type.
 List<Map.Entry<K,V>> getMapping(Class<? extends V>... pValueType)
          Gets a list of entries but only includes the values of a specific type.
 boolean isChanged(K pKey)
          Checks if a the value of a property is currently marked as changed.
 V put(K pKey, V pValue)
          Maps the specified key to the specified value in this hashtable.
 V put(K pKey, V pValue, boolean pTrackChanges)
          Maps the specified key to the specified value in this hashtable with optional tracking of changes.
 V put(K pKey, V pValue, boolean pTrackChanges, boolean pOverride)
          Maps the specified key to the specified value in this hashtable with optional tracking of changes.
 V remove(Object pKey)
          Removes the key (and its corresponding value) from this hashtable.
 V remove(Object pKey, boolean pTrackChanges)
          Removes the key (and its corresponding value) from this hashtable with optional tracking of changes.
 V remove(Object pKey, boolean pTrackChanges, boolean pOverride)
          Removes the key (and its corresponding value) from this hashtable with optional tracking of changes.
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChangedHashtable

public ChangedHashtable()
Method Detail

put

public V put(K pKey,
             V pValue)
Maps the specified key to the specified value in this hashtable. If the pValue is null, the pKey will removed from this hashtable, if present.

This method tracks all changes to the hashtable.

Specified by:
put in interface Map<K,V>
Overrides:
put in class Hashtable<K,V>
Parameters:
pKey - the key with which the specified value is to be associated
pValue - the value to be associated with the specified key
Returns:
the previous value of the specified pKey in this hashtable, or null if it did not have one.

remove

public V remove(Object pKey)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.

This method tracks all changes to the hashtable.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class Hashtable<K,V>
Parameters:
pKey - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.
Throws:
NullPointerException - if the key is null.

clear

public void clear()
Clears this hashtable so that it contains no keys. All keys will be tracked as changed.

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class Hashtable<K,V>

put

public V put(K pKey,
             V pValue,
             boolean pTrackChanges)
Maps the specified key to the specified value in this hashtable with optional tracking of changes.

Parameters:
pKey - the key with which the specified value is to be associated
pValue - the value to be associated with the specified key
pTrackChanges - true to track all changes to the hashtable
Returns:
the previous value of the specified pKey in this hashtable, or null if it did not have one.

put

public V put(K pKey,
             V pValue,
             boolean pTrackChanges,
             boolean pOverride)
Maps the specified key to the specified value in this hashtable with optional tracking of changes.

Parameters:
pKey - the key with which the specified value is to be associated
pValue - the value to be associated with the specified key
pTrackChanges - true to track all changes to the hashtable
pOverride - true to track changes, if pTrackChanges = true independent of the old value
Returns:
the previous value of the specified pKey in this hashtable, or null if it did not have one.

remove

public V remove(Object pKey,
                boolean pTrackChanges)
Removes the key (and its corresponding value) from this hashtable with optional tracking of changes. This method does nothing if the key is not in the hashtable.

Parameters:
pKey - the key that needs to be removed.
pTrackChanges - true to track all changes to the hashtable
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.
Throws:
NullPointerException - if the key is null.

remove

public V remove(Object pKey,
                boolean pTrackChanges,
                boolean pOverride)
Removes the key (and its corresponding value) from this hashtable with optional tracking of changes. This method does nothing if the key is not in the hashtable.

Parameters:
pKey - the key that needs to be removed.
pTrackChanges - true to track all changes to the hashtable
pOverride - true to track changes, if pTrackChanges = true independent of the old value
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.
Throws:
NullPointerException - if the key is null.

getChanges

public List<Map.Entry<K,V>> getChanges(Class<? extends V>... pValueType)
Gets the tracked changes of this Hashtable but return only the values with a specified class type. If the Hashtable contains Object types as values, then you can return all values with Integer types or String types: ChangedHashtable<String, Object> table = new ChangedHashtable<String, Object>(); List<Entry<String, Object>> changes = table.getChanges(String.class);

ALL changes will be reset.

Parameters:
pValueType - missing or null to return all values, or a list of class types to return the values with this class types. (null values are always included)
Returns:
the changed key/values as Map.Entry list or null if there are no changes

getLastChanges

public List<Map.Entry<K,V>> getLastChanges()
Gets the last tracked changes of this Hashtable but return only the values with a specified class type. If the Hashtable contains Object types as values, then you can return all values with Integer types or String types: ChangedHashtable<String, Object> table = new ChangedHashtable<String, Object>(); List<Entry<String, Object>> changes = table.getChanges(String.class);

ALL changes will be reset.

Returns:
the changed key/values as Map.Entry list or null if there are no changes

clearChanges

public void clearChanges()
Clears the list of changed mappings.


getMapping

public List<Map.Entry<K,V>> getMapping(Class<? extends V>... pValueType)
Gets a list of entries but only includes the values of a specific type. If the Hashtable contains Object types as values, then you can return all values with Integer types or String types: ChangedHashtable<String, Object> table = new ChangedHashtable<String, Object>(); List<Entry<String, Object>> changes = table.getMapping(String.class);

Parameters:
pValueType - missing or null to return all values, or a list of class types to return the values with this class types. (null values are always included)
Returns:
the current key/values as Map.Entry list

isChanged

public boolean isChanged(K pKey)
Checks if a the value of a property is currently marked as changed.

Parameters:
pKey - the property name
Returns:
true if the property value has changed since last access
See Also:
getChanges(Class...), getLastChanges()


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.