Package com.irurueta.units
Class SpeedFormatter
- All Implemented Interfaces:
Cloneable
Formats and parses speed value and unit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFeet per second symbol.static final StringKilometers per hour symbol.static final StringKilometers per second symbol.static final StringMeters per second symbol.static final StringMiles per hour symbol.Fields inherited from class com.irurueta.units.MeasureFormatter
DEFAULT_VALUE_AND_UNIT_FORMAT_PATTERN, numberFormat -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.SpeedFormatter(SpeedFormatter formatter) Copy constructor.SpeedFormatter(Locale locale) Constructor with locale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if two speed formatters are equal by comparing all of their internal parameters.Attempts to determine a speed unit within a measurement string representation.formatAndConvert(Number value, SpeedUnit unit, UnitSystem system) Formats and converts provided speed value and unit using provided unit system.formatAndConvertImperial(Number value, SpeedUnit unit) Formats and converts provided speed value and unit using imperial unit system.formatAndConvertMetric(Number value, SpeedUnit unit) Formats and converts provided speed value and unit using metric unit system.getUnitSymbol(SpeedUnit 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 speed 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
-
METERS_PER_SECOND
Meters per second symbol.- See Also:
-
KILOMETERS_PER_HOUR
Kilometers per hour symbol.- See Also:
-
KILOMETERS_PER_SECOND
Kilometers per second symbol.- See Also:
-
FEET_PER_SECOND
Feet per second symbol.- See Also:
-
MILES_PER_HOUR
Miles per hour symbol.- See Also:
-
-
Constructor Details
-
SpeedFormatter
public SpeedFormatter()Constructor. -
SpeedFormatter
Constructor with locale.- Parameters:
locale- locale.- Throws:
IllegalArgumentException- if locale is null.
-
SpeedFormatter
Copy constructor.- Parameters:
formatter- input instance to copy from.- Throws:
NullPointerException- if provided formatter is null.
-
-
Method Details
-
equals
Determines if two speed formatters are equal by comparing all of their internal parameters.- Overrides:
equalsin classMeasureFormatter<Speed,SpeedUnit> - 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<Speed,SpeedUnit> - Returns:
- hash code.
-
getUnitSystem
Gets unit system for detected unit into provided string representation of a measurement.- Specified by:
getUnitSystemin classMeasureFormatter<Speed,SpeedUnit> - 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 speed value and unit.- Specified by:
parsein classMeasureFormatter<Speed,SpeedUnit> - Parameters:
source- a string to be parsed.- Returns:
- a speed containing a value and unit.
- Throws:
ParseException- if provided string cannot be parsed.UnknownUnitException- if unit cannot be determined.
-
findUnit
Attempts to determine a speed unit within a measurement string representation.- Specified by:
findUnitin classMeasureFormatter<Speed,SpeedUnit> - Parameters:
source- a measurement string representation.- Returns:
- a speed unit, or null if none can be determined.
-
formatAndConvert
Formats and converts provided speed 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<Speed,SpeedUnit> - Parameters:
value- a speed value.unit- a speed unit.system- system unit to convert speed to.- Returns:
- a string representation of speed value and unit.
-
formatAndConvertMetric
Formats and converts provided speed value and unit using metric unit system. If provided speed value is too large for provided speed unit, this method will convert it to a more appropriate unit.- Parameters:
value- a speed value.unit- a speed unit.- Returns:
- a string representation of speed value and unit using metric unit system.
-
formatAndConvertImperial
Formats and converts provided speed value and unit using imperial unit system. If provided speed value is too large for provided speed unit, this method will convert it to a more appropriate unit.- Parameters:
value- a speed value.unit- a speed unit.- Returns:
- a string representation of speed value and unit using imperial unit system.
-
getUnitSymbol
Returns unit string representation.- Specified by:
getUnitSymbolin classMeasureFormatter<Speed,SpeedUnit> - Parameters:
unit- a speed unit.- Returns:
- its string representation.
-