Class FWSimHelper

java.lang.Object
net.simplace.sim.util.FWSimHelper

public class FWSimHelper extends Object
Helper instance consisting of helper methods with instances of an operation tree parser to evaluate rules while replacing parameters in variables
Author:
Andreas Enders
  • Field Details

    • PARAMPATTERN

      public static final Pattern PARAMPATTERN
      [$][{][^},^{]*[}]
    • PARAMSEARCHPATTERN

      public static final Pattern PARAMSEARCHPATTERN
      [$][{][^},^{]*[}]
    • EXPRESSIONPATTERN

      public static final Pattern EXPRESSIONPATTERN
      [!][A-Z]*:.*[!]
    • ARRAYVALUEPATTERN

      public static final Pattern ARRAYVALUEPATTERN
      [!][A-Z]*:.*[!]
    • FIELD_COMPERATOR

      public static Comparator<FWSimFieldContainer> FIELD_COMPERATOR
    • SIM_VAR_COMARATOR

      public static final Comparator<FWSimVariable<?>> SIM_VAR_COMARATOR
      Instantiates the Comparator for SimVariables to order them within the SimComponent (used for nice output)
  • Constructor Details

    • FWSimHelper

      public FWSimHelper()
  • Method Details

    • replaceParamTokens

      public static String replaceParamTokens(FWSimVarMap aParamMap, String aValue, Object aDefault)
      replaces Parameters in
      Parameters:
      aValue - matching the regexp '.*[${].*[}].*' with given parameters in
      aParamMap -
      aDefault -
      Returns:
      aNewValue
    • getValueFromSpecialParameter

      public static Object getValueFromSpecialParameter(FWSimVarMap aParamMap, String aKey, Object aDefault)
      getting parameter value from key if value is Map, Array, List or Date using '!' as a separator.
      Parameters:
      aParamMap -
      aKey -
      aDefault -
      Returns:
      the new value object - if not retrieved the default.
    • getParametersFromString

      public static Set<String> getParametersFromString(Pattern pattern, String aString)
      Parameters:
      pattern -
      aString -
      Returns:
      parameters from a given aString
    • ArrayToLinkedMap

      public static LinkedHashMap<String,String> ArrayToLinkedMap(Object[] aArray)
      converts a Object[] to a LinkedHashMap
      Parameters:
      aArray -
      Returns:
      the fixed ordered tree map
    • ArrayToMap

      public static TreeMap<Double,Double> ArrayToMap(Double[] aArray)
      converts a double[] to a tree map
      Parameters:
      aArray -
      Returns:
      the fixed ordered tree map
    • findSimComponents

      public static List<String> findSimComponents()
      Returns:
      a List of Strings representing the Classes extended from FWSimComponent
    • findResources

      public static Collection<String> findResources(String aPackage, String aRegexp)
      Parameters:
      aPackage -
      aRegexp -
      Returns:
      a List of Strings representing the Classes extended from FWSimComponent
    • findResourceTransformers

      public static List<String> findResourceTransformers()
      Returns:
      a List of Strings representing the Classes extended from FWSimResourceTransformer
    • findSelectors

      public static List<String> findSelectors()
      Returns:
      a List of Strings representing the Classes extended from FWSimulationSelector
    • findGenerators

      public static List<String> findGenerators()
      Returns:
      a List of Strings representing the Classes extended from FWSimulationSelector
    • findIterators

      public static List<String> findIterators()
      Returns:
      a List of Strings representing the Classes extended from FWSimulationSelector
    • showFields

      public static void showFields(FWSimFieldContainer aVertex)
      Parameters:
      aVertex -
    • edit

      public static void edit(FWSimFieldContainer aContainer, boolean aEnabled)
      Parameters:
      aContainer -
      aEnabled -
    • getDataTypeFromValue

      public static FWSimVariable.DATA_TYPE getDataTypeFromValue(String aFirstValue)
      Parameters:
      aFirstValue -
      Returns:
      the fitting data type
    • getObjectArrayFromVarMap

      public static Object[][] getObjectArrayFromVarMap(FWSimVarMap aVarMap)
      Parameters:
      aVarMap -
      Returns:
      the Object Array containing keys and values of the data
    • getParameterName

      public static String getParameterName(String aKey)
      Parameters:
      aKey -
      Returns:
      the first parameter in the key string
    • unzipArray

      public static Object unzipArray(FWSimVariable<?> aTargetVariable, ArrayList<String> aFieldMapIndizes, Object[] aSourceArray, Set<String> aParametersFromString, FWSimFieldContainer aContainer)
      Implement rules for expressions like !UNZIP_KEYS(${C[])! = A[] !UNZIP_VALUES(${C[]})! = B[]
      Parameters:
      aTargetVariable -
      aFieldMapIndizes -
      aSourceArray -
      aParametersFromString -
      aContainer -
      Returns:
      the unzipped array
    • zipArray

      public static Object zipArray(FWSimVariable<?> aTargetVariable, ArrayList<String> aFieldMapIndizes, Object[] aSourceArray, Set<String> aParametersFromString, FWSimFieldContainer aContainer)
      Implemented rules for expressions like !ZIP(${A[]},${B[]})! = C[]
      Parameters:
      aTargetVariable -
      aFieldMapIndizes -
      aSourceArray -
      aParametersFromString -
      aContainer -
      Returns:
      the zipped Array
    • filterVarMap

      public static HashMap<String,FWSimVariable<?>> filterVarMap(HashMap<String,FWSimVariable<?>> aMap, String aRegexp)
      Parameters:
      aMap -
      aRegexp -
      Returns:
      returns a HashMap that contains only the entries whose keys matched the regexp
    • addResourceFiles

      public static File addResourceFiles(String aWorkDir, String aSimulationExperimentPath, String aSolutionFileName, String aProjectFileName) throws MissingSimResourceException
      Parameters:
      aWorkDir -
      aSimulationExperimentPath -
      aSolutionFileName -
      aProjectFileName -
      Returns:
      the ZipFile with all resources of the simulation experiment.
      Throws:
      MissingSimResourceException
    • logInitialInfo

      public static void logInitialInfo(boolean aForce)
      Log system information at beginning of the application start
      Parameters:
      aForce -
    • prepareDatabase

      public static PreparedStatement prepareDatabase(String aTableName, HashMap<String,FWSimVariable<?>> aHeaderVariables, String aConnectionPoolDefault, boolean aDropIfExists, boolean aDoCreateTable) throws SQLException
      Parameters:
      aTableName -
      aHeaderVariables -
      aConnectionPoolDefault -
      aDropIfExists -
      aDoCreateTable -
      Returns:
      the preparedStatement
      Throws:
      SQLException
    • prepareLimitedSelect

      public static PreparedStatement prepareLimitedSelect(String aTableName, HashMap<String,FWSimVariable<?>> aFieldMap, String aConnectionPoolDefault) throws SQLException
      Parameters:
      aTableName -
      aFieldMap -
      aSimulationsList -
      aConnectionPoolDefault -
      Returns:
      the prepared select Statement
      Throws:
      SQLException
    • prepareCountSelect

      public static PreparedStatement prepareCountSelect(String aTableName, String aConnectionPoolDefault) throws SQLException
      Parameters:
      aTableName -
      aConnectionPoolDefault -
      Returns:
      Throws:
      SQLException
    • generateSimulationID

      public static String generateSimulationID(Integer aProjectIteration, String aProjectID, String aSimulationName, Integer aSimulationNumber)
    • splitProjectDataBySimulationCount

      public static LinkedHashMap<String,String> splitProjectDataBySimulationCount(File aProjectDataFile, String aDivider, int aSplitCount)
      Parameters:
      aProjectDataFile -
      aDivider -
      aSplitCount -
      Returns:
      a list divided by aSplitNumber
    • splitProjectDataBySimulationCount

      public static LinkedHashMap<String,String> splitProjectDataBySimulationCount(File aProjectDataFile, String aDivider, int aSplitNumber, String[][] aReadCSVtoArray)
    • splitProjectDataByNumberOfCores

      public static List<String> splitProjectDataByNumberOfCores(File aProjectDataFile, String aDivider, int[] aListOfCores)
      Parameters:
      aProjectDataFile -
      aListOfCores -
      aDivider -
      Returns:
      a list divided by aListOfCores
    • checkForAction

      public static Boolean checkForAction(LocalDateTime aCurrentDate, FWSimIOAdapter.FREQUENCE aFrequence, JexlRuleScript aJexlScript, FWSimVarMap aVarMap)