org.deduced
Class PropertyMap<K,V>

java.lang.Object
  extended by org.deduced.AbstractPropertyCollection<K,V>
      extended by org.deduced.PropertyMap<K,V>
Type Parameters:
K - the type of key in the map
V - the type of value in the map
All Implemented Interfaces:
java.lang.Cloneable, PropertyCollection<K,V>
Direct Known Subclasses:
DynamicPropertyMap, IdPropertyMap

public class PropertyMap<K,V>
extends AbstractPropertyCollection<K,V>

A property map represents a property collection in which properties may be added, changed and removed. The keys aren't specified, so it's up to the user of the property map to specify the keys he wants to use in this map.

Some specialization exists where the object instance ID is used as a fixed key so that there is no need to specify the key. (IdPropertyMap and PropertyList)

Author:
Steve McDuff

Nested Class Summary
protected  class PropertyMap.PropertyIterator
           Title: PropertyIterator
protected  class PropertyMap.ValueIterator
           Title: ValueIterator
 
Nested classes/interfaces inherited from class org.deduced.AbstractPropertyCollection
AbstractPropertyCollection.CollectionToDeleteMonitor
 
Field Summary
private  PropertyCollection<?,?> fixedInstance
          the instance hooked to all the values in this map
static PropertyCollectionTypeHolder PROPERTY_MAP_TYPE
          property map type
private  java.util.Map<K,Property<V>> propertyMap
          the array Map containing all the properties
private static long serialVersionUID
          the serial version
 
Fields inherited from class org.deduced.AbstractPropertyCollection
CHECK_DELETE_MODE_AUTOMATIC, CHECK_DELETE_MODE_MANUAL, COLLECTION_TO_DELETE
 
Fields inherited from interface org.deduced.PropertyCollection
PROPERTY_COLLECTION_TYPE
 
Constructor Summary
  PropertyMap()
          constructor for the property map
protected PropertyMap(java.util.Map<K,Property<V>> mapToUse, PropertyCollection<?,?> setFixedInstance)
          constructor for the property map
  PropertyMap(PropertyCollection<?,?> setFixedInstance)
          constructor for the property map
 
Method Summary
 K addProperty(K key, PropertyCollection<?,?> instance, V value)
          (non-Javadoc)
 boolean areKeysAssignedAutomatically()
          (non-Javadoc)
 java.util.Set<K> asKeySet()
          (non-Javadoc)
protected  void cleanNewlyClonedValue(AbstractPropertyCollection<K,V> newClone)
          (non-JSDoc)
 java.lang.Object clone()
          (non-Javadoc)
 boolean containsKey(java.lang.Object key)
          (non-Javadoc)
 PropertyCollection<?,?> getFixedInstance()
          (non-Javadoc)
 Property<V> getProperty(java.lang.Object propertyKey)
          (non-Javadoc)
 V getPropertyValue(java.lang.Object key)
          (non-Javadoc)
protected  void handleRemovedProperty(java.lang.Object propertyKey, Property<V> removedProperty)
          handleRemovedProperty
protected  K internalAddProperty(K propertyKey, Property<V> resultAdd)
          internalAddProperty internally add a property to the map.
protected  boolean internalIsSetValueParentNecessary(V newValue, boolean isReference)
          check if set value parent is necessary
protected  Property<V> internalRemoveProperty(java.lang.Object propertyKey)
          Internal method used to remove a property from the map.
protected  void internalSetValueParentIfNecessary(K propertyKey, V newValue, boolean isReference)
          internal Set the parent on the new value If Necessary
 boolean isFixedInstanceReference()
          is Fixed Instance Reference
 java.util.Iterator<Property<V>> iterator()
          (non-Javadoc)
 java.util.Iterator<V> iteratorByValue()
          (non-Javadoc)
protected  void putPropertyInMap(K propertyKey, Property<V> resultAdd)
          put Property In Map
 Property<V> removeProperty(java.lang.Object propertyKey)
          (non-Javadoc)
 Property<V> removePropertyInstance(V instance)
          (non-Javadoc)
 Property<V> removePropertyValue(V value)
          (non-Javadoc)
protected  void resetRemovedPropertyParent(PropertyCollection<?,?> instance, V value)
          reset Removed Property Parent
 void setFixedInstance(PropertyCollection<?,?> instance)
          (non-JSDoc)
 V setProperty(K propertyKey, V value)
          (non-Javadoc)
 int size()
          (non-Javadoc)
 PropertyCollection<?,?> type()
          (non-Javadoc)
protected  void validateCollectionParentBeforeAddition(PropertyCollection<?,?> newCollection)
          validate Collection Parent Before Addition
 
