Class VolumeFormatter

All Implemented Interfaces:
Cloneable

public class VolumeFormatter extends MeasureFormatter<Volume,VolumeUnit>
Formats and parses volume value and unit.
  • Field Details

  • Constructor Details

    • VolumeFormatter

      public VolumeFormatter()
      Constructor.
    • VolumeFormatter

      public VolumeFormatter(Locale locale)
      Constructor with locale.
      Parameters:
      locale - locale.
      Throws:
      IllegalArgumentException - if locale is null.
    • VolumeFormatter

      public VolumeFormatter(VolumeFormatter formatter)
      Copy constructor.
      Parameters:
      formatter - input instance to copy from.
      Throws:
      NullPointerException - if provided formatter is null.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Determines if two volume formatters are equal by comparing all of their internal parameters.
      Overrides:
      equals in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      obj - another object to compare.
      Returns:
      true if provided object is assumed to be equal to this instance.
    • hashCode

      public int hashCode()
      Hash code generated for this instance. Hash codes can be internally used by some collections to coarsely compare objects. This implementation only calls parent implementation to avoid static analyzer warning.
      Overrides:
      hashCode in class MeasureFormatter<Volume,VolumeUnit>
      Returns:
      hash code.
    • getUnitSystem

      public UnitSystem getUnitSystem(String source)
      Gets unit system for detected unit into provided string representation of a measurement.
      Specified by:
      getUnitSystem in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      source - a measurement string representation to be checked.
      Returns:
      a unit system (either metric or imperial) or null if unit cannot be determined.
    • parse

      public Volume parse(String source) throws ParseException, UnknownUnitException
      Parses provided string and tries to determine a volume value and unit.
      Specified by:
      parse in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      source - a string to be parsed.
      Returns:
      a volume containing a value and unit.
      Throws:
      ParseException - if provided string cannot be parsed.
      UnknownUnitException - if unit cannot be determined.
    • findUnit

      public VolumeUnit findUnit(String source)
      Attempts to determine a volume unit within a measurement string representation.
      Specified by:
      findUnit in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      source - a volume measurement string representation.
      Returns:
      a volume unit, or null if none can be determined.
    • formatAndConvert

      public String formatAndConvert(Number value, VolumeUnit unit, UnitSystem system)
      Formats and converts provided volume value and unit using provided unit system. If provided value is too large for provided unit, this method will convert it to a more appropriate unit using provided unit system (either metric or imperial).
      Specified by:
      formatAndConvert in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      value - a volume value.
      unit - a volume unit.
      system - system unit to convert measurement to.
      Returns:
      a string representation of volume value and unit.
    • formatAndConvertMetric

      public String formatAndConvertMetric(Number value, VolumeUnit unit)
      Formats and converts provided volume value and unit using metric unit system. If provided volume value is too large for provided volume unit, this method will convert to a more appropriate unit.
      Parameters:
      value - a volume value.
      unit - a volume unit.
      Returns:
      a string representation of volume value and unit using metric unit system.
    • formatAndConvertImperial

      public String formatAndConvertImperial(Number value, VolumeUnit unit)
      Formats and converts provided volume value and unit using imperial unit system. If provided volume value is too large for provided volume unit, this method will convert to a more appropriate unit.
      Parameters:
      value - a volume value.
      unit - a volume unit.
      Returns:
      a string representation of volume value and unit using imperial unit system.
    • getUnitSymbol

      public String getUnitSymbol(VolumeUnit unit)
      Returns unit string representation.
      Specified by:
      getUnitSymbol in class MeasureFormatter<Volume,VolumeUnit>
      Parameters:
      unit - a volume unit.
      Returns:
      its string representation.