Class LabelUnit

  • All Implemented Interfaces:
    java.lang.Comparable<LabelUnit>

    public class LabelUnit
    extends java.lang.Object
    implements java.lang.Comparable<LabelUnit>
    Utility class for working with units for labelling extents. It is not currently intended for use with absolute values.
    Since:
    23 Jan 2018
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      LabelUnit​(java.lang.String name, double factor)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(LabelUnit other)  
      static java.lang.String formatValue​(double value, double eps, LabelUnit[] units)
      Formats a given number giving its value in a sensible precision using a suitable unit.
      double getFactor()
      Returns the size of this unit in terms of some standard unit.
      java.lang.String getName()
      Returns this unit's name as used for annotating values.
      static LabelUnit getUnit​(double value, LabelUnit[] units)
      Returns an appropriate unit for annotating the given value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LabelUnit

        public LabelUnit​(java.lang.String name,
                         double factor)
        Constructor.
        Parameters:
        name - human-readable unit name for annotating values
        factor - size of this unit in terms of some standard unit
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns this unit's name as used for annotating values.
        Returns:
        name
      • getFactor

        public double getFactor()
        Returns the size of this unit in terms of some standard unit.
        Returns:
        factor
      • compareTo

        public int compareTo​(LabelUnit other)
        Specified by:
        compareTo in interface java.lang.Comparable<LabelUnit>
      • getUnit

        public static LabelUnit getUnit​(double value,
                                        LabelUnit[] units)
        Returns an appropriate unit for annotating the given value.
        Parameters:
        value - value in standard units
        units - list of available units
        Returns:
        most suitable entry from supplied units list
      • formatValue

        public static java.lang.String formatValue​(double value,
                                                   double eps,
                                                   LabelUnit[] units)
        Formats a given number giving its value in a sensible precision using a suitable unit.
        Parameters:
        value - numeric value in standard units
        eps - approximate precision of value in standard units
        units - list of available units
        Returns:
        string giving numeric value, with unit name appended