Class ValueWithUnit
java.lang.Object
neqsim.mcp.model.ValueWithUnit
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ValueWithUnitParses a ValueWithUnit from a JSON element.getUnit()Gets the unit string.doublegetValue()Gets the numeric value.com.google.gson.JsonElementtoJson()Converts this value to a JSON element.toString()
-
Field Details
-
value
private final double value -
unit
-
-
Constructor Details
-
ValueWithUnit
Creates a value with unit.- Parameters:
value- the numeric valueunit- the unit string
-
-
Method Details
-
getValue
public double getValue()Gets the numeric value.- Returns:
- the value
-
getUnit
-
fromJson
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 parsedefaultUnit- 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
-