Class Unit

java.lang.Object
hec.heclib.util.Unit
All Implemented Interfaces:
Serializable

public class Unit extends Object implements Serializable
Holds Unit Definitions, Conversion Factors, and Conversion Functions. Resource file loaded from file system or classpath via static initializer.
See Also:
  • Field Details

  • Constructor Details

    • Unit

      public Unit()
  • Method Details

    • getUnitSystems

      public static String[] getUnitSystems()
      Returns known unit system strings ordered alphabetically
    • getUnitsAliasTable

      public static Hashtable<String,String> getUnitsAliasTable()
      Returns a mapping of aliases to units
    • getUnitTypes

      public static String[] getUnitTypes()
      Returns all unique unit strings for known systems
    • getUnitsForSystem

      public static String[] getUnitsForSystem(String forSys)
      Returns the all units for the specific system
    • getUnitsToConvertTo

      public static String[] getUnitsToConvertTo(String fromSys, String fromUnit)
      Returns the units that can be converted to from the arg unit and system
    • getConvFunction

      public static RpnFunction getConvFunction(String fromSys, String fromId, String toSys, String toId)
      Returns an RpnFunction for use in converting units.
    • load

      public static void load()
      Loads this class from the resource file.
    • loadFromUrl

      public static boolean loadFromUrl(String filepath)
      Loads this class from a resource file specified via the arg URL
    • loadFromFile

      public static boolean loadFromFile(String filepath)
      Loads this class from the resource file specified via the filpath arg
    • loadFromReader

      public static boolean loadFromReader(BufferedReader br)
      Loads this class from the resource file loaded into the arg reader
    • addUnit

      public static void addUnit(String unitSys, String unitId)
      Adds a unit type without any conversions
    • doesUnitExist

      public static boolean doesUnitExist(String unitSys, String unitId)
      Returns true if a unit definition exists for the arg string and system
    • addConvFunction

      public static void addConvFunction(String fromSys, String fromId, String toSys, String toId, String strFunction)
      Creates and adds a RPN conversion function to convert from sys/unit to sys/unit
    • addConvFunction

      public static void addConvFunction(String fromSys, String fromId, String toSys, String toId, RpnFunction function)
      Adds the RPN conversion function to convert from sys/unit to sys/unit
    • addConvFunction

      public static void addConvFunction(String fromSys, String fromId, String toSys, String toId, double factor)
      Adds a scalar conversion factors to convert both ways between specified system/unit combinations
      Parameters:
      fromSys - The feature to be added to the ConvFunction attribute
      fromId - The feature to be added to the ConvFunction attribute
      toSys - The feature to be added to the ConvFunction attribute
      toId - The feature to be added to the ConvFunction attribute
      factor - The feature to be added to the ConvFunction attribute