Package com.irurueta.units
Class TemperatureFormatter
java.lang.Object
com.irurueta.units.MeasureFormatter<Temperature,TemperatureUnit>
com.irurueta.units.TemperatureFormatter
- All Implemented Interfaces:
Cloneable
Formats and parses temperature value and unit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCelsius symbol.static final StringFahrenheit symbol.static final StringKelvin symbol.Fields inherited from class com.irurueta.units.MeasureFormatter
DEFAULT_VALUE_AND_UNIT_FORMAT_PATTERN, numberFormat -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.TemperatureFormatter(TemperatureFormatter formatter) Copy constructor.TemperatureFormatter(Locale locale) Constructor with locale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if two temperature formatters are equal by comparing all of their internal parameters.Attempts to determine a temperature unit within a measurement string representation.formatAndConvert(Number value, TemperatureUnit unit, UnitSystem system) Formats and converts provided temperature value and unit using provided unit system.getUnitSymbol(TemperatureUnit 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 temperature 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
-
CELSIUS
Celsius symbol.- See Also:
-
FAHRENHEIT
Fahrenheit symbol.- See Also:
-
KELVIN
Kelvin symbol.- See Also:
-
-
Constructor Details
-
TemperatureFormatter
public TemperatureFormatter()Constructor. -
TemperatureFormatter
Constructor with locale.- Parameters:
locale- locale.- Throws:
IllegalArgumentException- if locale is null.
-
TemperatureFormatter
Copy constructor.- Parameters:
formatter- input instance to copy from.- Throws:
NullPointerException- if provided formatter is null.
-
-
Method Details
-
equals
Determines if two temperature formatters are equal by comparing all of their internal parameters.- Overrides:
equalsin classMeasureFormatter<Temperature,TemperatureUnit> - 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<Temperature,TemperatureUnit> - Returns:
- hash code.
-
getUnitSystem
Gets unit system for detected unit into provided string representation of a measurement.- Specified by:
getUnitSystemin classMeasureFormatter<Temperature,TemperatureUnit> - 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 temperature value and unit.- Specified by:
parsein classMeasureFormatter<Temperature,TemperatureUnit> - Parameters:
source- a string to be parsed.- Returns:
- a temperature containing a value and unit.
- Throws:
ParseException- if provided string cannot be parsed.UnknownUnitException- if unit cannot be determined.
-
findUnit
Attempts to determine a temperature unit within a measurement string representation.- Specified by:
findUnitin classMeasureFormatter<Temperature,TemperatureUnit> - Parameters:
source- a measurement string representation.- Returns:
- a temperature unit, or null if none can be determined.
-
formatAndConvert
Formats and converts provided temperature 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).This implementation just formats provided value using provided unit, ignoring provided unit system.
- Specified by:
formatAndConvertin classMeasureFormatter<Temperature,TemperatureUnit> - Parameters:
value- a temperature value.unit- a temperature unit.system- system unit to convert temperature to.- Returns:
- a string representation of temperature value and unit.
-
getUnitSymbol
Returns unit string representation.- Specified by:
getUnitSymbolin classMeasureFormatter<Temperature,TemperatureUnit> - Parameters:
unit- a temperature unit.- Returns:
- its string representation.
-