Class FWFrameworkHelper

java.lang.Object
net.simplace.core.FWFrameworkHelper

public final class FWFrameworkHelper extends Object
Static helper methods of the framework, mainly for parameter maps: reading typed parameters, processing templates and localizing form component values. Parameter tokens and expressions are replaced by FWParameterResolver.
Author:
Andreas Enders
  • Field Details

    • WEBEUROSIGN

      public static final char WEBEUROSIGN
      the currency sign (ISO-8859-1 code 164)
      See Also:
  • Method Details

    • getParameterFromMap

      public static Object getParameterFromMap(Map<String,Object> aParamMap, String aKey, Object aDefault)
      Returns a parameter value. String values have their parameter tokens replaced (see FWParameterResolver.replace(Map, String, Object, boolean)).
      Parameters:
      aParamMap - the parameter map
      aKey - the key
      aDefault - value returned if the key is null or has no value
      Returns:
      the parameter value, or the default
    • getStringParameterFromMap

      public static String getStringParameterFromMap(Map<String,Object> aParamMap, String aKey, Object aDefault)
      Returns a parameter value as string, see getParameterFromMap(Map, String, Object).
      Parameters:
      aParamMap - the parameter map
      aKey - the key
      aDefault - value used if the parameter has no value
      Returns:
      the value as string, or null if neither value nor default exist
    • getNumberParameterFromMap

      public static <T extends Number> T getNumberParameterFromMap(Map<String,Object> aParamMap, String aKey, Class<T> aNumberType, T aDefault)
      Getting parameter value from map as a number.
      Type Parameters:
      T - the number type
      Parameters:
      aParamMap - map the parameter is taken from
      aKey - key for the map
      aNumberType - number type, the determined value is converted to (subclass of Number)
      aDefault - default value, which is returned if parameter not set or value can not be converted to aNumberType.
      Returns:
      parameter value from map as a number
    • processTemplate

      public static String processTemplate(String aTemplate, ResultSet aResultSet, Map<String,Object> aParameterMap)
      Replaces the tokens ${name} of a template: names in the parameter map or starting with _ via FWParameterResolver.replace(Map, String, Object, boolean), all others by the column of the current result set row. Errors are logged.
      Parameters:
      aTemplate - the template text
      aResultSet - result set (current row) providing column values, may be null
      aParameterMap - the parameter map
      Returns:
      the processed template (partially processed on errors)
    • transformMapToStringValue

      public static Map<String,String> transformMapToStringValue(Map<String,Object> aParameterMap)
      Parameters:
      aParameterMap - the parameter map
      Returns:
      a new map with the values as strings (toString()); null values are left out
    • getParametersMatchingRegex

      public static Map<Object,Object> getParametersMatchingRegex(Map<String,Object> aMap, String aRegexString)
      Parameters:
      aMap - the parameter map
      aRegexString - regular expression the whole key must match
      Returns:
      a new map with the entries whose keys match
    • replaceParamsInFile

      public static void replaceParamsInFile(FWObservable aObservable, File aFile)
      Replaces the parameters and evaluates the expressions within a text file; the file is overwritten. Errors are logged.
      Parameters:
      aObservable - provides the parameter map
      aFile - the text file
    • createMapFromCollection

      public static <T> Map<T,Object> createMapFromCollection(Collection<T> tLoopList)
      Type Parameters:
      T - element type
      Parameters:
      tLoopList - the elements
      Returns:
      a map (in element order) with the elements as keys and null values
    • createFormComponentLocaleBundleKey

      public static String createFormComponentLocaleBundleKey(FWObservable aObservable, String aFormComponentID, String aShortKey)
      Creates a locale bundle key for the specified short key. Parameter wildcards in short key are replaced from parameter map. Spaces in short key are replaced by "_". If form component ID is specified, it is used as prefix for locale bundle key (besides standard prefix: .FormComponent).
      Parameters:
      aObservable - used to retrieve the parameter map to replace wildcards in short key (from parameter map)
      aFormComponentID - form component ID, which is used as prefix for localization key (can be null or empty)
      aShortKey - short key
      Returns:
      null if aShortKey is null
    • localizeFormComponentValue

      public static String localizeFormComponentValue(FWObservable aObservable, String aFormComponentID, String aFormComponentValue)
      Localizes a form component value (e.g. table cell value from database) by generating a locale bundle key from value as follows: Parameter wildcards in form component value are replaced from parameter map. Spaces in form component value are replaced by "_". If form component ID is specified, it is used as prefix for locale bundle key (besides standard prefix: .FormComponent).
      Parameters:
      aObservable - used to retrieve the parameter map to replace wildcards in short key (from parameter map)
      aFormComponentID - form component ID, which is used as prefix for localization key (can be null or empty)
      aFormComponentValue - value to determine a localization for
      Returns:
      unchanged form component value, if no localization can be found
    • checkEquals

      public static boolean checkEquals(Object aValueCalculated, Object aValueExpected, FWSimVariable.DATA_TYPE aDATA_TYPE)
      Compares a calculated with an expected value according to the data type; doubles (also in arrays) are compared with a tolerance of 0.00001.
      Parameters:
      aValueCalculated - the calculated value
      aValueExpected - the expected value; null means no check
      aDATA_TYPE - the data type of both values
      Returns:
      true if the values are equal or no value is expected
    • toStringForm

      public static String toStringForm(Collection<FWSimVariable<?>> aVariableList, String aSeparator)
      Lists variables as text, one line name separator value per variable; dots in the names are replaced by the separator as well.
      Parameters:
      aVariableList - the variables
      aSeparator - the separator
      Returns:
      the lines, each ending with \r\n; empty for an empty list