Class UnitSystem

java.lang.Object
com.tccc.kos.commons.util.units.UnitSystem
Direct Known Subclasses:
SiUnitSystem, UsUnitSystem

public abstract class UnitSystem extends Object
This class contains a full description of a "unit system". A unit system contains multiple Unit definitions, which provide a way to convert to/from the base data within kOS, which is typically stored as SI units. Unit systems are also shared with UI code for standardized type conversion as part of the kOS UI framework. While kOS provides default base unit systems, applications can add units to existing systems, replace existing systems, or add new systems, as needed.
Since:
1.0
Version:
2023-02-28
  • Constructor Details

    • UnitSystem

      public UnitSystem(String id)
      Creates a new unit system with the specified identifier.
      Parameters:
      id - ID of the unit system
  • Method Details

    • add

      public void add(Unit unit)
      Adds a new unit to the system. If the measure and unit name match an existing unit, the new unit replaces the existing unit.
      Parameters:
      unit - the unit to add
    • getDefaultUnit

      public Unit getDefaultUnit(String measure)
      Returns the default unit for the specified measure.
      Parameters:
      measure - the measure to match
      Throws:
      IllegalArgumentException - if no default unit exists for the measure
    • getAliasUnit

      public Unit getAliasUnit(String measure, String alias)
      Returns the unit with the specified alias for the specified measure. If the alias isn't found, the default unit is returned.
      Parameters:
      measure - the measure to match (null for any)
      alias - the alias to match
    • getUnit

      public Unit getUnit(String measure, String nameOrAlias)
      Returns the unit with the specified name or alias. If no unit is found, returns null.
      Parameters:
      measure - the measure to match (null for any)
      nameOrAlias - the name / alias to match
    • getId

      public String getId()
    • getUnits

      public Set<Unit> getUnits()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object