Methods inherited from class org.deduced.AbstractPropertyCollection
activate, addListener, asPropertyList, asPropertyMap, asValueList, asValueMap, callObjectClone, classLogger, clear, clearCollectionMonitoredForDelete, cloneCollection, containsInstance, containsValue, createUniqueID, delete, deleteClearAllProperties, deleteClearListenerList, deleteFireDeleteEvent, deleteProcessCompletedValidation, deleteRemoveLocalObjectFromParent, deleteValidateEmptyListenerList, deleteValidateNoPendingReferences, equals, firePropertyChangeEvent, flushCollectionsWithNewParent, flushCollectionsWithNewParent, getActionInvoker, getCheckDeleteMode, getCheckDeleteRunner, getInstanceIdentityKey, hashCode, id, instanceKey, internalFirePropertyChangeEvent, invokeAction, isActivated, isDeleteCheckedOnClearParent, isEmpty, isListenerRegistered, isParentOrKeyNull, keyOnParent, parent, removeListener, requiresChangeEvent, setActionInvoker, setCheckDeleteMode, setCheckDeleteRunner, setDeleteCheckedOnClearParent, setParent, toString, updateReference, updateReferenceWithReferenceFlag, validateAllPropertyInstances, validateNoListener, validateNoParentRecursion, validateParentIsNull, validateParentIsNull, valueKey
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
the serial version

See Also:
Constant Field Values

PROPERTY_MAP_TYPE

public static final PropertyCollectionTypeHolder PROPERTY_MAP_TYPE
property map type


propertyMap

private java.util.Map<K,Property<V>> propertyMap
the array Map containing all the properties


fixedInstance

private PropertyCollection<?,?> fixedInstance
the instance hooked to all the values in this map

Constructor Detail

PropertyMap

public PropertyMap()
constructor for the property map


PropertyMap

public PropertyMap(PropertyCollection<?,?> setFixedInstance)
constructor for the property map

Parameters:
setFixedInstance - instance of objects contained by this map

PropertyMap

protected PropertyMap(java.util.Map<K,Property<V>> mapToUse,
                      PropertyCollection<?,?> setFixedInstance)
constructor for the property map

Parameters:
mapToUse - the map implementation to use while storing properties
setFixedInstance - the fixed instance used by this map
Method Detail

setFixedInstance

public void setFixedInstance(PropertyCollection<?,?> instance)
(non-JSDoc)

Specified by:
setFixedInstance in interface PropertyCollection<K,V>
Overrides:
setFixedInstance in class AbstractPropertyCollection<K,V>
Parameters:
instance - the new fixed instance
See Also:
PropertyCollection.setFixedInstance(org.deduced.PropertyCollection)

getProperty

public Property<V> getProperty(java.lang.Object propertyKey)
(non-Javadoc)

Parameters:
propertyKey - the property key
Returns:
the property, null if the get failed
See Also:
PropertyCollection.getProperty(java.lang.Object)

removeProperty

public Property<V> removeProperty(java.lang.Object propertyKey)
(non-Javadoc)

Parameters:
propertyKey - the key of the property
Returns:
the removed property, null if remove failed
See Also:
PropertyCollection.removeProperty(java.lang.Object)

internalRemoveProperty

protected Property<V> internalRemoveProperty(java.lang.Object propertyKey)
Internal method used to remove a property from the map. The caller of this method is responsible to unregister references and send the remove property change event.

Parameters:
propertyKey - the property key to remove
Returns:
the removed property

handleRemovedProperty

protected void handleRemovedProperty(java.lang.Object propertyKey,
                                     Property<V> removedProperty)
handleRemovedProperty

Parameters:
propertyKey - the removed property key
removedProperty - the removed property

resetRemovedPropertyParent

protected void resetRemovedPropertyParent(PropertyCollection<?,?> instance,
                                          V value)
reset Removed Property Parent

Parameters:
instance - property instance
value - property value

setProperty

public V setProperty(K propertyKey,
                     V value)
(non-Javadoc)

Parameters:
propertyKey - the key of the property
value - the new value of the property. If the property is a collection that is not by reference, this method requires that the passed collection has a parent set to null since it will reset the parent.
Returns:
the added value instance
See Also:
PropertyCollection.setProperty(java.lang.Object, java.lang.Object)

isFixedInstanceReference

public boolean isFixedInstanceReference()
is Fixed Instance Reference

Returns:
true if the fixed instance is a reference

internalAddProperty

protected K internalAddProperty(K propertyKey,
                                Property<V> resultAdd)
internalAddProperty internally add a property to the map. This method checks that the added property conforms to the fixed instance that must be held in this map. It also checks that the property isn't already contained in the map. This method fires property change events when the operation is completed

Parameters:
propertyKey - the key of the added property
resultAdd - the property to add to the map
Returns:
the added property value

internalSetValueParentIfNecessary

