Class SystemOfMeasurement


  • public class SystemOfMeasurement
    extends java.lang.Object
    A system of units used to express length and area measurements.

    This class also manages one globally set system of measurement stored in the ProjectionPreference

    Since:
    3406 (creation), 6992 (extraction in this package)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  SystemOfMeasurement.SoMChangeListener
      Interface to notify listeners of the change of the system of measurement.
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemOfMeasurement​(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue)
      System of measurement.
      SystemOfMeasurement​(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue, double areaCustomValue, java.lang.String areaCustomName)
      System of measurement.
    • Field Detail

      • IMPERIAL

        public static final SystemOfMeasurement IMPERIAL
        Imperial system (British Commonwealth and former British Empire).
        Since:
        3406
      • name

        private final java.lang.String name
        Translatable name of this system of measurement.
      • aValue

        public final double aValue
        First value, in meters, used to translate unit according to above formula.
      • bValue

        public final double bValue
        Second value, in meters, used to translate unit according to above formula.
      • aName

        public final java.lang.String aName
        First unit used to format text.
      • bName

        public final java.lang.String bName
        Second unit used to format text.
      • speedValue

        public final double speedValue
        Speed value for the most common speed symbol, in meters per second
        Since:
        10175
      • speedName

        public final java.lang.String speedName
        Most common speed symbol (kmh/h, mph, kn, etc.)
        Since:
        10175
      • areaCustomValue

        public final double areaCustomValue
        Specific optional area value, in squared meters, between aValue*aValue and bValue*bValue. Set to -1 if not used.
        Since:
        5870
      • areaCustomName

        public final java.lang.String areaCustomName
        Specific optional area unit. Set to null if not used.
        Since:
        5870
    • Constructor Detail

      • SystemOfMeasurement

        public SystemOfMeasurement​(java.lang.String name,
                                   double aValue,
                                   java.lang.String aName,
                                   double bValue,
                                   java.lang.String bName,
                                   java.lang.String speedName,
                                   double speedValue)
        System of measurement. Currently covers only length (and area) units. If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as x_a == x_m / aValue
        Parameters:
        name - Translatable name of this system of measurement
        aValue - First value, in meters, used to translate unit according to above formula.
        aName - First unit used to format text.
        bValue - Second value, in meters, used to translate unit according to above formula.
        bName - Second unit used to format text.
        speedName - the most common speed symbol (kmh/h, mph, kn, etc.)
        speedValue - the speed value for the most common speed symbol, for 1 meter per second
        Since:
        15395
      • SystemOfMeasurement

        public SystemOfMeasurement​(java.lang.String name,
                                   double aValue,
                                   java.lang.String aName,
                                   double bValue,
                                   java.lang.String bName,
                                   java.lang.String speedName,
                                   double speedValue,
                                   double areaCustomValue,
                                   java.lang.String areaCustomName)
        System of measurement. Currently covers only length (and area) units. If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as x_a == x_m / aValue
        Parameters:
        name - Translatable name of this system of measurement
        aValue - First value, in meters, used to translate unit according to above formula.
        aName - First unit used to format text.
        bValue - Second value, in meters, used to translate unit according to above formula.
        bName - Second unit used to format text.
        speedName - the most common speed symbol (kmh/h, mph, kn, etc.)
        speedValue - the speed value for the most common speed symbol, for 1 meter per second
        areaCustomValue - Specific optional area value, in squared meters, between aValue*aValue and bValue*bValue. Set to -1 if not used.
        areaCustomName - Specific optional area unit. Set to null if not used.
        Since:
        15395
    • Method Detail

      • fireSoMChanged

        protected static void fireSoMChanged​(java.lang.String oldSoM,
                                             java.lang.String newSoM)
      • getSystemOfMeasurement

        public static SystemOfMeasurement getSystemOfMeasurement()
        Returns the current global system of measurement.
        Returns:
        The current system of measurement (metric system by default).
        Since:
        8554
      • setSystemOfMeasurement

        public static void setSystemOfMeasurement​(SystemOfMeasurement som)
        Sets the current global system of measurement.
        Parameters:
        som - The system of measurement to set. Must be defined in ALL_SYSTEMS.
        Throws:
        java.lang.IllegalArgumentException - if som is not known
        Since:
        16985 (signature)
      • getDistText

        public java.lang.String getDistText​(double dist)
        Returns the text describing the given distance in this system of measurement.
        Parameters:
        dist - The distance in metres
        Returns:
        The text describing the given distance in this system of measurement.
      • getDistText

        public java.lang.String getDistText​(double dist,
                                            java.text.NumberFormat format,
                                            double threshold)
        Returns the text describing the given distance in this system of measurement.
        Parameters:
        dist - The distance in metres
        format - A NumberFormat to format the area value
        threshold - Values lower than this threshold are displayed as "< [threshold]"
        Returns:
        The text describing the given distance in this system of measurement.
        Since:
        6422
      • getAreaText

        public java.lang.String getAreaText​(double area)
        Returns the text describing the given area in this system of measurement.
        Parameters:
        area - The area in square metres
        Returns:
        The text describing the given area in this system of measurement.
        Since:
        5560
      • getAreaText

        public java.lang.String getAreaText​(double area,
                                            java.text.NumberFormat format,
                                            double threshold)
        Returns the text describing the given area in this system of measurement.
        Parameters:
        area - The area in square metres
        format - A NumberFormat to format the area value
        threshold - Values lower than this threshold are displayed as "< [threshold]"
        Returns:
        The text describing the given area in this system of measurement.
        Since:
        6422
      • getName

        public java.lang.String getName()
        Returns the translatable name of this system of measurement.
        Returns:
        the translatable name of this system of measurement
        Since:
        15395
      • toString

        public java.lang.String toString()
        Returns the localized name of this system of measurement
        Overrides:
        toString in class java.lang.Object
        Returns:
        the localized name
      • getDefault

        public static SystemOfMeasurement getDefault()
        Returns the default system of measurement for the current country.
        Returns:
        the default system of measurement for the current country
        Since:
        15395
      • formatText

        private static java.lang.String formatText​(double v,
                                                   java.lang.String unit,
                                                   java.text.NumberFormat format)