Package net.simplace.sim.util
Class FWSimHelper
java.lang.Object
net.simplace.sim.util.FWSimHelper
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 Summary
Modifier and TypeFieldDescriptionstatic final Pattern
[!]static final Pattern
[!]static Comparator<FWSimFieldContainer>
static final Pattern
[$][{][^},^{]*[}]static final Pattern
[$][{][^},^{]*[}]static final Comparator<FWSimVariable<?>>
Instantiates the Comparator for SimVariables to order them within the SimComponent (used for nice output) -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
addResourceFiles
(String aWorkDir, String aSimulationExperimentPath, String aSolutionFileName, String aProjectFileName) static LinkedHashMap<String,
String> ArrayToLinkedMap
(Object[] aArray) converts a Object[] to a LinkedHashMapArrayToMap
(Double[] aArray) converts a double[] to a tree mapstatic Boolean
checkForAction
(LocalDateTime aCurrentDate, FWSimIOAdapter.FREQUENCE aFrequence, JexlRuleScript aJexlScript, FWSimVarMap aVarMap) static void
edit
(FWSimFieldContainer aContainer, boolean aEnabled) static HashMap<String,
FWSimVariable<?>> filterVarMap
(HashMap<String, FWSimVariable<?>> aMap, String aRegexp) static Collection<String>
findResources
(String aPackage, String aRegexp) static String
generateSimulationID
(Integer aProjectIteration, String aProjectID, String aSimulationName, Integer aSimulationNumber) static FWSimVariable.DATA_TYPE
getDataTypeFromValue
(String aFirstValue) static Object[][]
getObjectArrayFromVarMap
(FWSimVarMap aVarMap) static String
getParameterName
(String aKey) getParametersFromString
(Pattern pattern, String aString) static Object
getValueFromSpecialParameter
(FWSimVarMap aParamMap, String aKey, Object aDefault) getting parameter value from key if value is Map, Array, List or Date using '!'static void
logInitialInfo
(boolean aForce) Log system information at beginning of the application startstatic PreparedStatement
prepareCountSelect
(String aTableName, String aConnectionPoolDefault) static PreparedStatement
prepareDatabase
(String aTableName, HashMap<String, FWSimVariable<?>> aHeaderVariables, String aConnectionPoolDefault, boolean aDropIfExists, boolean aDoCreateTable) static PreparedStatement
prepareLimitedSelect
(String aTableName, HashMap<String, FWSimVariable<?>> aFieldMap, String aConnectionPoolDefault) static String
replaceParamTokens
(FWSimVarMap aParamMap, String aValue, Object aDefault) replaces Parameters instatic void
showFields
(FWSimFieldContainer aVertex) splitProjectDataByNumberOfCores
(File aProjectDataFile, String aDivider, int[] aListOfCores) static LinkedHashMap<String,
String> splitProjectDataBySimulationCount
(File aProjectDataFile, String aDivider, int aSplitCount) static LinkedHashMap<String,
String> splitProjectDataBySimulationCount
(File aProjectDataFile, String aDivider, int aSplitNumber, String[][] aReadCSVtoArray) static Object
unzipArray
(FWSimVariable<?> aTargetVariable, ArrayList<String> aFieldMapIndizes, Object[] aSourceArray, Set<String> aParametersFromString, FWSimFieldContainer aContainer) Implement rules for expressions like !static Object
zipArray
(FWSimVariable<?> aTargetVariable, ArrayList<String> aFieldMapIndizes, Object[] aSourceArray, Set<String> aParametersFromString, FWSimFieldContainer aContainer) Implemented rules for expressions like !
-
Field Details
-
PARAMPATTERN
[$][{][^},^{]*[}] -
PARAMSEARCHPATTERN
[$][{][^},^{]*[}] -
EXPRESSIONPATTERN
[!][A-Z]*:.*[!] -
ARRAYVALUEPATTERN
[!][A-Z]*:.*[!] -
FIELD_COMPERATOR
-
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
replaces Parameters in- Parameters:
aValue
- matching the regexp '.*[${].*[}].*' with given parameters inaParamMap
-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
- Parameters:
pattern
-aString
-- Returns:
- parameters from a given aString
-
ArrayToLinkedMap
converts a Object[] to a LinkedHashMap- Parameters:
aArray
-- Returns:
- the fixed ordered tree map
-
ArrayToMap
converts a double[] to a tree map- Parameters:
aArray
-- Returns:
- the fixed ordered tree map
-
findSimComponents
- Returns:
- a List of Strings representing the Classes extended from FWSimComponent
-
findResources
- Parameters:
aPackage
-aRegexp
-- Returns:
- a List of Strings representing the Classes extended from FWSimComponent
-
findResourceTransformers
- Returns:
- a List of Strings representing the Classes extended from FWSimResourceTransformer
-
findSelectors
- Returns:
- a List of Strings representing the Classes extended from FWSimulationSelector
-
findGenerators
- Returns:
- a List of Strings representing the Classes extended from FWSimulationSelector
-
findIterators
- Returns:
- a List of Strings representing the Classes extended from FWSimulationSelector
-
showFields
- Parameters:
aVertex
-
-
edit
- Parameters:
aContainer
-aEnabled
-
-
getDataTypeFromValue
- Parameters:
aFirstValue
-- Returns:
- the fitting data type
-
getObjectArrayFromVarMap
- Parameters:
aVarMap
-- Returns:
- the Object Array containing keys and values of the data
-
getParameterName
- 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
-
splitProjectDataBySimulationCount
public static LinkedHashMap<String,String> splitProjectDataBySimulationCount(File aProjectDataFile, String aDivider, int aSplitCount) - Parameters:
aProjectDataFile
-aDivider
-aSplitCount
-- Returns:
- a list divided by aSplitNumber
-
splitProjectDataBySimulationCount
-
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)
-