public class TLcdModelHeightProviderFactoryUtil extends Object
ILcdModelHeightProviderFactory
. The methods simplify handling
required and optional properties.
A height provider factory could use the convenience methods as follows, when implementing the interface:
public ILcdHeightProvider createHeightProvider(ILcdModel aModel,
Map<String, Object> aRequiredPropertiesSFCT,
Map<String, Object> aOptionalProperties)
throws TLcdMissingPropertyException, TLcdUnsupportedPropertyException {
// Retrieve a property that is necessary for this height provider.
// Throw a TLcdMissingPropertyException if it is missing.
Integer someProperty1 = (Integer)TLcdModelHeightProviderFactoryUtil.
retrieveNecessaryProperty(KEY_SOME_PROPERTY1, aRequiredPropertiesSFCT, aOptionalProperties);
...
// Retrieve a property that is just a hint for this height provider.
Integer someProperty2 = (Integer)TLcdModelHeightProviderFactoryUtil.
retrieveProperty(KEY_SOME_PROPERTY2, aRequiredPropertiesSFCT, aOptionalProperties);
if (someProperty2 != null) {
...
}
// Delegate to another height provider factory.
ILcdModelHeightProviderFactory delegateFactory = ...;
Map<String, Object> requiredProperties = TLcdModelHeightProviderFactoryUtil.
copyProperties(aRequiredPropertiesSFCT);
ILcdHeightProvider heightProvider =
delegateFactory.createHeightProvider(aModel, requiredProperties, aOptionalProperties);
...
// Check that all properties required by the caller have been consumed.
// Throw a TLcdUnsupportedPropertyException if it's not the case.
TLcdModelHeightProviderFactoryUtil.verifyRequiredProperties(requiredProperties);
...
}
Modifier and Type | Method and Description |
---|---|
static boolean |
containsProperty(String aPropertyName,
Map<String,Object> aRequiredProperties,
Map<String,Object> aOptionalProperties)
Checks if a property exists with the given name.
|
static Map<String,Object> |
copyProperties(Map<String,Object> aProperties)
Returns a copy of the given properties.
|
static Object |
getProperty(String aPropertyName,
Map<String,Object> aRequiredProperties,
Map<String,Object> aOptionalProperties)
Returns the property with the given name.
|
static void |
replaceProperty(String aPropertyName,
Object aNewProperty,
Map<String,Object> aRequiredProperties,
Map<String,Object> aOptionalProperties)
Replaces all properties with the given name with the given property object.
|
static Object |
retrieveNecessaryProperty(String aPropertyName,
Map<String,Object> aRequiredProperties,
Map<String,Object> aOptionalProperties)
Returns the property with the given name.
|
static Object |
retrieveProperty(String aPropertyName,
Map<String,Object> aRequiredProperties,
Map<String,Object> aOptionalProperties)
Returns the property with the given name.
|
static void |
verifyRequiredProperties(Map<String,Object> aRequiredProperties)
Checks if no required properties exist and throws a
TLcdUnsupportedPropertyException otherwise. |
public static Map<String,Object> copyProperties(Map<String,Object> aProperties)
aProperties
- the given properties.public static boolean containsProperty(String aPropertyName, Map<String,Object> aRequiredProperties, Map<String,Object> aOptionalProperties)
aPropertyName
- the property name.aRequiredProperties
- the required properties.aOptionalProperties
- the optional properties.public static void verifyRequiredProperties(Map<String,Object> aRequiredProperties) throws TLcdUnsupportedPropertyException
TLcdUnsupportedPropertyException
otherwise.aRequiredProperties
- the required properties.TLcdUnsupportedPropertyException
- when the list of required properties is not empty.public static Object retrieveNecessaryProperty(String aPropertyName, Map<String,Object> aRequiredProperties, Map<String,Object> aOptionalProperties) throws TLcdMissingPropertyException
TLcdMissingPropertyException
is thrown.aPropertyName
- the property name.aRequiredProperties
- the required properties.aOptionalProperties
- the optional properties.TLcdMissingPropertyException
- if no property with the given name exists.public static Object retrieveProperty(String aPropertyName, Map<String,Object> aRequiredProperties, Map<String,Object> aOptionalProperties)
aPropertyName
- the property name.aRequiredProperties
- the required properties.aOptionalProperties
- the optional properties.null
if no such
property exists.public static Object getProperty(String aPropertyName, Map<String,Object> aRequiredProperties, Map<String,Object> aOptionalProperties)
aPropertyName
- the property name.aRequiredProperties
- the required properties.aOptionalProperties
- the optional properties.null
if no such
property exists.public static void replaceProperty(String aPropertyName, Object aNewProperty, Map<String,Object> aRequiredProperties, Map<String,Object> aOptionalProperties)
aPropertyName
- the property name.aNewProperty
- the property object that replaces the existing
properties with the given name.aRequiredProperties
- the required properties.aOptionalProperties
- the optional properties.