|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<Object>
org.mmbase.util.functions.Parameters
public class 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| Nested Class Summary | |
|---|---|
protected static class |
Parameters.SerializableAbstractMap<K,V>
|
| Field Summary | |
|---|---|
protected boolean |
autoCasting
If true, values are automatically cast to the right type (if possible) when set. |
protected Map<String,Object> |
backing
The contents of this List are stored in this HashMap. |
protected Parameter<Object>[] |
definition
This array maps integers (position in array) to map keys, making it possible to implement List. |
protected List<Map.Entry<String,Object>> |
patternBacking
|
protected int |
patternLimit
|
protected int |
toIndex
|
static Parameters |
VOID
No need to bother for the functions with no parameters. |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
|
Parameters(List<Map.Entry<String,Object>> list)
|
|
Parameters(Map<String,Object> backing)
|
|
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. |
|
Parameters(Parameter<?>[] def,
Object... values)
|
|
Parameters(Parameters params)
Copy-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 |
check()
|
|
protected void |
checkDef()
|
|
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)
|
|
|
get(Parameter<F> 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'. |
|
boolean |
isHavingPatterns()
|
|
Object |
set(int i,
Object value)
implementation of (modifiable) List |
|
|
set(Parameter<F> parameter,
F 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<String,?> map)
Copies all values of a map to the corresponding values of this Parameters Object. |
|
Parameters |
setAll(Object... values)
|
|
Parameters |
setAll(Parameters params)
|
|
Parameters |
setAllIfDefined(Parameters params)
|
|
void |
setAutoCasting(boolean autocast)
Sets the 'auto casting' property (which on default is false) |
|
|
setIfDefined(Parameter<F> parameter,
F 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()
|
|
Parameters |
subList(int fromIndex,
int toIndex)
|
|
Class<?>[] |
toClassArray()
|
|
List<Map.Entry<String,Object>> |
toEntryList()
Returns the Parameters as an unmodifiable List of Map.Entrys with predictable iteration order (the same order of this Parameters, which is a List of the values only, itself) |
|
Map<String,Object> |
toMap()
Gives the arguments back as a (unmodifiable) map. |
|
String |
toString()
|
|
List<Map.Entry<String,Object>> |
toUndefaultEntryList()
Returns the Parameters as an unmodifiable List of Map.Entrys with predictable iteration order (the same order of this Parameters, which is a List of the values only, itself) Values which are the same as the default value are returned as null. |
|
Map<String,Object> |
toUndefaultMap()
Returns this parameters object as a (unmodifiable) Map, but all values which only have the default value are null |
|
protected Map<String,Object> |
undefaultBacking()
Returns a view on the backing where every value wich is the default value is set to null. |
|
Collection<LocalizedString> |
validate()
Validates all values in the Parameters object with their Parameter.getDataType(). |
|
| 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 final Map<String,Object> backing
protected final List<Map.Entry<String,Object>> patternBacking
protected int patternLimit
protected Parameter<Object>[] definition
protected boolean autoCasting
true, values are automatically cast to the right type (if possible) when set.
protected int toIndex
| 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[])
public Parameters(Parameter<?>[] def,
Object... values)
public Parameters(Map<String,Object> backing)
public Parameters(List<Map.Entry<String,Object>> list)
public Parameters(Parameters params)
protected Parameters(Parameters params,
int from,
int to)
| Method Detail |
|---|
public boolean isHavingPatterns()
protected final void checkDef()
public String toString()
toString in class AbstractCollection<Object>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 Collection<Object>size in interface List<Object>size in class AbstractCollection<Object>public Object get(int i)
get in interface List<Object>get in class AbstractList<Object>
public Object set(int i,
Object value)
set in interface List<Object>set in class AbstractList<Object>NullPointerException - if definition not setpublic void checkRequiredParameters()
For complete datatype validationpublic Collection<LocalizedString> validate()
Parameter.getDataType(). You should
call this method if you ready to pass it into some function or so, if you want
validation. If the returned Collection is not empty, something is wrong, and you may want to
not proceed.
public void check()
IllegalArgumentException - if one or more of the the current values are not valid.validate()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 <F> Parameters set(Parameter<F> parameter,
F 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<String,?> map)
public Parameters setAll(Collection<?> values)
public Parameters setAll(Object... values)
public Parameters setAllIfDefined(Parameters params)
public Parameters setAll(Parameters params)
public Parameters subList(int fromIndex,
int toIndex)
subList in interface List<Object>subList in class AbstractList<Object>
public <F> Parameters setIfDefined(Parameter<F> parameter,
F 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 <F> F get(Parameter<F> 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
Stringprotected Map<String,Object> undefaultBacking()
null. If the default is not null itself, but the value is,
than the value will be returned as an empty string.
This can be used to generated keys and such, which are not polluted with all kind of default values.
public Map<String,Object> toMap()
public Map<String,Object> toUndefaultMap()
null
public List<Map.Entry<String,Object>> toEntryList()
public List<Map.Entry<String,Object>> toUndefaultEntryList()
null. If the
default is not null but the value is, then it is returned as an empty string.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||