public class ElementHelper extends PropertyResources implements Initializable, UserAdjustable, UserDetails
(ExposureTime|SignalToNoise)&FilterNameAs soon as the user supplies a value for a parameter, it toggles to boolean true and the entire requirement can be checked for fullfillment with a call to
isValid(). To get the list of still unset parameters, call
getMissing(). Note that this method will always return all the missing
parameters, even if they are not any more needed for validity. In particular,
the example above will still list the ExposureTime as missing, even
if the SignalToNoise has been specified.| Modifier and Type | Class and Description |
|---|---|
static class |
ElementHelper.Valid
Test the validity of an element helper.
|
PropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private List<BooleanNode> |
check
The boolean expression parser, initialized at construction.
|
private Map<String,String> |
choices
Variable names to comma-separated choices as strings.
|
private Map<String,Object> |
constants
The mapping of constant names to their values or to null if undefined.
|
private Map<String,ExpressionNode> |
follows
These variables follow from expressions.
|
private BuildingHandler |
handled
If an error handler was assigned to the element helper.
|
static String |
KEY_APPENDIX
The appendix to link a single key to two values.
|
static String |
KEY_CHECKS
After everything is set up and valid, this checks may be performed.
|
static String |
KEY_CHOICES
For these variable names, we have a mapping to possible values.
|
static String |
KEY_FOLLOWFROM
A mapping of variables that follow from others.
|
static String |
KEY_HELPERCLASS
The key mapping to the element helper class name.
|
static String |
KEY_ID
The key mapping to ID key name.
|
static String |
KEY_INIT
Matches constant names to their initial values.
|
static String |
KEY_LISTMULTIPLY
If this is set, it is the separator for a multiplicative list.
|
static String |
KEY_REQUIREMENT
The boolean expression defining the validity requirement.
|
static String |
KEY_SETTABLE
Matches variable names that are settable.
|
static String |
KEY_TYPEMAP
Matches variable names to class type names.
|
static String |
KEY_VALUEDETAILS
The mapping of variable names to a more detailed description.
|
private BooleanNode |
requires
The boolean expression parser, initialized at construction.
|
private List<String> |
settable
The list of variable names that are settable by the user.
|
private Map<String,String> |
types
The mapping of constant names to their class types.
|
KEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOMECONFIG, KEY_CLASS| Constructor and Description |
|---|
ElementHelper(Map<String,String> prop)
Constructs a new constant helper.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assignBuildingHandler(BuildingHandler bh)
Assigns a (new) building handler to this element handler.
|
private void |
checkFollow(String name,
Object to) |
static ElementHelper |
createElementHelper(Map<String,String> prop)
Creates a
ElementHelper using the provided properties. |
static List<ElementHelper> |
createElementHelpers(ResourceSupplying i,
String props)
Converts a comma-separated list of property files into a list of
ElementHelpers by reading the properties and passing them to the
element helper constructor. |
protected List<ElementHelper> |
createElementHelpers(String props)
Converts a comma-separated list of property files into a list of
ElementHelpers by reading the properties and passing them to the
element helper constructor. |
static Map<Object,ElementHelper> |
createHelperMap(ResourceSupplying i,
String props)
Converts a comma-separted list of property files into a mapping of
ElementHelpers to keys queried from the helpers by asking their
property named according to the second argument. |
protected Map<Object,ElementHelper> |
createHelperMap(String props)
Converts a comma-separted list of property files into a mapping of
ElementHelpers to keys queried from the helpers by asking their
property named according to the second argument. |
void |
erase()
Sets up the lookup table of constant names to constant values.
|
protected void |
error(String warn)
Issues an error message.
|
static ElementHelper |
fromResourceName(ResourceSupplying i,
String file)
Creates a single element helper from a specified named resource, normally
a properties file.
|
protected ElementHelper |
fromResourceName(String file)
Creates a single element helper from a specified named resource, normally
a properties file.
|
List<Object> |
getChoices(String name)
If the variable is listed as having possible choices, we return the list
of objects it can assume.
|
Map<String,Object> |
getDefined()
Returns all mappings to non-null values, thus returns all constants that
are set.
|
Map<String,String> |
getDetails()
Returns detailed description to the settable variables as found in the
properties.
|
Map<String,ExpressionNode> |
getFollows()
Returns all variable names whose value follows from other variables.
|
Object |
getID()
Returns the value of the id-varibale.
|
Map<String,Object> |
getMissing()
Returns a list of names of all constants that are still not set.
|
List<String> |
getMissingRequired()
Tries to infer the variables missing that hinder this element from
becoming valid.
|
Map<String,Object> |
getRequired()
Returns all variables that are named in the requirement section.
|
Map<String,Object> |
getSettable()
Returns a mapping of all settable variables against their current values,
including unset variables.
|
Class<?> |
getType(String name)
Returns the entry in the types map as a class object.
|
Object |
getValue(String name)
Returns the present value of the constant.
|
Map<String,Object> |
getVariables()
Returns all mappings present, valid and invalid ones.
|
void |
init()
Initializes the types look-up table and the boolean node.
|
boolean |
isValid()
Checks if the required constants have been set.
|
boolean |
setValue(String name,
Object val)
Sets the constant of the given name to the given value.
|
private boolean |
setValue(String name,
Object val,
boolean force)
Sets the constant of the given name to the given value.
|
String |
toLongString() |
String |
toString()
Returns a description of this element helper.
|
boolean |
update()
Returns true, as normal element helpers do not have dependant variables.
|
private boolean |
validChecks() |
private boolean |
validRequirement() |
clone, createFrom, createFrom, createFrom, createInstance, getApplet, getAsResources, getLocate, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, hasLocalURLs, initProperties, keyCreate, keyCreate, reload, setAppletaugment, augment, augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, parseObject, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringPropertiesequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdefaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringPropertiespublic static final String KEY_HELPERCLASS
public static final String KEY_ID
public static final String KEY_TYPEMAP
public static final String KEY_LISTMULTIPLY
public static final String KEY_SETTABLE
public static final String KEY_INIT
public static final String KEY_REQUIREMENT
public static final String KEY_CHOICES
public static final String KEY_CHECKS
public static final String KEY_FOLLOWFROM
public static final String KEY_VALUEDETAILS
public static final String KEY_APPENDIX
private BooleanNode requires
private List<BooleanNode> check
private Map<String,Object> constants
private Map<String,ExpressionNode> follows
private BuildingHandler handled
public void init()
erase() method.init in interface Initializablepublic Map<String,ExpressionNode> getFollows()
public void erase()
public Object getID()
KEY_ID key.getID in interface UserAdjustablepublic boolean isValid()
KEY_REQUIREMENT section to true,
undefined constants are false. The evaluation of the entrie string is
then returned.isValid in interface UserAdjustableprivate boolean validRequirement()
private boolean validChecks()
public Map<String,Object> getMissing()
getMissing in interface UserAdjustablepublic Map<String,Object> getRequired()
getRequired in interface UserAdjustablepublic List<String> getMissingRequired()
getMissing() and
getRequired() such that variables in both, missing and required,
are returned. This might still over-estimate the number of required
variables, as an undefined variable, e.g., can be overcome in an OR
clausepublic Map<String,Object> getDefined()
getDefined in interface UserAdjustablepublic Map<String,Object> getVariables()
getVariables in interface UserAdjustablepublic Map<String,Object> getSettable()
getSettable in interface UserAdjustablepublic Map<String,String> getDetails()
getDetails in interface UserDetailspublic Object getValue(String name)
getValue in interface UserAdjustablepublic List<Object> getChoices(String name)
name - public Class<?> getType(String name)
getType in interface UserAdjustablepublic boolean update()
update in interface UserAdjustablepublic boolean setValue(String name, Object val)
KEY_TYPEMAP is queried for
the correct class type and a new instance of this class is stored in the
constants look-up table, instantiated with the string as the
only argument in the constructor.setValue in interface UserAdjustableprivate boolean setValue(String name, Object val, boolean force)
KEY_TYPEMAP is queried for
the correct class type and a new instance of this class is stored in the
constants look-up table, instantiated with the string as the
only argument in the constructor.force - If true, even non-settable variables are set. This is done
during initialization.public void assignBuildingHandler(BuildingHandler bh)
bh - protected void error(String warn)
public String toString()
toString in class PropertyContainerpublic String toLongString()
public static ElementHelper createElementHelper(Map<String,String> prop)
ElementHelper using the provided properties. If the
properties do not contain a PropertySupplying.KEY_CLASS property the
standard ElementHelper class is used. If one wants to create
daughter classes of the ElementHelper, e.g. to provide
GUI-enhanced functionality, the properties should contain a class entry
of this telescope helper subclass.protected ElementHelper fromResourceName(String file)
public static ElementHelper fromResourceName(ResourceSupplying i, String file)
public static List<ElementHelper> createElementHelpers(ResourceSupplying i, String props)
ElementHelpers by reading the properties and passing them to the
element helper constructor.protected List<ElementHelper> createElementHelpers(String props)
ElementHelpers by reading the properties and passing them to the
element helper constructor.public static Map<Object,ElementHelper> createHelperMap(ResourceSupplying i, String props)
ElementHelpers to keys queried from the helpers by asking their
property named according to the second argument. A warning is issued if
two identical mappings exist, in which case only the later on is kept.
Note that this method can only work correctly if the value of the
ID-field is already set after initialization, i.e. it must be specified
in the KEY_INIT section.protected Map<Object,ElementHelper> createHelperMap(String props)
ElementHelpers to keys queried from the helpers by asking their
property named according to the second argument. A warning is issued if
two identical mappings exist, in which case only the later on is kept.
Note that this method can only work correctly if the value of the
ID-field is already set after initialization, i.e. it must be specified
in the KEY_INIT section.