de.cau.cs.kieler.core.properties
Class MapPropertyHolder

java.lang.Object
  extended by de.cau.cs.kieler.core.properties.MapPropertyHolder
All Implemented Interfaces:
IPropertyHolder
Direct Known Subclasses:
FEdge, FGraph, FParticle, LayoutContext, LayoutMapping, LGraphElement, TransformationData

public class MapPropertyHolder
extends Object
implements IPropertyHolder

An abstract holder class for properties that uses a hash map.

Rating yellow
(2011-01-17) reviewed by haf, cmot, soh

Constructor Summary
MapPropertyHolder()
           
 
Method Summary
 void checkProperties(IProperty<?>... newProperties)
          Check for upper and lower bounds.
 void copyProperties(IPropertyHolder other)
          Copy all properties from another property holder to this one.
 Map<IProperty<?>,Object> getAllProperties()
          Returns a map of all assigned properties with associated values.
<T> T
getProperty(Class<T> clazz)
          Retrieves a property value for a given class.
<T> T
getProperty(IProperty<T> property)
          Retrieves a property value.
 void setProperty(IProperty<?> property, Object value)
          Sets a property value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapPropertyHolder

public MapPropertyHolder()
Method Detail

setProperty

public void setProperty(IProperty<?> property,
                        Object value)
Sets a property value. No type checking is performed while setting, so users of this method must take care that the right object types are generated.

Specified by:
setProperty in interface IPropertyHolder
Parameters:
property - the property to set
value - the new value

getProperty

public <T> T getProperty(IProperty<T> property)
Retrieves a property value. If the property is not set, its default value shall be taken, which is taken from the given property instance.

Specified by:
getProperty in interface IPropertyHolder
Type Parameters:
T - type of property
Parameters:
property - the property to get
Returns:
the current value, or the default value if the property is not set

getProperty

public <T> T getProperty(Class<T> clazz)
Retrieves a property value for a given class. If the property holder contains multiple instances of the class, the returned instance is selected arbitrarily. This method is less efficient than getProperty(IProperty), so use it with caution.

Type Parameters:
T - type of property
Parameters:
clazz - a class
Returns:
a contained instance of the class, or null if there is none

copyProperties

public void copyProperties(IPropertyHolder other)
Copy all properties from another property holder to this one.

Specified by:
copyProperties in interface IPropertyHolder
Parameters:
other - another property holder

getAllProperties

public Map<IProperty<?>,Object> getAllProperties()
Returns a map of all assigned properties with associated values.

Specified by:
getAllProperties in interface IPropertyHolder
Returns:
a map of all properties

checkProperties

public void checkProperties(IProperty<?>... newProperties)
Check for upper and lower bounds. If a property value does not fit into the bounds, it is reset to the default value.

Parameters:
newProperties - the properties that shall be checked