|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractList
org.mmbase.util.functions.Parameters
This class implemements the Parameters interface. It provides a convenient way to create a List that allows the use of 'named parameters'. This List is therefore backed by a HashMap, but it behaves as a list. So if you set a parameter with a certain name, it always appears in the same location of the List. This List is modifiable but not resizeable. It is always the size of the definition array.
Parameter,
Parameters(Parameter[]),
Serialized Form| Field Summary | |
protected boolean |
autoCasting
If true, values are automatically cast to the right type (if possible) when set. |
protected Map |
backing
The contents of this List are stored in this HashMap. |
protected Parameter[] |
definition
This array maps integers (position in array) to map keys, making it possible to implement List. |
static Parameters |
VOID
No need to bother for the functions with no parameters. |
| Fields inherited from class java.util.AbstractList |
modCount |
| Constructor Summary | |
|
Parameters(Parameter[] def)
Constructor, taking an Parameter[] array argument. |
|
Parameters(Parameter[] def,
Collection values)
If you happen to have a List of parameters, then you can wrap it into an Parameters with this constructor. |
protected |
Parameters(Parameters params,
int from,
int to)
Used for nicer implemenation of subList (which we want to also be instanceof Parameters). |
| Method Summary | |
void |
checkRequiredParameters()
Throws an IllegalArgumentException if one of the required parameters was not entered. |
boolean |
containsParameter(Parameter parameter)
Checks wether a certain parameter is available, using the Parameter as a qualifier. |
boolean |
containsParameter(String parameterName)
Checks wether a certain parameter is available, using the parameter name as a qualifier. |
Object |
get(int i)
|
Object |
get(Parameter parameter)
Gets the value of a parameter. |
Object |
get(String parameterName)
Gets the value of a parameter. |
Parameter[] |
getDefinition()
|
String |
getString(Parameter parameter)
Gets the value of a parameter, cast to a String. |
String |
getString(String parameterName)
Gets the value of a parameter, cast to a String. |
int |
indexOfParameter(Parameter parameter)
Returns the position of a parameter in the parameters list, using the Parameter as a qualifier. |
int |
indexOfParameter(String parameterName)
Returns the position of a parameter in the parameters list, using the parameter name as a qualifier. |
boolean |
isAutoCasting()
Whether this Parameters object is 'automaticly casting'. |
Object |
set(int i,
Object value)
|
Parameters |
set(Parameter parameter,
Object value)
Sets the value of a parameter. |
Parameters |
set(String parameterName,
Object value)
Sets the value of a parameter. |
Parameters |
setAll(Collection values)
Copies all values of a collection to the corresponding values of this Parameters Object. |
Parameters |
setAll(Map map)
Copies all values of a map to the corresponding values of this Parameters Object. |
void |
setAutoCasting(boolean autocast)
Sets the 'auto casting' property (which on default is false) |
Parameters |
setIfDefined(Parameter parameter,
Object value)
Sets the value of an argument, if the argument is defined, otherwise do nothing. |
Parameters |
setIfDefined(String parameterName,
Object value)
Sets the value of an argument, if the argument is defined, otherwise do nothing. |
int |
size()
|
List |
subList(int fromIndex,
int toIndex)
|
Class[] |
toClassArray()
|
Map |
toMap()
Gives the arguments back as a (unmodifiable) map. |
String |
toString()
|
| Methods inherited from class java.util.AbstractList |
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange |
| Methods inherited from class java.util.AbstractCollection |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
| Field Detail |
public static final Parameters VOID
protected Map backing
protected Parameter[] definition
protected boolean autoCasting
true, values are automatically cast to the right type (if possible) when set.
| Constructor Detail |
public Parameters(Parameter[] def)
public final static Parameter[] MYFUNCTION_PARAMETERS = {
new Parameter("type", Integer.class),
new Parameter("text", String.class),
Parameter.CLOUD, // a predefined parameter
new Parameter.Wrapper(OTHERFUNCTION_PARAMETERS) // a way to include another definition in this one
};
public Parameters(Parameter[] def,
Collection values)
values - Collection with values. This Collection should have a predictable iteration order.
NullPointerException - if definition is nullParameters(Parameter[])
protected Parameters(Parameters params,
int from,
int to)
| Method Detail |
public String toString()
public Class[] toClassArray()
public void setAutoCasting(boolean autocast)
autocast - the new value for autocastisAutoCasting()public Parameter[] getDefinition()
public boolean isAutoCasting()
true if autocasting is onpublic int size()
size in interface Listpublic Object get(int i)
get in interface List
public Object set(int i,
Object value)
set in interface Listpublic void checkRequiredParameters()
public int indexOfParameter(Parameter parameter)
get(int).
parameter - the parameter
public int indexOfParameter(String parameterName)
get(int).
parameterName - the name of the parameter
public boolean containsParameter(Parameter parameter)
parameter - the parameter
true if a parameter exists.public boolean containsParameter(String parameterName)
parameterName - the name of the parameter
true if a parameter exists.
public Parameters set(Parameter parameter,
Object value)
parameter - the Parameter describing the parameter to setvalue - the object value to set
IllegalArgumentException - if either the argument name is unknown to this Parameters, or the value is of the wrong type.
public Parameters set(String parameterName,
Object value)
parameterName - the name of the parameter to setvalue - the object value to set
IllegalArgumentException - if either the argument name is unknown to this Parameters, or the value is of the wrong type.public Parameters setAll(Map map)
public Parameters setAll(Collection values)
public List subList(int fromIndex,
int toIndex)
subList in interface List
public Parameters setIfDefined(Parameter parameter,
Object value)
parameter - the parameter to setvalue - the object value to set
public Parameters setIfDefined(String parameterName,
Object value)
parameterName - the name of the parameter to setvalue - the object value to setpublic Object get(Parameter parameter)
parameter - the parameter to get
public Object get(String parameterName)
parameterName - the name of the parameter to get
public String getString(Parameter parameter)
parameter - the parameter to get
STringpublic String getString(String parameterName)
parameterName - the name of the parameter to get
STringpublic Map toMap()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||