Class FWSimVariable<T>

java.lang.Object
net.simplace.sim.util.FWSimVariable<T>
Type Parameters:
T -
Direct Known Subclasses:
FWSimCalibrationVariable

public class FWSimVariable<T> extends Object
Author:
Andreas Enders
  • Constructor Details

  • Method Details

    • createSimVariable

      public static FWSimVariable<?> createSimVariable(org.jdom2.Element aVarElement, FWSimFieldContainer aFWSimFieldContainer)
      factory method to create a FWSimVariable (Typed)
      Parameters:
      aVarElement -
      aFWSimFieldContainer -
      Returns:
      the new created Variable
    • createSimVariable

      public static FWSimVariable<?> createSimVariable(String aName, String aDesc, FWSimVariable.DATA_TYPE aDataType, FWSimVariable.CONTENT_TYPE aContentType, String aUnit, Number aMin, Number aMax, Object aDefault, FWSimFieldContainer aSourceSimComponent)
      factory method to create a component sim variable for FWSimVariable.CONTENT_TYPE out use method above
      Parameters:
      aName -
      aDesc -
      aDataType -
      aContentType -
      aUnit -
      aMin -
      aMax -
      aDefault -
      aSourceSimComponent -
      Returns:
      the new created Variable
    • createOutputSimVariable

      public static FWSimVariable<?> createOutputSimVariable(String aName, String aDesc, String aRule, FWSimVariable.DATA_TYPE aDataType, String aUnit, String aOutputFormat, Object aDefault, FWSimVariable.MODE_TYPE aModeType, FWSimFieldContainer aTarget)
      factory method to create an output (system-output - not component output) sim variable for FWSimVariable.CONTENT_TYPE out use method above.
      Parameters:
      aName -
      aDesc -
      aRule -
      aDataType -
      aUnit -
      aOutputFormat -
      aDefault -
      aModeType -
      aTarget -
      Returns:
      the new created Variable
    • createSimVariable

      public static FWSimVariable<?> createSimVariable(String aName, String aDesc, String aRule, FWSimVariable.DATA_TYPE aDataType, FWSimVariable.CONTENT_TYPE aContentType, String aUnit, Object aValue, Number aMin, Number aMax, Object aDefault, Integer[] aCount, FWSimVariable.MODE_TYPE aModeType, FWSimVarMap aVarMap, FWSimFieldContainer aSourceSimComponent)
      standard constructor for FWSimVariable - called from clone, too.
      Parameters:
      aName - Variable name
      aDesc - Description
      aRule -
      aDataType - Data type
      aContentType - Input, output, etc
      aUnit - Units
      aValue - (internal use, not for initializing)
      aMin - Minimum
      aMax - Maximum
      aDefault - Default, use when initializing constants or inputs
      aCount -
      aModeType -
      aVarMap - (internal use, not for initializing)
      aSourceSimComponent - SimModel declaring the variable
      Returns:
    • fillMetaDataFromSource

      public void fillMetaDataFromSource(FWSimVarMap aVarMap)
      Parameters:
      aVarMap -
    • isNumber

      public boolean isNumber()
      Returns:
      if Variable is a Number (int or double)
    • hasRule

      public boolean hasRule()
      Returns:
      true if has a rule implemented
    • isDouble

      public boolean isDouble()
      Returns:
      true if variable is double or array of double
    • isInt

      public boolean isInt()
      Returns:
      true if variable contains int or array of int
    • isBoolean

      public boolean isBoolean()
      Returns:
      true if variable is boolean
    • isString

      public boolean isString()
      Returns:
      true if variable is char type
    • isDate

      public boolean isDate()
      Returns:
      true if variable is of date type
    • isArray

      public boolean isArray()
      Returns:
      true if variable is an array (int or double)
    • isOutputContent

      public boolean isOutputContent()
      Returns:
      false if this is of type Input field: input or constant, else true
    • isInputContent

      public boolean isInputContent()
      Returns:
      true if this is of type Input field: input or constant, else false
    • isMeasData

      public boolean isMeasData()
      Returns:
      the isMeasData
    • getDescription

      public String getDescription()
      Returns:
      description of this variable
    • getOrder

      public String getOrder()
      Returns:
      order of this variable
    • getDataType

      public FWSimVariable.DATA_TYPE getDataType()
      Returns:
      the dataType
    • getContentType

      public FWSimVariable.CONTENT_TYPE getContentType()
      Returns:
      the contentType
    • getCategory

      public FWSimVariable.VARIABLE_CATEGORY getCategory()
    • getModeType

      public FWSimVariable.MODE_TYPE getModeType()
      Returns:
      the modeType
    • getMax

      public Number getMax()
      Returns:
      the max
    • getMin

      public Number getMin()
      Returns:
      the min
    • getValue

      public T getValue()
      Use this method to get value out of the variable by default!
      Returns:
      the value
    • getArrayValue

      public Number getArrayValue(int aIndex)
      Use this method to get value out of the variable by default!
      Parameters:
      aIndex -
      Returns:
      the value
    • getMatrixValue

      public Double getMatrixValue(int aXIndex, int aYIndex)
      Use this method to get value out of the variable by default!
      Parameters:
      aXIndex -
      aYIndex -
      Returns:
      the value
    • forceDoubleMapValue

      public TreeMap<Double,Double> forceDoubleMapValue() throws SimFieldTypeException
      Returns:
      a Tree Map with fixed order derived from a double array
      Throws:
      SimFieldTypeException - if value was NO double array
    • forceBooleanValue

      public boolean forceBooleanValue(boolean aDefault)
      forces a value to be returned as boolean !!! don't use this method for variables type Boolean !!!
      Parameters:
      aDefault - - taken if conversion is not successful
      Returns:
      the boolean parameter - or the default
    • forceDoubleValue

      public double forceDoubleValue()
      forces a value to be returned as double !!! don't use this method for variables type double !!!
      Returns:
      the double parameter
    • forceIntValue

      public int forceIntValue()
      forces a value to be returned as integer !!! don't use this method for variables type integer !!!
      Returns:
      the integer parameter
    • forceStringValue

      public String forceStringValue()
      forces a value to be returned as string !!! don't use this method for variables type string !!!
      Returns:
      the string parameter
    • setDefaultValue

      public void setDefaultValue()
      replaces the value with the default - even if default is null value
    • reset

      public void reset()
      replaces the value with the default - even if default is null value
    • setVarMap

      public void setVarMap(FWSimVarMap aFwSimvarMap)
      Parameters:
      aFwSimvarMap -
    • setModeType

      public void setModeType(FWSimVariable.MODE_TYPE aModeType)
      Parameters:
      aModeType -
    • setRule

      public void setRule(String aRule)
      Parameters:
      aRule -
    • setName

      public void setName(String aNewName)
      Parameters:
      aNewName - only used for generator purpose
    • changeDefaultValue

      public void changeDefaultValue(T aValue)
      changes default value
      Parameters:
      aValue -
    • setNull

      public void setNull(FWSimFieldContainer aSource)
      sets value to null: - checks for authentication - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimLinkInvalidException
    • setValue

      public void setValue(T aValue, FWSimFieldContainer aSource)
      standard set Value method: - checks for min and max limits - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aValue - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
      SimLinkInvalidException
    • setValue

      public void setValue(FWSimVariable<T> aVariable, FWSimFieldContainer aSource) throws SimValueOutOfRangeException, SimLinkInvalidException
      standard set Value method: - checks for min and max limits - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aVariable - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
      SimLinkInvalidException
    • addValue

      public void addValue(T aValue, FWSimFieldContainer aSource) throws SimValueOutOfRangeException
      standard set Value method: - checks for min and max limits - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aValue - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
    • addValue

      public void addValue(FWSimVariable<T> aVariable, FWSimFieldContainer aSource) throws SimValueOutOfRangeException
      standard set Value method: - checks for min and max limits - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aVariable - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
    • multiplyValue

      public void multiplyValue(Number aValue, FWSimFieldContainer aSource) throws SimValueOutOfRangeException
      standard set Value method: - checks for min and max limits - sets the current date when the value had changed last time - but only if SimModel was registered
      Parameters:
      aValue - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
    • setArrayValue

      public void setArrayValue(int aIndex, Number aValue, FWSimFieldContainer aSource) throws SimValueOutOfRangeException, SimFieldTypeException
      special method for setting values to an array type variable
      Parameters:
      aIndex - of the array value should be set to
      aValue - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
      SimFieldTypeException - if variable is NO array
    • setArrayValue

      public void setArrayValue(int aIndex, String aValue, FWSimFieldContainer aSource) throws SimValueOutOfRangeException, SimFieldTypeException
      special method for setting values to an array type variable
      Parameters:
      aIndex - of the array value should be set to
      aValue - the value to set
      aSource - Component who wants to set this value - for checking purpose
      Throws:
      SimValueOutOfRangeException - if new value exceeds the limits of Min and Max value
      SimFieldTypeException - if variable is NO array
    • getName

      public String getName()
      Returns:
      the name
    • getInternalName

      public String getInternalName()
      Returns:
      The Name of the Variable without the component Name
    • getUnit

      public String getUnit()
      Returns:
      the unit
    • getFormat

      public String getFormat()
      Returns:
      the format
    • getFormatter

      public Object getFormatter()
      Returns:
      the format
    • getStringUnit

      public String getStringUnit()
      Returns:
      the unit
    • getDefault

      public T getDefault()
      Returns:
      the default
    • getRule

      public String getRule()
      Returns:
      the rule implemented in the variable
    • calculateValue

      public Object calculateValue(FWSimVarMap aVarMap)
      Parameters:
      aVarMap -
      Returns:
      the result of the rule implemented in the variable will be set to the value field.
    • evaluate

      public Object evaluate(FWSimVarMap aVarMap)
      Parameters:
      aVarMap -
      Returns:
      the result of the rule implemented in the variable
    • evaluate

      public Object evaluate()
      Returns:
      the result of the rule implemented in the variable
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • getStringValue

      public String getStringValue()
      Returns:
      a fromatted string value
      See Also:
    • toShortString

      public String toShortString()
      Returns:
      the name as short string
    • toDebugString

      public String toDebugString()
      Returns:
      long debugging string value with all content of the variable
    • toXML

      public org.jdom2.Element toXML()
      Returns:
      the Element of the variable with all needed values
    • getFieldName

      public String getFieldName()
      Returns:
      the short name without container information
    • getCount

      public Integer[] getCount()
      Returns:
      the count of items in the array
    • setCount

      public Integer[] setCount(int aCount)
      Parameters:
      aCount - count of the params
      Returns:
      the count of items in the array
    • setCount

      public void setCount(Integer[] aArray)
      Parameters:
      aArray - of the counts
    • setFormat

      public void setFormat(String aFormat)
      Parameters:
      aFormat -
    • setValueAndDefault

      public static <F> F setValueAndDefault(Object aObject, FWSimVariable<F> aSimVariable, FWSimFieldContainer aSourceComponent) throws SimValueOutOfRangeException, SimLinkInvalidException
      static factory implementation for setting unknown object type to a given FWSimVariable with type F
      Type Parameters:
      F -
      Parameters:
      aObject - value
      aSimVariable - to which the value is to be set
      aSourceComponent - Component who wants to set this value - for checking purpose
      Returns:
      the Value set with correct type
      Throws:
      SimValueOutOfRangeException
      SimLinkInvalidException
    • setValue

      public static <F> F setValue(Object aObject, FWSimVariable<F> aSimVariable, FWSimFieldContainer aSourceComponent) throws SimValueOutOfRangeException, SimLinkInvalidException
      static factory implementation for setting unknown object type to a given FWSimVariable with type F
      Type Parameters:
      F -
      Parameters:
      aObject - value
      aSimVariable - to which the value is to be set
      aSourceComponent - Component who wants to set this value - for checking purpose
      Returns:
      the Value set with correct type
      Throws:
      SimValueOutOfRangeException
      SimLinkInvalidException
    • transformDataType

      public static Object transformDataType(String aObject, FWSimVariable.DATA_TYPE aDataType) throws NumberFormatException
      static implementation of a data converter if possible use static setValue()-Method instead
      Parameters:
      aObject -
      aDataType -
      Returns:
      the transformed data object
      Throws:
      NumberFormatException
    • transformDataType

      public static Object transformDataType(String aObject, FWSimVariable<?> aSimVariable) throws NumberFormatException
      static implementation of a data converter if possible use static setValue()-Method instead
      Parameters:
      aObject -
      aSimVariable -
      Returns:
      the transformed data object
      Throws:
      NumberFormatException
    • transformDataTypeToDB

      public static String transformDataTypeToDB(FWSimVariable.DATA_TYPE aDataType)
      transforms from Database type to FWSimVariable.DATA_TYPE
      Parameters:
      aDataType - used in database
      Returns:
      the FWSimVariable.DATA_TYPE
    • transformDBDataType

      public static FWSimVariable.DATA_TYPE transformDBDataType(String dataType)
      transforms from Database type to FWSimVariable.DATA_TYPE
      Parameters:
      dataType - used in database
      Returns:
      the FWSimVariable.DATA_TYPE
    • transformJavaDataType

      public static String transformJavaDataType(FWSimVariable.DATA_TYPE aDataType)
      Parameters:
      aDataType -
      Returns:
      the Java Type Name
    • transformJavaDataType

      public static FWSimVariable.DATA_TYPE transformJavaDataType(String dataType)
      transforms from written code style type to FWSimVariable.DATA_TYPE
      Parameters:
      dataType - used in java code
      Returns:
      the FWSimVariable.DATA_TYPE
    • transformContentType

      public static String transformContentType(FWSimVariable.CONTENT_TYPE aContentType)
      Parameters:
      aContentType -
      Returns:
      good toString information
    • getPrefix

      public String getPrefix()
      Returns:
      the matching prefix
    • addPrefix

      public String addPrefix(String aFieldName)
      Parameters:
      aFieldName -
      Returns:
      the field name with matching prefix
    • check

      public String check(FWSimVariable<?> aOutputVar)
      checking routine for 2 different SimVariables that are to be linked together
      Parameters:
      aOutputVar -
      Returns:
      an error string - if string is null everything seems to be perfect!
    • getSource

      public FWSimFieldContainer getSource()
      Returns:
      the component registered as source component
    • getVarMap

      public FWSimVarMap getVarMap()
      Returns:
      the VarMap connected to this Variable
    • setSource

      public void setSource(FWSimFieldContainer aComponent)
      changing registered source component for this variable ! use this with care! should not be used by default
      Parameters:
      aComponent -
    • addOutputLink

      public void addOutputLink(String aFieldName) throws SimLinkInvalidException
      adding a link to the output-part of the link.
      Parameters:
      aFieldName -
      Throws:
      SimLinkInvalidException - if variable is no output field!
    • addInputLink

      public void addInputLink(String aFieldName) throws SimLinkInvalidException
      adding a link to the output-part of the link.
      Parameters:
      aFieldName -
      Throws:
      SimLinkInvalidException - if variable is no output field!
    • removeLink

      public void removeLink(String aName)
      Parameters:
      aName -
    • isInputLinked

      public boolean isInputLinked() throws SimLinkInvalidException
      Returns:
      if is linked to another field as input
      Throws:
      SimLinkInvalidException - if field is no input
    • isOutputLinked

      public boolean isOutputLinked()
      Returns:
      if is linked to another field as output
    • getRuleComplexity

      public JexlRuleScript.COMPLEXITY getRuleComplexity()
      Returns:
      the complexRule
    • clone

      public FWSimVariable<T> clone(FWSimVarMap aVarMap)
      deep clone of the SimVariable copying all fields to a new variable
      Parameters:
      aVarMap -
      Returns:
      a new cloned FWSimVariable with identical meta data
      See Also:
    • deepClone

      public FWSimVariable<T> deepClone(FWSimVarMap aVarMap)
      Parameters:
      aVarMap -
      Returns:
    • setContentType

      public void setContentType(FWSimVariable.CONTENT_TYPE aContentType)
      Parameters:
      aContentType -
    • createFormFields

      public static org.jdom2.Element createFormFields(FWSimVariable<?> aVariable, FWSimVariable.CONTENT_TYPE aComponentContentType, String aDescription, String aFrequence, String aVisible, String aEnabled, boolean aMultipleVarType)
      Parameters:
      aVariable -
      aComponentContentType -
      aDescription -
      aFrequence -
      aVisible -
      aEnabled -
      aMultipleVarType -
      Returns:
      the FormElement
    • createFormFields

      public static org.jdom2.Element createFormFields(String aName, String aDescription, String aContentTypeDefault, String aVisible, String aEnabled, FWSimVariable.CONTENT_TYPE aComponentContentType)
      Parameters:
      aName -
      aDescription -
      aContentTypeDefault -
      aVisible -
      aEnabled -
      aComponentContentType -
      Returns:
      the FormElement
    • createMultipleFormElement

      public static org.jdom2.Element createMultipleFormElement(FWSimVariable<?> aVariable, String aName, String aDescription, String aVisible, String aEnabled, String aContentType, String tModeType, boolean aModeNeeded, String aFrequence, String tDataType, String tUnit, String tMax, String tMin, String tRule, String tDesc, String tDefault, FWSimVariable.CONTENT_TYPE aComponentContentType)
      Parameters:
      aVariable -
      aName -
      aDescription -
      aVisible -
      aEnabled -
      aContentType -
      tModeType -
      aModeNeeded -
      aFrequence -
      tDataType -
      tUnit -
      tMax -
      tMin -
      tRule -
      tDesc -
      tDefault -
      aComponentContentType -
      Returns:
      the Form Element
    • createFormElement

      public static org.jdom2.Element createFormElement(FWSimVariable<?> aVariable, String aName, String aDescription, String aVisible, String aEnabled, String aContentType, String aModeType, boolean aModeNeeded, String tDataType, String tUnit, String tMax, String tMin, String tRule, String tDesc, String tDefault, FWSimVariable.CONTENT_TYPE aComponentContentType)
      Parameters:
      aVariable -
      aName -
      aDescription -
      aVisible -
      aEnabled -
      aContentType -
      aModeType -
      aModeNeeded -
      tDataType -
      tUnit -
      tMax -
      tMin -
      tRule -
      tDesc -
      tDefault -
      aComponentContentType -
      Returns:
      the Form Element
    • updateFields

      public void updateFields(org.jdom2.Element aVarElement)
      Parameters:
      aVarElement -
    • updateFields

      public static FWSimVariable<?> updateFields(FWSimVariable<?> aVariable, FWObservable aObservable) throws SimLinkInvalidException, SimValueOutOfRangeException
      Parameters:
      aVariable -
      aObservable -
      Returns:
      a new created sim variable
      Throws:
      SimValueOutOfRangeException
      SimLinkInvalidException
    • getFormComponentXML

      public org.jdom2.Element getFormComponentXML()
      Returns:
      the generated form xml
    • getDateFormatter

      public FWSimVariable.DateFormatter getDateFormatter(String aPattern)
    • equals

      public boolean equals(Object aObj)
      Overrides:
      equals in class Object
    • toHTMLTablestring

      public String toHTMLTablestring()
      Returns:
      the HTML Table String