Class UnitsConverter


  • public class UnitsConverter
    extends java.lang.Object
    • Field Detail

      • conversionRate

        private java.math.BigDecimal conversionRate
      • reciprocal

        private boolean reciprocal
      • offset

        private java.math.BigDecimal offset
      • specialSource

        private java.lang.String specialSource
      • specialTarget

        private java.lang.String specialTarget
      • minMetersPerSecForBeaufort

        private static final java.math.BigDecimal[] minMetersPerSecForBeaufort
    • Constructor Detail

      • UnitsConverter

        public UnitsConverter​(java.lang.String sourceIdentifier,
                              java.lang.String targetIdentifier)
        Constructor of UnitsConverter. NOTE: - source and target must be under the same category - e.g. meter to mile --> both of them are length units.

        NOTE: This constructor creates an instance of UnitsConverter internally.

        Parameters:
        sourceIdentifier - represents the source unit identifier.
        targetIdentifier - represents the target unit identifier.
      • UnitsConverter

        public UnitsConverter​(MeasureUnitImpl source,
                              MeasureUnitImpl target,
                              ConversionRates conversionRates)
        Constructor of UnitsConverter. NOTE: - source and target must be under the same category - e.g. meter to mile --> both of them are length units. This converts from source to base to target (one of those may be a no-op).
        Parameters:
        source - represents the source unit.
        target - represents the target unit.
        conversionRates - contains all the needed conversion rates.
    • Method Detail

      • insertInMap

        private static void insertInMap​(java.util.HashMap<java.lang.String,​java.lang.Integer> dimensionMap,
                                        java.util.ArrayList<SingleUnitImpl> singleUnits,
                                        int multiplier)
        Helpers
      • areDimensionsZeroes

        private static boolean areDimensionsZeroes​(java.util.HashMap<java.lang.String,​java.lang.Integer> dimensionMap)
      • convert

        public java.math.BigDecimal convert​(java.math.BigDecimal inputValue)
      • convertInverse

        public java.math.BigDecimal convertInverse​(java.math.BigDecimal inputValue)
      • scaleToBase

        private java.math.BigDecimal scaleToBase​(java.math.BigDecimal scaleValue,
                                                 java.math.BigDecimal[] minBaseForScaleValues)
      • baseToScale

        private java.math.BigDecimal baseToScale​(java.math.BigDecimal baseValue,
                                                 java.math.BigDecimal[] minBaseForScaleValues)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object