Class ProcessVariableAccessor

java.lang.Object
neqsim.process.mpc.ProcessVariableAccessor

public class ProcessVariableAccessor extends Object
Accessor for reading and writing process variables by path.

Provides a unified interface for accessing any variable in a NeqSim ProcessSystem using a simple path notation.

Path formats supported:

  • Simple: "UnitName.propertyName" (e.g., "Feed.flowRate")
  • Nested: "UnitName.subObject.propertyName" (e.g., "Separator.gasOutStream.flowRate")
  • Indexed: "UnitName.propertyName[index]" (e.g., "Feed.composition[0]")
Version:
1.0
Author:
NeqSim Development Team
  • Field Details

    • process

      private ProcessSystem process
      The process system to access.
    • DEFAULT_UNITS

      private static final Map<String,String> DEFAULT_UNITS
      Default units for common properties that require unit parameters.
  • Constructor Details

    • ProcessVariableAccessor

      public ProcessVariableAccessor(ProcessSystem process)
      Constructor.
      Parameters:
      process - the process system to access
  • Method Details

    • getValue

      public double getValue(String path)
      Get a variable value by path.
      Parameters:
      path - variable path (e.g., "Feed.flowRate", "Separator.gasOutStream.temperature")
      Returns:
      variable value
    • extractNumericValue

      private double extractNumericValue(Object result, int arrayIndex, String path)
      Extract numeric value from method result.
      Parameters:
      result - the result object from method invocation
      arrayIndex - the array index if result is an array, -1 otherwise
      path - the variable path for error messages
      Returns:
      the extracted numeric value
    • getDefaultUnit

      private String getDefaultUnit(String propertyName)
      Get default unit for a property name.
      Parameters:
      propertyName - the property name to look up
      Returns:
      the default unit string, or empty string if unknown
    • findMethodNoParams

      private Method findMethodNoParams(Class<?> clazz, String name)
      Find a method with no parameters.
      Parameters:
      clazz - the class to search for the method
      name - the method name to find
      Returns:
      the Method object if found, null otherwise
    • getValue

      public double getValue(String path, String unit)
      Get a variable value with unit conversion.
      Parameters:
      path - variable path
      unit - desired unit
      Returns:
      variable value in specified unit
    • setValue

      public void setValue(String path, double value)
      Set a variable value by path.
      Parameters:
      path - variable path
      value - value to set
    • setValue

      public void setValue(String path, double value, String unit)
      Set a variable value with unit specification.
      Parameters:
      path - variable path
      value - value to set
      unit - unit of the value
    • isValidPath

      public boolean isValidPath(String path)
      Check if a variable path is valid.
      Parameters:
      path - variable path
      Returns:
      true if path can be resolved
    • parsePath

      private String[] parsePath(String path)
      Parse a path into components.
      Parameters:
      path - the dot-separated path string to parse
      Returns:
      array of path components
    • resolveTarget

      private Object resolveTarget(String[] parts, int depth)
      Resolve the target object for a path.
      Parameters:
      parts - array of path components
      depth - number of path components to navigate (excluding the property)
      Returns:
      the resolved target object
    • findMethod

      private Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
      Find a method by name and parameter types.
      Parameters:
      clazz - the class to search for the method
      name - the method name to find
      paramTypes - the parameter types of the method
      Returns:
      the Method object if found, null otherwise
    • matchesParams

      private boolean matchesParams(Method method, Class<?>[] paramTypes)
      Check if method parameters match.
    • isBoxedEquivalent

      private boolean isBoxedEquivalent(Class<?> a, Class<?> b)
      Check if types are boxed equivalents.
      Parameters:
      a - first class type to compare
      b - second class type to compare
      Returns:
      true if a and b are boxed/unboxed equivalents (e.g., int and Integer)
    • capitalize

      private String capitalize(String s)
      Capitalize first letter.
      Parameters:
      s - the string to capitalize
      Returns:
      the string with first letter capitalized, or original if null/empty