jezuch.utils.starmapper2
Class Parameters

java.lang.Object
  |
  +--jezuch.utils.starmapper2.Parameters
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ImageParameters

public class Parameters
extends java.lang.Object
implements java.io.Serializable

This class is similar to Properties but accepts more data types than String - int, boolean and Object. It's not very elegant, but extensible.
Parameter names are String and parameter values are Objects; this class exposes getters and setters for types boolean, int, String and Object, which "wrap" given values in objects and iterpret values according to one of these types. They are not converting values, but they expect that the value is correct, what might result in ClassCastException.
This class holds a list of reserved keys, that are a subject to check if their values are valid; this check is dome by subclasses of Parameters.ParamHandler.

Since:
2.0
Version:
2.0
Author:
Krzysztof Sobolewski
See Also:
Serialized Form

Nested Class Summary
static interface Parameters.ParamHandler
          Interface that defines a method to validate a reserved parameter.
 
Field Summary
static Parameters.ParamHandler BOOLEAN_PARAM_HANDLER
          Generic ParamHandler that checks if the parameter is Boolean.
protected  java.util.Map params
          A map that holds all parameters; specific accessors get values from this map and convert (cast) them to correct types and optionally check for correct values.
protected  java.util.Map reservedKeys
          A map of reserved keys.
 
Constructor Summary
Parameters()
          Construct Parameters instace with default values.
 
Method Summary
 boolean getBoolean(java.lang.String name)
          Accessor method for type boolean; returns true if and only if parameter's value is identical to java.lang.Boolean.TRUE.
 int getInt(java.lang.String name)
          Accessor method for type int; might throw an exception if parameter's value is not an integer or is not set at all.
 java.lang.Object getObject(java.lang.String name)
          Returns parameter's value.
 java.lang.String getString(java.lang.String name)
          Returns String interpretation of parameter's value.
 void setBoolean(java.lang.String name, boolean value)
          Sets parameter as boolean value overwriting previous value.
 void setInt(java.lang.String name, int value)
          Sets parameter as int value overwriting previous value.
 void setObject(java.lang.String name, java.lang.Object value)
          Sets parameter's value overwriting previous value.
 void setString(java.lang.String name, java.lang.String value)
          Sets parameter as String value overwriting previous value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN_PARAM_HANDLER

public static final Parameters.ParamHandler BOOLEAN_PARAM_HANDLER
Generic ParamHandler that checks if the parameter is Boolean.


params

protected final java.util.Map params
A map that holds all parameters; specific accessors get values from this map and convert (cast) them to correct types and optionally check for correct values.


reservedKeys

protected final java.util.Map reservedKeys
A map of reserved keys. It mas Strings to Parameters.ParamHandlers that handle these parameters.

Constructor Detail

Parameters

public Parameters()
Construct Parameters instace with default values. Sublasses should supply these values and set reserved keys.

Method Detail

getBoolean

public boolean getBoolean(java.lang.String name)
Accessor method for type boolean; returns true if and only if parameter's value is identical to java.lang.Boolean.TRUE.

Parameters:
name - parameter's name
Returns:
boolean intepretation of parameter's value, that is the value of expression [value]==Boolean.TRUE

getInt

public int getInt(java.lang.String name)
           throws java.lang.ClassCastException
Accessor method for type int; might throw an exception if parameter's value is not an integer or is not set at all.

Parameters:
name - parameter's name
Returns:
int intepretation of parameter's value
Throws:
java.lang.NullPointerException - if the parameter is not set
java.lang.ClassCastException - if the parameter is not an int

getObject

public java.lang.Object getObject(java.lang.String name)
Returns parameter's value.

Parameters:
name - parameter's name
Returns:
parameter's value as Object

getString

public java.lang.String getString(java.lang.String name)
                           throws java.lang.ClassCastException
Returns String interpretation of parameter's value.

Parameters:
name - parameter's name
Returns:
int intepretation of parameter's value
Throws:
java.lang.ClassCastException - if the parameter is not a String

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
Sets parameter as boolean value overwriting previous value.

Parameters:
name - parameter's name
value - parameter's boolean value.

setInt

public void setInt(java.lang.String name,
                   int value)
Sets parameter as int value overwriting previous value.

Parameters:
name - parameter's name
value - parameter's int value

setObject

public void setObject(java.lang.String name,
                      java.lang.Object value)
Sets parameter's value overwriting previous value.

Parameters:
name - parameter's name
value - parameter's value

setString

public void setString(java.lang.String name,
                      java.lang.String value)
Sets parameter as String value overwriting previous value.

Parameters:
name - parameter's name
value - parameter's String value