Class FWSimVarMap

java.lang.Object
net.simplace.sim.util.FWSimVarMap
All Implemented Interfaces:
org.apache.commons.jexl3.JexlContext

public class FWSimVarMap extends Object implements org.apache.commons.jexl3.JexlContext
Each parameter has a "string" name Value is given as implemented member of Variable Variable has last changed date instance, creator reference and value Has a general simulation (model run) and project (project run) id Implements a HashMap <String, Object> Has replacement method for parameter tokens Linking Variables can hereby be checked for: Unit, DataType and ContentType Setting Value can be checked for DataType, Source of Data, Min/Max Debugging can be done using Description, Unit, Date last changed (same day yesterday, ), Source of value
Author:
Andreas Enders
  • Field Details

    • CURRENT_DATE

      public static final String CURRENT_DATE
      signifying the string used as id for the current date in the VarMap
      See Also:
    • CURRENT_YEAR

      public static final String CURRENT_YEAR
      signifying the string used as id for the current year in the VarMap
      See Also:
    • CURRENT_DAY

      public static final String CURRENT_DAY
      signifying the string used as id for the current day of month
      See Also:
    • CURRENT_MONTH

      public static final String CURRENT_MONTH
      signifying the string used as id for the current month in the VarMap
      See Also:
    • CURRENT_DOY

      public static final String CURRENT_DOY
      signifying the string used as id for the current day of year
      See Also:
    • PROJECT_ID

      public static final String PROJECT_ID
      signifying the string used as id for the current date in the VarMap
      See Also:
    • PROJECT_ITERATION

      public static final String PROJECT_ITERATION
      signifying the string used as id for the current date in the VarMap
      See Also:
    • SIMULATION_ID

      public static final String SIMULATION_ID
      signifying the string used as id for the current date in the VarMap
      See Also:
    • SIMULATION_NAME

      public static final String SIMULATION_NAME
      signifying the string used as id for the current date in the VarMap
      See Also:
    • SIMULATION_NUMBER

      public static final String SIMULATION_NUMBER
      signifying the string used as id for the current date in the VarMap
      See Also:
    • SESSION_ID

      public static final String SESSION_ID
      signifying the string used as id for the current date in the VarMap
      See Also:
    • SPINUP_DAYS

      public static final String SPINUP_DAYS
      signifying the integer number of spin up days in the VarMap
      See Also:
    • SPINUP_DO_RESET

      public static final String SPINUP_DO_RESET
      signifying whether date has to be reset after spinup
      See Also:
    • SPINUP_RESET

      public static final String SPINUP_RESET
      signifying whether date was reset after spinup
      See Also:
    • SYNCHRONIZE_FREQUENCE

      public static final String SYNCHRONIZE_FREQUENCE
      signifying whether threads are synchronized within one project (true) or not (false)
      See Also:
    • SYNCHRONIZE_RULE

      public static final String SYNCHRONIZE_RULE
      the rule for the data synchronized within one project if FREQUENCE is COMPLEX
      See Also:
    • PROJECT_LINES

      public static final String PROJECT_LINES
      projectlines that are read from project file
      See Also:
    • SIMULATIONS_SELECTED

      public static final String SIMULATIONS_SELECTED
      signifying whether date has to be reset after spinup
      See Also:
    • END_DATE

      public static final String END_DATE
      signifying the string used as id for the end date in the VarMap
      See Also:
    • START_DATE

      public static final String START_DATE
      signifying the string used as id for the end date in the VarMap
      See Also:
    • DATE_FORMAT

      public static final DateTimeFormatter DATE_FORMAT
      Parser for operations to be calculated
  • Constructor Details

    • FWSimVarMap

      public FWSimVarMap(HashMap<String,FWSimVariable<?>> aFormInputParameterMap, FWSimModel aModel, String aProjectID, FWSimSession aCurrentSession)
      Parameters:
      aFormInputParameterMap -
      aModel -
      aProjectID -
      aCurrentSession -
    • FWSimVarMap

      public FWSimVarMap(HashMap<String,FWSimVariable<?>> aParameterMap)
      Parameters:
      aParameterMap -
    • FWSimVarMap

      public FWSimVarMap()
      For documentation reasons
  • Method Details

    • setWaiting

      public void setWaiting(boolean shouldWait) throws InterruptedException
      Throws:
      InterruptedException
    • getVarMap

      public HashMap<String,FWSimVariable<?>> getVarMap()
      Returns:
      the parameterMap
    • getStringValue

      public String getStringValue(String aKey)
      Parameters:
      aKey -
      Returns:
      one parameter value for given key - null if key was not set
    • forceIntegerValue

      public Integer forceIntegerValue(String aKey)
      Parameters:
      aKey -
      Returns:
      one parameter converted to Integer value for given key - null if key was not set or value not convertible
    • forceDoubleValue

      public Double forceDoubleValue(String aKey)
      Parameters:
      aKey -
      Returns:
      one parameter converted to Double value for given key - null if key was not set or value not convertible
    • forceBooleanValue

      public boolean forceBooleanValue(String aParamKey)
      used if generic type of the SimVariable is different but convertable to boolean. otherwise use getValue()!
      Parameters:
      aParamKey -
      Returns:
      boolean value to be forced from other data type
    • forceDateValue

      public LocalDateTime forceDateValue(String aParamKey)
      used if generic type of the SimVariable is different but convertable to date. otherwise use getValue()!
      Parameters:
      aParamKey -
      Returns:
      the date that was retrieved from convert.
    • forceDoubleArrayValue

      public Double[] forceDoubleArrayValue(String aString)
      used if generic type of the SimVariable is different but convertible to double array. otherwise use getValue()!
      Parameters:
      aString -
      Returns:
      the converted value
    • forceDoubleMapValue

      public TreeMap<Double,Double> forceDoubleMapValue(String aKey)
      used if generic type of the SimVariable is different but convertible to Double Map from array. otherwise use getValue()!
      Parameters:
      aKey -
      Returns:
      the converted value
    • forceIntegerArrayValue

      public Integer[] forceIntegerArrayValue(String aString)
      used if generic type of the SimVariable is different but convertible to integer array. otherwise use getValue()!
      Parameters:
      aString -
      Returns:
      the converted value
    • replaceParamTokens

      public String replaceParamTokens(String aString, Object aDefault)
      Replacement of parameters in a string is performed.
      Parameters:
      aString -
      aDefault -
      Returns:
      the new String after replacement of the different variable tags
      See Also:
    • getValue

      public Object getValue(String aKey)
      Parameters:
      aKey -
      Returns:
      object value of the FWSimVariable registered with key
    • getValue

      public Object getValue(String aKey, Object aDefault)
      Parameters:
      aKey -
      aDefault -
      Returns:
      object value of the FWSimVariable registered with key
    • setValue

      public void setValue(String aKey, Object aValue, FWSimVariable.DATA_TYPE aDataType, FWSimVariable.CONTENT_TYPE aContentType, FWSimFieldContainer aSourceComponent) throws SimValueOutOfRangeException
      sets the value to the FWSimVariable. If Max or Min rule is not successfully evaluated SimValueOutOfRangeException is thrown. It is typeof RuntimeException and need not to be handled If FWSimVariable is not existing it will be created with a warn Message in log.
      Parameters:
      aKey -
      aValue -
      aDataType -
      aContentType -
      aSourceComponent -
      Throws:
      SimValueOutOfRangeException
    • initValue

      public void initValue(String aKey, FWSimVariable<?> aFWSimVariable)
      new SimVariable is initialized and put to simVarMap
      Parameters:
      aKey -
      aFWSimVariable -
    • addVariable

      public void addVariable(String aKey, FWSimVariable<?> aFWSimVariable, boolean isLink)
      new SimVariable is initialized and put to simVarMap
      Parameters:
      aKey -
      aFWSimVariable -
      isLink -
    • getProjectID

      public String getProjectID()
      Returns:
      Identifier of this Functionality
    • getSimulationID

      public String getSimulationID()
      Returns the number of observers of this Observable object.
      Returns:
      the number of observers of this object.
    • generateSimulationID

      public String generateSimulationID()
      Returns the number of observers of this Observable object.
      Returns:
      the number of observers of this object.
    • setSimulationName

      public void setSimulationName(String aSimulationName)
      Parameters:
      aSimulationName -
    • getSimulationName

      public String getSimulationName()
      Returns:
      simulation name
    • getSimulationNumber

      public Integer getSimulationNumber()
      Returns:
      the simulation number
    • getIteration

      public Integer getIteration()
      Returns:
      the iteration number
    • getCurrentSession

      public FWSimSession getCurrentSession()
      Returns:
      the current session
    • isSynchronized

      public boolean isSynchronized()
      Returns:
      if session is synchronized
    • getSynchronizedFrequence

      public FWSimIOAdapter.FREQUENCE getSynchronizedFrequence()
      Returns:
      if session is synchronized
    • getSynchronizeRule

      public String getSynchronizeRule()
      Returns:
    • isWaiting

      public boolean isWaiting()
      Returns:
    • getCurrentDateString

      public String getCurrentDateString()
      calculates statistics
      Returns:
      Current model date toFormated string
    • getStartDate

      public LocalDateTime getStartDate()
      Returns:
      Start Date Variable
    • getEndDate

      public LocalDateTime getEndDate()
      Returns:
      End Date Variable
    • calculateStatistics

      public void calculateStatistics()
      calculates statistics
    • setProjectID

      public void setProjectID(String aProjectID)
      Parameters:
      aProjectID -
    • setSessionID

      public void setSessionID(String aSessionID)
      Parameters:
      aSessionID -
    • setSimulationNumber

      public void setSimulationNumber(Integer aSimulationNumber)
      Parameters:
      aSimulationNumber -
    • setCurrentSession

      public void setCurrentSession(FWSimSession aFwSimSession)
      Parameters:
      aFwSimSession -
    • removeVariable

      public void removeVariable(String aElement)
      use with care! Variable might be needed
      Parameters:
      aElement -
    • filterData

      public Object[] filterData(HashMap<String,FWSimVariable<?>> aFilterMap)
      filters data from the map and returns it as Object[]
      Parameters:
      aFilterMap -
      Returns:
    • filterData

      public Object[] filterData(Set<String> aKeySet)
      filters data from the map and returns it as Object[]
      Parameters:
      aKeySet -
      Returns:
    • putAllVariables

      public void putAllVariables(Map<String,FWSimVariable<?>> aVarMap)
      number of variables are added to the VarMap
      Parameters:
      aVarMap -
    • isVariableAvailable

      public boolean isVariableAvailable(String aKey)
      Parameters:
      aKey -
      Returns:
      s if a SimVariable is available
    • isSpinupPeriode

      public boolean isSpinupPeriode()
      Returns:
      s if system is in spin up period
    • doSpinupReset

      public boolean doSpinupReset()
      Returns:
    • toString

      public String toString()
      simple output of VarMap
      Overrides:
      toString in class Object
      See Also:
    • toArray

      public String[][] toArray()
      Returns:
      Key, SimVarName and Value as Array
    • addLink

      public void addLink(String aKey, FWSimVariable<?> aVar, boolean performChecks) throws SimLinkInvalidException
      Link between 2 SimVariables is added. If Link cannot be established a SimLinkInvalidException is thrown
      Parameters:
      aKey - of the target part of the link
      aVar - with the source part of the link
      performChecks -
      Throws:
      SimLinkInvalidException
    • removeLink

      public void removeLink(String aName, FWSimVariable<?> aFwSimVariable)
      Parameters:
      aName -
      aFwSimVariable -
    • initializeCurrentDate

      public void initializeCurrentDate(LocalDateTime aDate)
      Initializes the Current Date of the VarMap
      Parameters:
      aDate -
    • updateCurrentDate

      public void updateCurrentDate()
      used to set the current model date to the VarMap
    • getCurrentDate

      public LocalDateTime getCurrentDate()
      Returns:
      the current model date
    • setCurrentDate

      public void setCurrentDate(LocalDateTime aCurrentDate)
      Parameters:
      aCurrentDate - the current model date
    • getCurrentDOY

      public int getCurrentDOY()
      Returns:
      current DayOfYear
    • getCurrentYear

      public int getCurrentYear()
      Returns:
      current Year
    • getCurrentDayOfMonth

      public int getCurrentDayOfMonth()
      Returns:
      current Day of Month
    • getCurrentMonth

      public int getCurrentMonth()
      Returns:
      current Month
    • hasSimulationEnded

      public Boolean hasSimulationEnded()
      Returns:
      the simulationEnd
    • setSimulationEnd

      public void setSimulationEnd()
      sets the simulation end
    • clone

      public FWSimVarMap clone(FWSimSession aSession)
      deep clone on the SimVarMap - no references will stay same!
      Parameters:
      aSession -
      Returns:
      See Also:
    • cloneToControlMap

      public FWSimVarMap cloneToControlMap()
      deep clone on the SimVarMap - no references will stay same!
      Returns:
      See Also:
    • getSimLinks

      public HashMap<String,String> getSimLinks()
      Returns:
      a MultiHashMap containing all Links
    • reset

      public void reset()
      set all variables to default values
    • hasSimVariable

      public boolean hasSimVariable(String aRule)
      Parameters:
      aRule -
      Returns:
      if the registered FWSimVariable is available for the given key!
    • getSimVariable

      public FWSimVariable<?> getSimVariable(String aKey) throws SimFieldMissingException
      Parameters:
      aKey -
      Returns:
      the registered FWSimVariable - need not be the one with the given key!
      Throws:
      SimFieldMissingException
    • getValueToDatabaseString

      public String getValueToDatabaseString(String aSourceKey) throws SimFieldMissingException
      mainly used for Date, DoubleArray and IntArray to get String format of the values
      Parameters:
      aSourceKey -
      Returns:
      the value as converted database string
      Throws:
      SimFieldMissingException
    • getVariables

      public Set<FWSimVariable<?>> getVariables(FWSimVariable.CONTENT_TYPE aContentType)
      Parameters:
      aContentType -
      Returns:
      a list of Variables having this content type
    • getVariables

      Parameters:
      aContainer -
      aContentType -
      Returns:
      a list of Variables having this source container
    • has

      public boolean has(String aName)
      Decorates the class as MapContext
      Specified by:
      has in interface org.apache.commons.jexl3.JexlContext
      See Also:
      • org.apache.commons.jexl2.MapContext#has(java.lang.String)
    • get

      public Object get(String aName)
      Decorates the class as MapContext
      Specified by:
      get in interface org.apache.commons.jexl3.JexlContext
      See Also:
      • org.apache.commons.jexl2.MapContext#get(java.lang.String)
    • set

      public void set(String aName, Object aValue)
      Decorates the class as MapContext
      Specified by:
      set in interface org.apache.commons.jexl3.JexlContext
      See Also:
      • org.apache.commons.jexl2.MapContext#set(java.lang.String, java.lang.Object)
    • isInternal

      public static boolean isInternal(String aVarName)
    • checkInternal

      public boolean checkInternal(FWSimVariable<?> aFwSimVariable)