Package com.irurueta.units
Class VolumeFormatter
- All Implemented Interfaces:
Cloneable
Formats and parses volume value and unit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBarrel symbol.static final StringCubic centimeter symbol.static final StringCubic decimeter symbol.static final StringCubic foot symbol.static final StringCubic inch symbol.static final StringCubic meter symbol.static final StringGallon symbol.static final StringHectoliter symbol.static final StringLiter symbol.static final StringMilliliter symbol.static final StringPint symbol.Fields inherited from class com.irurueta.units.MeasureFormatter
DEFAULT_VALUE_AND_UNIT_FORMAT_PATTERN, numberFormat -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.VolumeFormatter(VolumeFormatter formatter) Copy constructor.VolumeFormatter(Locale locale) Constructor with locale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if two volume formatters are equal by comparing all of their internal parameters.Attempts to determine a volume unit within a measurement string representation.formatAndConvert(Number value, VolumeUnit unit, UnitSystem system) Formats and converts provided volume value and unit using provided unit system.formatAndConvertImperial(Number value, VolumeUnit unit) Formats and converts provided volume value and unit using imperial unit system.formatAndConvertMetric(Number value, VolumeUnit unit) Formats and converts provided volume value and unit using metric unit system.getUnitSymbol(VolumeUnit unit) Returns unit string representation.getUnitSystem(String source) Gets unit system for detected unit into provided string representation of a measurement.inthashCode()Hash code generated for this instance.Parses provided string and tries to determine a volume value and unit.Methods inherited from class com.irurueta.units.MeasureFormatter
clone, format, format, format, format, format, format, formatAndConvert, formatAndConvert, formatAndConvert, formatAndConvert, formatAndConvert, getAvailableLocales, getLocale, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getRoundingMode, getUnitSystem, getValueAndUnitFormatPattern, internalClone, internalParse, isGroupingUsed, isImperialUnit, isMetricUnit, isParseIntegerOnly, isValidMeasurement, isValidUnit, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly, setRoundingMode, setValueAndUnitFormatPattern
-
Field Details
-
CUBIC_CENTIMETER
Cubic centimeter symbol.- See Also:
-
MILLILITER
Milliliter symbol.- See Also:
-
CUBIC_DECIMETER
Cubic decimeter symbol.- See Also:
-
LITER
Liter symbol.- See Also:
-
HECTOLITER
Hectoliter symbol.- See Also:
-
CUBIC_METER
Cubic meter symbol.- See Also:
-
CUBIC_INCH
Cubic inch symbol.- See Also:
-
PINT
Pint symbol.- See Also:
-
GALLON
Gallon symbol.- See Also:
-
CUBIC_FOOT
Cubic foot symbol.- See Also:
-
BARREL
Barrel symbol.- See Also:
-
-
Constructor Details
-
VolumeFormatter
public VolumeFormatter()Constructor. -
VolumeFormatter
Constructor with locale.- Parameters:
locale- locale.- Throws:
IllegalArgumentException- if locale is null.
-
VolumeFormatter
Copy constructor.- Parameters:
formatter- input instance to copy from.- Throws:
NullPointerException- if provided formatter is null.
-
-
Method Details
-
equals
Determines if two volume formatters are equal by comparing all of their internal parameters.- Overrides:
equalsin classMeasureFormatter<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:
hashCodein classMeasureFormatter<Volume,VolumeUnit> - Returns:
- hash code.
-
getUnitSystem
Gets unit system for detected unit into provided string representation of a measurement.- Specified by:
getUnitSystemin classMeasureFormatter<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
Parses provided string and tries to determine a volume value and unit.- Specified by:
parsein classMeasureFormatter<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
Attempts to determine a volume unit within a measurement string representation.- Specified by:
findUnitin classMeasureFormatter<Volume,VolumeUnit> - Parameters:
source- a volume measurement string representation.- Returns:
- a volume unit, or null if none can be determined.
-
formatAndConvert
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:
formatAndConvertin classMeasureFormatter<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
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
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
Returns unit string representation.- Specified by:
getUnitSymbolin classMeasureFormatter<Volume,VolumeUnit> - Parameters:
unit- a volume unit.- Returns:
- its string representation.
-