Package gda.util

Class QuantityFactory

java.lang.Object
gda.util.QuantityFactory

public class QuantityFactory extends Object
A factory class to create Quantities from Strings. Uses a combination of BFI and Trickery.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    createFromObject(Object value, String unitString)
    Similar to createFromObject(Object, Unit), but the unit is specified as a String
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    createFromObject(Object position, javax.measure.Unit<Q> unit)
    Takes an object and converts it into a quantity of the requested unit.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    Creates a Quantity from a single string specifying value and units.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    createFromTwoStrings(String valueString, String unitString)
    Creates a Quantity from two strings.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Unit<Q>
    Creates a Unit from a string by searching through the subclasses of quantity to find a predefined field.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createFromObject

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> createFromObject(Object position, javax.measure.Unit<Q> unit)
      Takes an object and converts it into a quantity of the requested unit.

      This can take a variety of objects, including Jython native types.

      Parameters:
      position -
      unit -
      Returns:
      the Quantity created (or null)
    • createFromObject

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> createFromObject(Object value, String unitString)
      Similar to createFromObject(Object, Unit), but the unit is specified as a String
      Parameters:
      value -
      unitString -
      Returns:
      the Quantity created (or null)
    • createFromString

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> createFromString(String string)
      Creates a Quantity from a single string specifying value and units. This should be useful, for example, in creating Quantities from scripts.
      Parameters:
      string - of the form '1.0 mm'
      Returns:
      the Quantity created (or null)
    • createFromTwoStrings

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> createFromTwoStrings(String valueString, String unitString)
      Creates a Quantity from two strings. This should be useful, for example, in creating Quantities from GUIs.
      Parameters:
      valueString - the numerical value e.g '1.0'
      unitString - the units - e.g. 'mm'
      Returns:
      the Quantity created (or null)
    • createUnitFromString

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Unit<Q> createUnitFromString(String string)
      Creates a Unit from a string by searching through the subclasses of quantity to find a predefined field. For example given 'mm' it will return the public static Length.Unit MM from the Length class. A blank unit string will return a dimensionless unit.
      Parameters:
      string - the name of a unit.
      Returns:
      the corresponding Unit, or null if not found