Class LinearUnit

    • Constructor Detail

      • LinearUnit

        public LinearUnit​(LinearUnitId unitId)
        Creates a new linear unit from a LinearUnitId value. Use this constructor to create an instance of LinearUnit representing any of the most commonly used linear units defined in the LinearUnitId enumeration.

        To use less common linear units not available in the enumeration, call the Unit.fromUnitId(int) factory method passing in a well-known ID of a linear unit.

        Parameters:
        unitId - the id of the linear unit to create
        Since:
        100.0.0
        See Also:
        Unit.fromUnitId(int)
      • LinearUnit

        public LinearUnit​(AreaUnit areaUnit)
        Creates a new linear unit based on the given AreaUnit. Use this method to find the units of linear measurement that correspond to a unit of area measurement. For example, passing in a AreaUnit of type LinearUnitId.METERS will create an LinearUnit of type AreaUnitId.SQUARE_METERS.
        Parameters:
        areaUnit - the area unit for which to create a new linear unit instance
        Since:
        100.0.0
    • Method Detail

      • getLinearUnitId

        public LinearUnitId getLinearUnitId()
        Gets the LinearIUnitId value for the type of linear units represented by this instance.
        Returns:
        the linear unit id
        Since:
        100.0.0
      • convertFrom

        public double convertFrom​(LinearUnit fromUnit,
                                  double value)
        Converts a value from the given units to the units of this instance.
        Parameters:
        fromUnit - the units to convert from
        value - the value to convert, in fromUnit units
        Returns:
        the value converted to the units represented by this instance
        Throws:
        IllegalArgumentException - if the fromUnit is null
        Since:
        100.0.0
        See Also:
        fromMeters(double)
      • convertTo

        public double convertTo​(LinearUnit toUnit,
                                double value)
        Converts a value from the units of this instance to the given units.
        Parameters:
        toUnit - he units to convert the value to
        value - the value to convert, in the units represented by this instance
        Returns:
        the value converted to the toUnit units
        Throws:
        IllegalArgumentException - if the toUnit is null
        Since:
        100.0.0
      • fromMeters

        public double fromMeters​(double value)
        Converts a value from meters to the units of this instance. This is a convenience method for the common task of conversion of linear measurements from meters. Use the convertFrom(LinearUnit, double) method to convert values from other linear units.
        Parameters:
        value - the value to convert, in meters
        Returns:
        the value converted to the units represented by this instance
        Since:
        100.0.0
      • toMeters

        public double toMeters​(double value)
        Converts a value from the units of this instance to meters. This is a convenience method for the common task of conversion of linear measurements to meters. Use the convertTo(LinearUnit, double) method to convert values to other linear units.
        Parameters:
        value - the value to convert, in the units represented by this instance
        Returns:
        the value converted to meters
        Since:
        100.0.0