Class Measure

java.lang.Object
org.apache.sis.internal.jaxb.gml.Measure

public final class Measure extends Object
A measurement value together with its unit of measure. This is used for marshalling an element defined by ISO 19103.

This class duplicates org.apache.sis.measure.Measure, but we have to do that way because that Measure extends Number and we are not allowed to use the @XmlValue annotation on a class that extends another class.

XML marshalling

Measures are used in different ways by the ISO 19115 (Metadata) and GML standards. The former expresses some measurements with an object of XML type gco:Distance (as a substitution for XML type gco:Measure): while GML will rather use a a syntax like below: Both have a value of type xs:double and a uom attribute (without namespace) of type gml:UomIdentifier. Those two information are represented by this class.
Since:
0.3
Version:
1.1
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    true if the units shall be formatted as xpointer.
    private static final UnitFormat
    An instance for formatting units with a syntax close to the UCUM one.
    javax.measure.Unit<?>
    The unit of measurement.
    double
    The value of the measure.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default empty constructor for JAXB.
    Measure(double value, javax.measure.Unit<?> unit)
    Constructs a representation of the measure as defined in ISO 19103 standard, with the UOM attribute like "gmxUom.xml#xpointer(//*[@gml:id='m'])".
  • Method Summary

    Modifier and Type
    Method
    Description
    <Q extends javax.measure.Quantity<Q>>
    javax.measure.Unit<Q>
    getUnit(Class<Q> type)
    Returns unit as a unit compatible with the given quantity.
    Constructs a string representation of the units as defined in the ISO 19103 standard.
    static String
    getUOM(javax.measure.Unit<?> unit, boolean asXPointer, boolean inAxis)
    Implementation of getUOM() as a static method for use by classes that define their own uom attribute, instead of letting the uom attribute on the measurement value.
    static void
    missingUOM(Class<?> caller, String methodName)
    Sends a warning for a missing "uom" attribute.
    boolean
    setUnit(javax.measure.Unit<?> newUnit)
    Sets the unit to the given value, and returns true if the current unit value was different.
    void
    Sets the unit of measure.

    Methods inherited from class java.lang.Object

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

    • UCUM

      private static final UnitFormat UCUM
      An instance for formatting units with a syntax close to the UCUM one. While UnitFormat is generally not thread-safe, this particular instance is safe if we never invoke any setter method.
    • value

      public double value
      The value of the measure.
    • unit

      public javax.measure.Unit<?> unit
      The unit of measurement.
    • asXPointer

      public boolean asXPointer
      true if the units shall be formatted as xpointer. If false (the default), then this class will try to format the units using the GML syntax.
  • Constructor Details

    • Measure

      public Measure()
      Default empty constructor for JAXB. The value is initialized to NaN, but JAXB will overwrite that value if a XML value is present.
    • Measure

      public Measure(double value, javax.measure.Unit<?> unit)
      Constructs a representation of the measure as defined in ISO 19103 standard, with the UOM attribute like "gmxUom.xml#xpointer(//*[@gml:id='m'])".
      Parameters:
      value - the value of the measure.
      unit - the unit of measurement.
  • Method Details

    • getUOM

      public String getUOM()
      Constructs a string representation of the units as defined in the ISO 19103 standard. This method is invoked during XML marshalling. For example if the units are "metre", then this method returns one of the following strings, in preference order: or one of the following:
      Returns:
      the string representation of the unit of measure.
    • getUOM

      public static String getUOM(javax.measure.Unit<?> unit, boolean asXPointer, boolean inAxis)
      Implementation of getUOM() as a static method for use by classes that define their own uom attribute, instead of letting the uom attribute on the measurement value. The main example is DefaultCoordinateSystemAxis.
      Parameters:
      unit - the unit to format.
      asXPointer - true if the units shall be formatted as xpointer.
      inAxis - true for a unit used in Coordinate System Axis definition.
      Returns:
      the string representation of the unit of measure.
    • setUOM

      public void setUOM(String uom) throws URISyntaxException
      Sets the unit of measure. This method is invoked by JAXB at unmarshalling time.
      Parameters:
      uom - the unit of measure as a string.
      Throws:
      URISyntaxException - if the uom looks like a URI, but cannot be parsed.
    • getUnit

      public <Q extends javax.measure.Quantity<Q>> javax.measure.Unit<Q> getUnit(Class<Q> type)
      Returns unit as a unit compatible with the given quantity.
      Type Parameters:
      Q - compile-time type of the type argument.
      Parameters:
      type - the quantity for the desired unit.
      Returns:
      a unit compatible with the given type, or null if none.
    • setUnit

      public boolean setUnit(javax.measure.Unit<?> newUnit)
      Sets the unit to the given value, and returns true if the current unit value was different. A return value of true means that the caller should log a warning.
      Example: Some users wrongly assign the "m" unit to Ellipsoid.inverseFlattening. The SIS adapter forces the unit to Units.UNITY, but we want to let the user know that he probably did something wrong.
      Parameters:
      newUnit - the new unit (cannot be null).
      Returns:
      true if a different unit was defined before this method call.
    • missingUOM

      public static void missingUOM(Class<?> caller, String methodName)
      Sends a warning for a missing "uom" attribute.
      Parameters:
      caller - the class of the method invoking this method.
      methodName - the name of the method invoking this method.