net.simplace.util.FWFrameworkHelper
Provides some static method for working with strings.
public final class FWFrameworkHelper {
// Constants
public static final char WEBEUROSIGN;
public static final Pattern PARAMPATTERN;
public static final Pattern EXPRESSIONPATTERN;
public static final OperationTreeParser MATHRULE_PARSER;
// Class Methods public static Object
getParameterFromMap(Map aParamMap, String aKey, Object
aDefault);
getting parameter value from key if value is Map or Date using '!' as a seperator.
returns parameter value from key if value is Map or Date using '!' as a seperator
public static String
getStringParameterFromMap(Map aParamMap, String aKey,
Object aDefault);
getting parameter value from map as string.
returns parameter value from map as string
public static Number
getNumberParameterFromMap(Map aParamMap, String aKey,
Class aNumberType, Number aDefault);
Getting parameter value from map as a number.
- aParamMap map the parameter is taken from
- aKey key for the map
- aNumberType number type, the determined value is converted to (subclass of
{@link Number})
- aDefault default value, which is returned if parameter not set or value can
not be converted to {@code aNumberType}.
returns parameter value from map as a number
public static String
replaceParamTokens(Map aParamMap, String aValue, Object
aDefault);
replaces Parameters in
- aValue
matching the regexp '.*[${].*[}].*' with given parameters in
- aParamMap
- aDefault
returns aNewValue
public static String
replaceParamTokens(Map aParamMap, String aValue, Object
aDefault, boolean aIgnoreNull);
replaces Parameters in
- aValue
matching the regexp '.*[${].*[}].*' with given parameters in
- aParamMap
- aDefault
- aIgnoreNull
returns aNewValue
public static Object
getValueFromSpecialParameter(Map aParamMap, String aKey,
Object aDefault);
getting parameter value from key if value is Map or Date using '!' as a separator.
returns parameter value from key if value is Map or Date using '!' as a separator
public static double
evaluateExpression(String aValue, Map aParameterMap);
evaluates expressions fith arithmetric operations
returns the double result value
public static double
evaluateMathematicalRule(String aRule);
Parst einen String, erstellt daraus einen de.schmitzm.lang.tree.OperationTreeOperator-Baum
und wertet diesen aus. Fuer die Syntax gelten die gleichen Regeln, wie
fuer
net.simplace.util.FWFrameworkHelper.evaluateRule(String). Das Ergebnis wird jedoch immer
als numerisch interpretiert. Ist das Ergebnis keine Instanz von java.lang.Number,
wird 0 zurueckgegeben.
returns the result ot the rule or 0 if the result is not numeric
public static Object
evaluateRule(String aRule);
returns resulting object
public static Object
evaluateRule(String aRule, OperationTreeParser aParser);
Evaluation
of Rules in SIMPLACE Framework with the SchmitzM Operation Tree Parser
The Operation Tree Parser evaluates mathematical rules of different
type. Logical or numerical operations can be evaluated. Before
evaluating the given rules the parameters given in the algorithm are
replaced. If a parameter was not correctly found the rule cannot be
evaluated. Make sure that either a value or a default is given for the
specific parameter.
Variables enclosed in ${variable.name}
First parameters have to be replaced hierarchically (not within this method), then calculation takes
place (here!).
${some.parameter.name} * 15 / ${some.other.param${param.index.param}}
Constant numerical values:
- Numbers in double type
- rand or random as alias for random numbers between 0 and 1
- "Not a number" (NaN): "NaN"
- Boolean TRUE (1)
- Boolean FALSE (0)
- Current time ms (System.currentTimeMillis()): "CURR_MILLIS"
- One day in ms (LangUtil?.DAY_MILLIS): "DAY_MILLIS"
- One Week in ms (LangUtil?.WEEK_MILLIS): "WEEK_MILLIS"
Constant String values
- Character arrays are started and ended by " or '.
2-partner arithmetic operation
- Summation: "+"
- Subtraction: "-"
- Multiplication: "*"
- Division: "/"
- Exponent: ""
15 + 5.6 (20.6)
The 2-partner Boolean operator
- Boolean AND: "&"
- Boolean OR: "|"
- Equals: "=" or "=="
- Unequal: "!=" or "<>"
- Smaller than: "<"
- Greater than ">"
- Smaller equals: "<="
- Greater equals: ">="
The 2-partner character
operation
- String-concatenation: "+"
- Regular expression check: "regex(expression,regular expr)"
- First value of a String-Splits via regular expression:
"split(expression,regular expr)"
- N-th value of the string split via regular expression:
"split(expression,regular expr,n)"
- String-Replace: "replAll(expression,pattern expr,repl expr)"
The singular operation
- Absolute Value: "abs(.)"
- Square root: "sqr(.)" or "sqrt(.)"
- Round: "rnd(.)" or "round(.)"
- Cut: "int(.)" or "trunc(.)"
- Test Not A Number (NaN): "isNaN(.)"
- Sinus: "sin(.)"
- Co sinus: "cos(.)"
- Tangent: "tan(.)"
- Arcos-Sinus: "arcsin(.)" or "asin(.)"
- Arcos - Co sinus: "arccos(.)" or "acos(.)"
- Arcos - Tangent: "arctan(.)" or "atan(.)"
- Exponential: "exp(.)"
- Logarithmic base e: "ln(.)"
- Logarithmic base 10: "log(.)"
The singular Boolean operation
The singular String operation
- Boolean NOT: "!(.)"
- Convert Number to String: "str(.)"
- Convert String to Number: "val(.)"
- Convert to upper case: "toupper(.)"
- Convert to lower case: "tolower(.)"
- Convert date-String to Milli-Seconds: str2millis(string expr,
format string expr)
- Convert date to Milli-Seconds: date2millis(year, month, day)
- Convert Milli-Seconds to date-String: millis2Str(millis, format
string expr)
- Convert date to date-String: date2Str(year, month, day, format
string expr)
The 3-partner operation ITE(.,.,.)
First parameter is replaced, then checked first partner. Result (0)
if parameter was > 5, (1) if not
To combine Boolean and arithmetic operations the operands have to be
coded as (1) or (0), not as TRUE or FALSE where op > 0 is TRUE and 0
is FALSE.
returns the result ot the rule
public static String
processTemplate(String aTemplate, SimpleFeature
tFeatureToUse, ResultSet aResultSet, Map aParameterMap);
- aTemplate
- tFeatureToUse
- aResultSet
- aParameterMap
returns a processed Template
public static String
combineHTML(String aHTMLBefore, String aStyleSheet)
throws IOException;
Reads the html and the stylesheet from the parameters and returns a combined html.
returns a combined html
public static void saveProblemReport();
public static Map
transformMapToStringValue(Map aParameterMap);
returns Map, transformed to String value
public static Map
getParametersMatchingRegex(Map aMap, String aRegexString);
returns parameters, which match the given Regex
public static Set
getParametersFromString(String aString);
- aString to be analyzed for Parameters
returns a Set of all Parameters within the given String
public static void
replaceParamsInFile(
FWObservable aObservable, File aFile);
- aFile
- aObservable containing Parameter Map and File
replaces Parameters and evaluates the expressions within the given Textfile
public static Map
createMapFromCollection(Collection tLoopList);
returns Map, created from Collection
}