| java.lang.Object java.util.Observable jimm.datavision.Parameter
Parameter | public class Parameter extends Observable implements Identity,Nameable,Writeable,Draggable,Cloneable(Code) | | A parameter is a piece of data the value of which is determined by
asking the user each time a report runs. Default values are only used
when asking the user for values, not when generating values in
getValue .
I started out with subclasses for each type of parameter. The problem is,
the user gets to pick what kind of data the parameter holds and that
type can be changed any time after the parameter gets created. Therefore,
we hold objects and change our output based on the type of the data.
author: Jim Menard, jimm@io.com |
Constructor Summary | |
public | Parameter(Long id, Report report) Constructor. | public | Parameter(Long id, Report report, String typeName, String name, String question, String arityString) Constructor.
If id is null , generates a new id number. | public | Parameter(Long id, Report report, int type, String name, String question, int arity) Constructor.
If id is null , generates a new id number. |
ARITY_LIST_MULTIPLE | final public static int ARITY_LIST_MULTIPLE(Code) | | |
ARITY_LIST_SINGLE | final public static int ARITY_LIST_SINGLE(Code) | | |
ARITY_ONE | final public static int ARITY_ONE(Code) | | |
ARITY_RANGE | final public static int ARITY_RANGE(Code) | | |
TYPE_BOOLEAN | final public static int TYPE_BOOLEAN(Code) | | |
TYPE_DATE | final public static int TYPE_DATE(Code) | | |
TYPE_NUMERIC | final public static int TYPE_NUMERIC(Code) | | |
TYPE_STRING | final public static int TYPE_STRING(Code) | | |
arity | protected int arity(Code) | | |
Parameter | public Parameter(Long id, Report report)(Code) | | Constructor. Creates a string parameter with no name or question
string.
Parameters: id - the unique identifier for the new parameter; ifnull , generate a new id Parameters: report - the report in which this parameter resides |
Parameter | public Parameter(Long id, Report report, String typeName, String name, String question, String arityString)(Code) | | Constructor.
If id is null , generates a new id number. This number
is one higher than any previously-seen id number. This does not
guarantee that no later parameter will be created manually with the same
id number.
Parameters: id - the unique identifier for the new parameter; ifnull , generate a new id Parameters: report - the report in which this parameter resides Parameters: typeName - one of "string", "numeric", or "date"; found in report XML Parameters: name - the name of this parameter Parameters: question - the question to ask when getting the parameter's valuefrom the user Parameters: arityString - arity (single, range, list) as a string |
Parameter | public Parameter(Long id, Report report, int type, String name, String question, int arity)(Code) | | Constructor.
If id is null , generates a new id number. This number
is one higher than any previously-seen id number. This does not
guarantee that no later parameter will be created manually with the same
id number.
Parameters: id - the unique identifier for the new parameter; ifnull , generate a new id Parameters: report - the report in which this parameter resides Parameters: type - one ofTYPE_BOOLEAN , TYPE_STRING ,TYPE_NUMERIC , or TYPE_DATE Parameters: name - the name of this parameter Parameters: question - the name of this parameter Parameters: arity - one of ARITY_ONE , ARITY_RANGE ,ARITY_LIST_SINGLE , or ARITY_LIST_MULTIPLE |
addDefaultValue | public void addDefaultValue(Object newDefaultValue)(Code) | | Adds a default value to the list.
Parameters: newDefaultValue - a new default value |
addValue | public void addValue(Object newValue)(Code) | | Adds a value to the list.
Parameters: newValue - a new value |
convertType | protected Object convertType(Object val)(Code) | | Converts the specified object to the proper type for this parameter.
Whenever we add or set a value or default value, we convert it to the
proper type (string, date, etc.)
If our type is boolean and the incoming object is:
- A string, return
a
true Boolean if the value matches "true", "t", "yes",
or "y" (ignoring case).
- A number, return a
true Boolean if the value is non-zero.
- Anything else, return a
true Boolean (any better
suggestions?)
Parameters: val - any old object some object of the proper type |
defaultValues | public Iterator defaultValues()(Code) | | Returns an iterator over the default values for this parameter.
an interator |
getArity | public int getArity()(Code) | | Returns the arity of this field. Will be one of ARITY_ONE ,
ARITY_RANGE , ARITY_LIST_SINGLE , or
ARITY_LIST_MULTIPLE .
the arity number |
getDefaultForType | public Object getDefaultForType(int type)(Code) | | Returns the default value for a specific parameter type. This is not
the same as the i'th default value; it is called when you have a
parameter that has no value or default value, or when you have one
with a different type and you want to switch types.
Parameters: type - one of TYPE_BOOLEAN , TYPE_STRING ,TYPE_NUMERIC , or TYPE_DATE a new object appropriate for the type |
getDefaultValue | public Object getDefaultValue(int i)(Code) | | Returns the i'th defaultValue for this parameter. If none has been
assigned, create and return -- but do not store -- a reasonable default.
The default is obtained by calling
Parameter.getDefaultForType .
Parameters: i - the index the defaultValue |
getName | public String getName()(Code) | | Returns the name for this parameter.
the name |
getQuestion | public String getQuestion()(Code) | | Returns the question for this parameter.
the question |
getType | public int getType()(Code) | | Returns the type of this field. Will be one of
TYPE_BOOLEAN , TYPE_STRING ,
TYPE_NUMERIC , or TYPE_DATE .
the type number |
getValue | public Object getValue()(Code) | | Returns the parameter value(s) the user has previously specified. If
the parameter has one value, return that value or possibly null. Else,
return a copy of our list of values.
values (see description) |
getValue | public Object getValue(int i)(Code) | | Returns the current value or, if that is null , the default
value. If the index is out of range, return null .
Parameters: i - the index the current or default value. |
isLegal | public boolean isLegal(int aType, int anArity)(Code) | | Returns true if the specified combination of type and arity
are legal.
Parameters: aType - one of TYPE_BOOLEAN , TYPE_STRING ,TYPE_NUMERIC , or TYPE_DATE Parameters: anArity - one of ARITY_ONE , ARITY_RANGE ,ARITY_LIST_SINGLE , or ARITY_LIST_MULTIPLE true if the specified combination of type and arityare legal |
removeDefaultValues | public void removeDefaultValues()(Code) | | Erases all default values.
|
removeValues | public void removeValues()(Code) | | Erases all values.
|
setArity | public void setArity(int newArity)(Code) | | Sets the parameter arity. Must be one of ARITY_ONE ,
ARITY_RANGE , ARITY_LIST_SINGLE , or
ARITY_LIST_MULTIPLE . We disallow illegal arity values.
For example, if our type is boolean we disallow a list arity.
Parameters: newArity - one of ARITY_ONE , ARITY_RANGE ,ARITY_LIST_SINGLE , or ARITY_LIST_MULTIPLE |
setDefaultValue | public void setDefaultValue(int i, Object newDefaultValue)(Code) | | Sets the i'th defaultValue. If i is out of range,
the list of default values grows to fit.
Parameters: i - the index Parameters: newDefaultValue - a value |
setName | public void setName(String newName)(Code) | | Sets the name.
Parameters: newName - the new name |
setQuestion | public void setQuestion(String newQuestion)(Code) | | Sets the question.
Parameters: newQuestion - the new question |
setType | public void setType(int newType)(Code) | | Sets the parameter type. Must be one of
TYPE_BOOLEAN , TYPE_STRING ,
TYPE_NUMERIC , or TYPE_DATE . If the new type
is different than the old, we also make sure the arity is appropriate
(for example, no boolean lists) and clear the value and default value
lists.
Parameters: newType - the new type; must be one of TYPE_BOOLEAN ,TYPE_STRING , TYPE_NUMERIC , orTYPE_DATE |
setValue | public void setValue(int i, Object newValue)(Code) | | Sets the i'th value. If i is out of range,
the list of values grows to fit.
param i the index
Parameters: newValue - the new value |
typeString | protected String typeString()(Code) | | Returns the string used as the "type" attribute when writing this
parameter as XML.
the "type" attribute string |
values | public Iterator values()(Code) | | Returns an iterator over the values for this parameter.
an interator |
writeXML | public void writeXML(XMLWriter out)(Code) | | Writes this parameter as an XML tag.
Parameters: out - a writer that knows how to write XML |
|
|