protected void internalSetValueParentIfNecessary(K propertyKey,
                                                 V newValue,
                                                 boolean isReference)
internal Set the parent on the new value If Necessary

Parameters:
propertyKey - the property key of the new value
newValue - the new value
isReference - is the new value a reference

validateCollectionParentBeforeAddition

protected void validateCollectionParentBeforeAddition(PropertyCollection<?,?> newCollection)
validate Collection Parent Before Addition

Parameters:
newCollection - the collection to add

internalIsSetValueParentNecessary

protected boolean internalIsSetValueParentNecessary(V newValue,
                                                    boolean isReference)
check if set value parent is necessary

Parameters:
newValue - the new value
isReference - is the new value a reference
Returns:
true if we must set the new value parent

putPropertyInMap

protected void putPropertyInMap(K propertyKey,
                                Property<V> resultAdd)
put Property In Map

Parameters:
propertyKey - the key to add
resultAdd - the property to add

size

public int size()
(non-Javadoc)

Returns:
the collection size
See Also:
PropertyCollection.size()

clone

public java.lang.Object clone()
(non-Javadoc)

Specified by:
clone in interface PropertyCollection<K,V>
Overrides:
clone in class AbstractPropertyCollection<K,V>
Returns:
the object clone
See Also:
Object.clone()

cleanNewlyClonedValue

protected void cleanNewlyClonedValue(AbstractPropertyCollection<K,V> newClone)
(non-JSDoc)

Overrides:
cleanNewlyClonedValue in class AbstractPropertyCollection<K,V>
Parameters:
newClone - the newly created clone of the current collection
See Also:
AbstractPropertyCollection.cleanNewlyClonedValue(org.deduced.AbstractPropertyCollection)

iterator

public java.util.Iterator<Property<V>> iterator()
(non-Javadoc)

Returns:
an iterator that iterates through the Property objects
See Also:
PropertyCollection.iterator()

getPropertyValue

public V getPropertyValue(java.lang.Object key)
(non-Javadoc)

Parameters:
key - the property key
Returns:
the property value, null if the get failed
See Also:
PropertyCollection.getPropertyValue(java.lang.Object)

iteratorByValue

public java.util.Iterator<V> iteratorByValue()
(non-Javadoc)

Returns:
an iterator that iterates through the Property values
See Also:
PropertyCollection.iteratorByValue()

addProperty

public K addProperty(K key,
                     PropertyCollection<?,?> instance,
                     V value)
(non-Javadoc)

Parameters:
key - the key of the property. Some collections assign keys automatically, for those collections, a null value is expected. If the key is specified when they are assigned automatically, an IllegalArgumentException will be thrown
instance - the property instance to add. Most collections assign the instance automatically, for those collections, the instance can either be null or be the same as the instance that is automatically assigned, otherwise an error will be thrown
value - the property value. If the value is a property collection, then the collection is expected to have a null parent if the instance is owned (not by reference), otherwise an IllegalArgumentException will be thrown
Returns:
the added property key
See Also:
PropertyCollection.addProperty(java.lang.Object, org.deduced.PropertyCollection, java.lang.Object)

getFixedInstance

public PropertyCollection<?,?> getFixedInstance()
Description copied from class: AbstractPropertyCollection
(non-Javadoc)

Specified by:
getFixedInstance in interface PropertyCollection<K,V>
Overrides:
getFixedInstance in class AbstractPropertyCollection<K,V>
Returns:
Returns the fixedInstance.
See Also:
PropertyCollection.getFixedInstance()

containsKey

public boolean containsKey(java.lang.Object key)
(non-Javadoc)

Parameters:
key - the property key
Returns:
true if the key is contained in this collection
See Also:
PropertyCollection.containsKey(java.lang.Object)

asKeySet

public java.util.Set<K> asKeySet()
(non-Javadoc)

Returns:
a list containing all the keys in this property collection
See Also:
PropertyCollection.asKeySet()

type

public PropertyCollection<?,?> type()
(non-Javadoc)

Returns:
the property description
See Also:
PropertyCollection.type()

removePropertyInstance

public Property<V> removePropertyInstance(V instance)
(non-Javadoc)

Parameters:
instance - the object to remove
Returns:
the removed object
See Also:
PropertyCollection.removePropertyInstance(java.lang.Object)

removePropertyValue

public Property<V> removePropertyValue(V value)
(non-Javadoc)

Parameters:
value - the value to remove
Returns:
the removed object
See Also:
PropertyCollection.removePropertyValue(java.lang.Object)

areKeysAssignedAutomatically

public boolean areKeysAssignedAutomatically()
(non-Javadoc)

Returns:
true if the keys are assigned automatically by the collection
See Also:
PropertyCollection.areKeysAssignedAutomatically()