Class ValueWithUnit

java.lang.Object
neqsim.mcp.model.ValueWithUnit

public class ValueWithUnit extends Object
A numeric value with its associated unit.

Used in MCP request/response models to represent physical quantities that can be specified with different units. Supports JSON deserialization from either a bare number (uses default unit) or an object with value and unit fields.

// Bare number — default unit assumed
25.0

// Object with unit
{"value": 25.0, "unit": "C"}
Version:
1.0
Author:
Even Solbraa
  • Field Details

    • value

      private final double value
    • unit

      private final String unit
  • Constructor Details

    • ValueWithUnit

      public ValueWithUnit(double value, String unit)
      Creates a value with unit.
      Parameters:
      value - the numeric value
      unit - the unit string
  • Method Details

    • getValue

      public double getValue()
      Gets the numeric value.
      Returns:
      the value
    • getUnit

      public String getUnit()
      Gets the unit string.
      Returns:
      the unit
    • fromJson

      public static ValueWithUnit fromJson(com.google.gson.JsonElement element, String defaultUnit)
      Parses a ValueWithUnit from a JSON element. Accepts either a bare number (using defaultUnit) or an object with "value" and optional "unit" fields.
      Parameters:
      element - the JSON element to parse
      defaultUnit - the unit to use if not specified
      Returns:
      the parsed ValueWithUnit, or null if parsing fails
    • toJson

      public com.google.gson.JsonElement toJson()
      Converts this value to a JSON element. Returns a JsonObject with "value" and "unit" fields.
      Returns:
      the JSON representation
    • toString

      public String toString()
      Overrides:
      toString in class Object