Class PropertyMapImpl
- java.lang.Object
-
- net.infonode.properties.propertymap.PropertyMapImpl
-
- All Implemented Interfaces:
PropertyMap,Readable,ReadWritable,Writable
public class PropertyMapImpl extends java.lang.Object implements PropertyMap
-
-
Constructor Summary
Constructors Constructor Description PropertyMapImpl(PropertyMapGroup propertyGroup)PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl superObject)PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl parent, PropertyMapProperty property)PropertyMapImpl(PropertyMapImpl inheritFrom)PropertyMapImpl(PropertyMapImpl parent, PropertyMapProperty property)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(PropertyMapListener listener)Adds a listener that listens for value changes in this PropertyMap.voidaddPropertyChangeListener(Property property, PropertyChangeListener listener)Adds a property listener that listens for value changes for a specific property.voidaddSuperMap(PropertyMap superMap)Adds a super map to this map.voidaddTreeListener(PropertyMapTreeListener listener)Adds a tree listener that listens for value changes in this PropertyMap or any child maps.voidclear(boolean recursive)Removes all property values in this property map.PropertyMapcopy(boolean copySuperMaps, boolean recursive)Creates a copy of this map.java.lang.ObjectcreateRelativeRef(Property fromProperty, PropertyMap toObject, Property toProperty)Creates a relative reference from one property value to another property value.voiddump()voiddump(Printer printer, java.util.Set printed)voiddumpSuperMaps(Printer printer)protected voidfirePropertyTreeValuesChanged(java.util.Map changes)voidfirePropertyValueChanged(Property property, ValueChange change)PropertyMapgetChildMap(PropertyMapProperty property)PropertyMapImplgetChildMapImpl(PropertyMapProperty property)ConstChangeNotifyMapgetMap()PropertyMapImplgetParent()PropertyMapPropertygetProperty()PropertyMapGroupgetPropertyGroup()PropertyMapgetSuperMap()Returns the most recently added super map.intgetSuperMapCount()PropertyValuegetValue(Property property)PropertyValuegetValueWithDefault(Property property)booleanisEmpty(boolean recursive)Returns true if this property map doesn't contain any property values.voidread(java.io.ObjectInputStream in)Reads property values from a stream and sets them in this map.voidremoveListener(PropertyMapListener listener)Removes a listener which was previously added withPropertyMap.addListener(PropertyMapListener).voidremovePropertyChangeListener(Property property, PropertyChangeListener listener)Removes a previously added property listener.PropertyMapremoveSuperMap()Removes the most recently added super map.booleanremoveSuperMap(PropertyMap superMap)Removes a super map that has previously been added usingPropertyMap.addSuperMap(PropertyMap).voidremoveTreeListener(PropertyMapTreeListener listener)Removes a previously added tree listener.java.lang.ObjectremoveValue(Property property)Removes a property value.booleanreplaceSuperMap(PropertyMap oldSuperMap, PropertyMap newSuperMap)Replaces a super map that has previously been added usingPropertyMap.addSuperMap(PropertyMap).PropertyValuesetValue(Property property, PropertyValue value)static voidskip(java.io.ObjectInputStream in)booleanvalueIsSet(Property property)booleanvaluesEqualTo(PropertyMap propertyObject, boolean recursive)Returns true if all the values in this property map is equal to the values in the given map.voidwrite(java.io.ObjectOutputStream out)Serializes the serializable values of this property map.voidwrite(java.io.ObjectOutputStream out, boolean recursive)Serializes the serializable values of this property map.
-
-
-
Constructor Detail
-
PropertyMapImpl
public PropertyMapImpl(PropertyMapGroup propertyGroup)
-
PropertyMapImpl
public PropertyMapImpl(PropertyMapImpl inheritFrom)
-
PropertyMapImpl
public PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl superObject)
-
PropertyMapImpl
public PropertyMapImpl(PropertyMapImpl parent, PropertyMapProperty property)
-
PropertyMapImpl
public PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl parent, PropertyMapProperty property)
-
-
Method Detail
-
getMap
public ConstChangeNotifyMap getMap()
-
getSuperMap
public PropertyMap getSuperMap()
Description copied from interface:PropertyMapReturns the most recently added super map.- Specified by:
getSuperMapin interfacePropertyMap- Returns:
- the super map
-
removeValue
public java.lang.Object removeValue(Property property) throws InvalidPropertyException
Description copied from interface:PropertyMapRemoves a property value.- Specified by:
removeValuein interfacePropertyMap- Parameters:
property- the property- Returns:
- the value removed
- Throws:
InvalidPropertyException- if values for this property can't be stored in this property map
-
createRelativeRef
public java.lang.Object createRelativeRef(Property fromProperty, PropertyMap toObject, Property toProperty)
Description copied from interface:PropertyMapCreates a relative reference from one property value to another property value.When the value of the fromProperty is read, it will return the value of the toProperty in the toMap.
Sub maps of this property map will inherit this reference relative to themselves, ie the reference in the sub map is converted to a reference relative to the sub map if possible, otherwise the reference is the same as for the super map. Here is an example:
- Property map A contains value 5 for property X.
- A relative reference is created in map A from property Y to property X. Getting the property value for Y in A will now return 5.
- A property map B is created and A is added as super map to B. Note that now B.Y will reference B.X and not A.X! Getting B.X now returns 5 and B.Y also returns 5.
- X is set to 7 in B. Getting B.Y will now return 7 as expected. Map A is unchanged and will still return 5 as value for property Y.
- A.Y is set to 1 which destroys the reference to A.X, and also the reference B.Y -> B.X. Getting B.Y will now return 1 as it's inherited from A.Y.
Changes to the referenced property value will be propagated to listeners of this property.
- Specified by:
createRelativeRefin interfacePropertyMap- Parameters:
fromProperty- the property value that will hold the referencetoObject- the property map that holds the property value that is referencedtoProperty- the property which value is referenced- Returns:
- the old value that the fromProperty had in this property map
-
getSuperMapCount
public int getSuperMapCount()
-
addSuperMap
public void addSuperMap(PropertyMap superMap)
Description copied from interface:PropertyMapAdds a super map to this map. If a property value is not found in this property map, the super maps will be searched recursively. The super map last added will be searched first.- Specified by:
addSuperMapin interfacePropertyMap- Parameters:
superMap- the super map
-
removeSuperMap
public PropertyMap removeSuperMap()
Description copied from interface:PropertyMapRemoves the most recently added super map.- Specified by:
removeSuperMapin interfacePropertyMap- Returns:
- the super map removed
-
removeSuperMap
public boolean removeSuperMap(PropertyMap superMap)
Description copied from interface:PropertyMapRemoves a super map that has previously been added usingPropertyMap.addSuperMap(PropertyMap).- Specified by:
removeSuperMapin interfacePropertyMap- Parameters:
superMap- the super map to remove- Returns:
- true if the super map was found and removed, otherwise false
-
replaceSuperMap
public boolean replaceSuperMap(PropertyMap oldSuperMap, PropertyMap newSuperMap)
Description copied from interface:PropertyMapReplaces a super map that has previously been added usingPropertyMap.addSuperMap(PropertyMap).- Specified by:
replaceSuperMapin interfacePropertyMap- Parameters:
oldSuperMap- the super map to replacenewSuperMap- the super map to replace it with- Returns:
- true if the super map was found and replaced, otherwise false
-
addTreeListener
public void addTreeListener(PropertyMapTreeListener listener)
Description copied from interface:PropertyMapAdds a tree listener that listens for value changes in this PropertyMap or any child maps. This listener will be notified of updates to values in this PropertyMap, any child map recusively and super maps unless the property value is overridden.- Specified by:
addTreeListenerin interfacePropertyMap- Parameters:
listener- the listener
-
removeTreeListener
public void removeTreeListener(PropertyMapTreeListener listener)
Description copied from interface:PropertyMapRemoves a previously added tree listener.- Specified by:
removeTreeListenerin interfacePropertyMap- Parameters:
listener- the listener
-
addListener
public void addListener(PropertyMapListener listener)
Description copied from interface:PropertyMapAdds a listener that listens for value changes in this PropertyMap. This listener will be notified of updates to values in this PropertyMap and super maps unless the property value is overridden.- Specified by:
addListenerin interfacePropertyMap- Parameters:
listener- the listener
-
removeListener
public void removeListener(PropertyMapListener listener)
Description copied from interface:PropertyMapRemoves a listener which was previously added withPropertyMap.addListener(PropertyMapListener).- Specified by:
removeListenerin interfacePropertyMap- Parameters:
listener- the listener
-
getPropertyGroup
public PropertyMapGroup getPropertyGroup()
-
addPropertyChangeListener
public void addPropertyChangeListener(Property property, PropertyChangeListener listener)
Description copied from interface:PropertyMapAdds a property listener that listens for value changes for a specific property. This listener will be notified of value changes for the property in this PropertyMap and super maps unless the property value is overridden.- Specified by:
addPropertyChangeListenerin interfacePropertyMap- Parameters:
property- the property to listen to changes onlistener- the listener
-
removePropertyChangeListener
public void removePropertyChangeListener(Property property, PropertyChangeListener listener)
Description copied from interface:PropertyMapRemoves a previously added property listener.- Specified by:
removePropertyChangeListenerin interfacePropertyMap- Parameters:
property- the property which the listener listens to changes onlistener- the listener
-
getParent
public PropertyMapImpl getParent()
-
getProperty
public PropertyMapProperty getProperty()
-
getChildMap
public PropertyMap getChildMap(PropertyMapProperty property)
-
getChildMapImpl
public PropertyMapImpl getChildMapImpl(PropertyMapProperty property)
-
getValueWithDefault
public PropertyValue getValueWithDefault(Property property)
-
getValue
public PropertyValue getValue(Property property)
-
setValue
public PropertyValue setValue(Property property, PropertyValue value)
-
valueIsSet
public boolean valueIsSet(Property property)
-
firePropertyValueChanged
public void firePropertyValueChanged(Property property, ValueChange change)
-
firePropertyTreeValuesChanged
protected void firePropertyTreeValuesChanged(java.util.Map changes)
-
dump
public void dump()
-
dump
public void dump(Printer printer, java.util.Set printed)
-
dumpSuperMaps
public void dumpSuperMaps(Printer printer)
-
clear
public void clear(boolean recursive)
Description copied from interface:PropertyMapRemoves all property values in this property map.- Specified by:
clearin interfacePropertyMap- Parameters:
recursive- true if child maps should be cleared recursively
-
isEmpty
public boolean isEmpty(boolean recursive)
Description copied from interface:PropertyMapReturns true if this property map doesn't contain any property values.- Specified by:
isEmptyin interfacePropertyMap- Parameters:
recursive- true if child maps should be recursively checked- Returns:
- true if this property map doesn't contain any property values
-
write
public void write(java.io.ObjectOutputStream out, boolean recursive) throws java.io.IOExceptionDescription copied from interface:PropertyMapSerializes the serializable values of this property map. Values not implementing theSerializableinterface will not be written to the stream. The properties are identified using their names.- Specified by:
writein interfacePropertyMap- Parameters:
out- the stream on which to serialize this maprecursive- true if child maps should be recursively serialized- Throws:
java.io.IOException- if there is an error in the stream
-
write
public void write(java.io.ObjectOutputStream out) throws java.io.IOExceptionDescription copied from interface:PropertyMapSerializes the serializable values of this property map. Values not implementing the
Serializableinterface will not be written to the stream. The properties are identified using their names.This method recursively writes all child maps.
- Specified by:
writein interfacePropertyMap- Specified by:
writein interfaceWritable- Parameters:
out- the stream- Throws:
java.io.IOException- if there is a stream error
-
read
public void read(java.io.ObjectInputStream in) throws java.io.IOExceptionDescription copied from interface:PropertyMapReads property values from a stream and sets them in this map. Will overwrite existing values, but not remove values not found in the stream. The properties are identified using their names. If no property is found for a property name read from the stream the value is skipped and no error is reported. If a value for a property in the stream is a reference to a another property value that cannot be resolved, the property is not modified.- Specified by:
readin interfacePropertyMap- Specified by:
readin interfaceReadable- Parameters:
in- the stream from which to read property values- Throws:
java.io.IOException- if there is an error in the stream
-
skip
public static void skip(java.io.ObjectInputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
valuesEqualTo
public boolean valuesEqualTo(PropertyMap propertyObject, boolean recursive)
Description copied from interface:PropertyMapReturns true if all the values in this property map is equal to the values in the given map. The property values are compared usingObject.equals(java.lang.Object).- Specified by:
valuesEqualToin interfacePropertyMap- Parameters:
propertyObject- the map to compare values withrecursive- true if child maps should be recursively checked- Returns:
- true if all the values in this property map is equal to the values in the given map
-
copy
public PropertyMap copy(boolean copySuperMaps, boolean recursive)
Description copied from interface:PropertyMapCreates a copy of this map. The method copies the values and optionally the references to super maps.- Specified by:
copyin interfacePropertyMap- Parameters:
copySuperMaps- if true, copies the references to super mapsrecursive- if true, copies all child maps as well- Returns:
- a copy of this map
-
-