Package ucar.units

Class ConverterImpl

  • All Implemented Interfaces:
    Converter
    Direct Known Subclasses:
    TimeScaleUnit.MyConverter, UnitImpl.MyConverter

    public abstract class ConverterImpl
    extends Object
    implements Converter
    Provides support for implementations of unit converters. A unit converter class may be created by subclassing this class and implementing the methods convert(double), convert(float[] input, float[] output) , and convert(double[] input, double[] output) of interface Converter.
    • Constructor Detail

      • ConverterImpl

        protected ConverterImpl​(Unit fromUnit,
                                Unit toUnit)
                         throws ConversionException
        Constructs from a "from" unit and a "to" unit.
        Parameters:
        fromUnit - The unit from which to convert.
        toUnit - The unit to which to convert.
        Throws:
        ConversionException - The units are not convertible.
    • Method Detail

      • create

        public static Converter create​(Unit fromUnit,
                                       Unit toUnit)
                                throws ConversionException
        Factory method for creating a unit converter.
        Parameters:
        fromUnit - The unit from which to convert.
        toUnit - The unit to which to convert.
        Throws:
        ConversionException - The units are not convertible.
      • convert

        public final float convert​(float amount)
        Converts a numeric value.
        Specified by:
        convert in interface Converter
        Parameters:
        amount - The numeric value to convert.
        Returns:
        The converted numeric value.
      • convert

        public final float[] convert​(float[] amounts)
        Converts an array of numeric values.
        Specified by:
        convert in interface Converter
        Parameters:
        amounts - The numeric values to convert.
        Returns:
        The converted numeric values in allocated space.
      • convert

        public final double[] convert​(double[] amounts)
        Converts an array of numeric values.
        Specified by:
        convert in interface Converter
        Parameters:
        amounts - The numeric values to convert.
        Returns:
        The converted numeric values in allocated space.