Package digilib.util
Class ParameterMap
- java.lang.Object
-
- digilib.util.ParameterMap
-
- Direct Known Subclasses:
DigilibConfiguration
,DigilibRequest
,PDFRequest
public class ParameterMap extends Object
HashMap of digilib.servlet.Parameter's. Keys are Strings. Values are Parameters.- Author:
- casties
-
-
Constructor Summary
Constructors Constructor Description ParameterMap()
Default constructor.ParameterMap(int size)
Constructor with initial size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ParameterMap
cloneInstance(ParameterMap pm)
Shallow copy constructor.Parameter
get(String key)
Get the Parameter with the corresponding key.boolean
getAsBoolean(String key)
Get the value with the corresponding key.File
getAsFile(String key)
Get the value with the corresponding key.float
getAsFloat(String key)
Get the value with the corresponding key.int
getAsInt(String key)
Get the value with the corresponding key.String
getAsString(String key)
Get the value with the corresponding key.static ParameterMap
getInstance(ParameterMap pm)
Creates new ParameterMap by merging Parameters from another ParameterMap.OptionsSet
getOptions()
Returns the options Set.HashMap<String,Parameter>
getParameters(int type)
Returns a map with all Parameters of a type.HashMap<String,Parameter>
getParams()
Returns the parameter Map.Object
getValue(String key)
Get the value with the corresponding key.boolean
hasOption(DigilibOption opt)
Returns if the option has been set.boolean
hasValue(String key)
Returns if the Parameter's value has been set.protected void
initOptions()
set up optionsprotected void
initParams()
set up parametersParameter
newParameter(String name, Object def, Object val)
Add a new Parameter with name, default and value.Parameter
newParameter(String name, Object def, Object val, int type)
Add a new Parameter with name, default, value and type.Parameter
put(Parameter val)
Add the Parameter val to the map, using val's name.Parameter
put(String key, Parameter val)
Add the Parameter to the map with a certain key.void
setOptions(OptionsSet options)
Sets the options Set.void
setParams(HashMap<String,Parameter> params)
Sets the parameter Map.boolean
setValue(String key, float val)
Set the value of an existing parameter.boolean
setValue(String key, int val)
Set the value of an existing parameter.boolean
setValue(String key, Object val)
Set the value of an existing parameter.boolean
setValueFromString(String key, String val)
Set the value of an existing parameter.
-
-
-
Field Detail
-
options
protected OptionsSet options
-
-
Method Detail
-
cloneInstance
public static ParameterMap cloneInstance(ParameterMap pm)
Shallow copy constructor. Be warned that the maps are only cloned i.e. keys and values are shared!- Parameters:
pm
- other ParameterMap- Returns:
- new ParameterMap
-
getInstance
public static ParameterMap getInstance(ParameterMap pm)
Creates new ParameterMap by merging Parameters from another ParameterMap.- Parameters:
pm
- other ParameterMap- Returns:
- new ParameterMap
-
initParams
protected void initParams()
set up parameters
-
initOptions
protected void initOptions()
set up options
-
get
public Parameter get(String key)
Get the Parameter with the corresponding key. Returns null if no element is associated with key.- Parameters:
key
- the key- Returns:
- the Parameter
-
getValue
public Object getValue(String key)
Get the value with the corresponding key. Returns null if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
getAsString
public String getAsString(String key)
Get the value with the corresponding key. Returns empty string if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
getAsInt
public int getAsInt(String key)
Get the value with the corresponding key. Returns 0 if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
getAsFloat
public float getAsFloat(String key)
Get the value with the corresponding key. Returns 0 if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
getAsBoolean
public boolean getAsBoolean(String key)
Get the value with the corresponding key. Returns false if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
getAsFile
public File getAsFile(String key)
Get the value with the corresponding key. Returns null if no element is associated with key.- Parameters:
key
- the key- Returns:
- the value
-
hasValue
public boolean hasValue(String key)
Returns if the Parameter's value has been set.- Parameters:
key
- the key- Returns:
- if the value has been set
-
put
public Parameter put(String key, Parameter val)
Add the Parameter to the map with a certain key. Returns the value that was previously associated with key.- Parameters:
key
- the keyval
- the value- Returns:
- last Parameter
-
put
public Parameter put(Parameter val)
Add the Parameter val to the map, using val's name. Returns the value that was previously associated with val's name.- Parameters:
val
- the value- Returns:
- last Parameter
-
newParameter
public Parameter newParameter(String name, Object def, Object val)
Add a new Parameter with name, default and value. Returns the key that was previously associated with name.- Parameters:
name
- the namedef
- the defaultval
- the value- Returns:
- last Parameter
-
newParameter
public Parameter newParameter(String name, Object def, Object val, int type)
Add a new Parameter with name, default, value and type. Returns the key that was previously associated with name.- Parameters:
name
- the namedef
- the defaultval
- the valuetype
- the type- Returns:
- last Parameter
-
setValue
public boolean setValue(String key, Object val)
Set the value of an existing parameter. Sets the value and returns true if the parameter exists.- Parameters:
key
- the keyval
- the value- Returns:
- true if the parameter exists.
-
setValue
public boolean setValue(String key, int val)
Set the value of an existing parameter. Sets the value and returns true if the parameter exists.- Parameters:
key
- the keyval
- the value- Returns:
- true if the parameter exists.
-
setValue
public boolean setValue(String key, float val)
Set the value of an existing parameter. Sets the value and returns true if the parameter exists.- Parameters:
key
- the keyval
- the value- Returns:
- true if the parameter exists.
-
setValueFromString
public boolean setValueFromString(String key, String val)
Set the value of an existing parameter. Sets the value and returns true if the parameter exists.- Parameters:
key
- the keyval
- the value- Returns:
- true if the parameter exists.
-
hasOption
public boolean hasOption(DigilibOption opt)
Returns if the option has been set.- Parameters:
opt
- the option- Returns:
- true if the option has been set.
-
getParameters
public HashMap<String,Parameter> getParameters(int type)
Returns a map with all Parameters of a type.- Parameters:
type
- the type- Returns:
- map with all Parameters of a type
-
getParams
public HashMap<String,Parameter> getParams()
Returns the parameter Map.- Returns:
- the parameter Map
-
setParams
public void setParams(HashMap<String,Parameter> params)
Sets the parameter Map.- Parameters:
params
- the parameter Map
-
getOptions
public OptionsSet getOptions()
Returns the options Set.- Returns:
- the options Set
-
setOptions
public void setOptions(OptionsSet options)
Sets the options Set.- Parameters:
options
- the options Set
-
-