Package com.irurueta.units
Class ForceFormatter
- All Implemented Interfaces:
Cloneable
Formats and parses force value and unit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDyne symbol.static final StringKilogram-force symbol.static final StringKilonewton symbol.static final StringNewton symbol.static final StringPound-force symbol.Fields inherited from class com.irurueta.units.MeasureFormatter
DEFAULT_VALUE_AND_UNIT_FORMAT_PATTERN -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ForceFormatter(ForceFormatter formatter) Copy constructor.ForceFormatter(Locale locale) Constructor with locale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if two force formatters are equal by comparing all of their internal parameters.Attempts to determine a force unit within a measurement string representation.formatAndConvert(Number value, ForceUnit unit, UnitSystem system) Formats and converts provided force value and unit using provided unit system.formatAndConvertImperial(Number value, ForceUnit unit) Formats and converts provided force value and unit using imperial unit system.formatAndConvertMetric(Number value, ForceUnit unit) Formats and converts provided force value and unit using metric unit system.getUnitSymbol(ForceUnit 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 force value and unit.Methods inherited from class com.irurueta.units.MeasureFormatter
clone, containsSymbol, format, format, format, format, format, format, formatAndConvert, formatAndConvert, formatAndConvert, formatAndConvert, formatAndConvert, getAvailableLocales, getLocale, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberFormat, getRoundingMode, getUnitSystem, getValueAndUnitFormatPattern, internalClone, internalParse, isGroupingUsed, isImperialUnit, isMetricUnit, isParseIntegerOnly, isValidMeasurement, isValidUnit, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly, setRoundingMode, setValueAndUnitFormatPattern
-
Field Details
-
NEWTON
Newton symbol.- See Also:
-
KILONEWTON
Kilonewton symbol.- See Also:
-
POUND_FORCE
Pound-force symbol.- See Also:
-
DYNE
Dyne symbol.- See Also:
-
KILOGRAM_FORCE
Kilogram-force symbol.- See Also:
-
-
Constructor Details
-
ForceFormatter
public ForceFormatter()Constructor. -
ForceFormatter
Constructor with locale.- Parameters:
locale- locale.- Throws:
IllegalArgumentException- if locale is null.
-
ForceFormatter
Copy constructor.- Parameters:
formatter- input instance to copy from.- Throws:
NullPointerException- if provided formatter is null.
-
-
Method Details
-
equals
Determines if two force formatters are equal by comparing all of their internal parameters.- Overrides:
equalsin classMeasureFormatter<Force,ForceUnit> - 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. It is kept becauseequals(Object)is overridden, so both methods remain consistent.- Overrides:
hashCodein classMeasureFormatter<Force,ForceUnit> - Returns:
- hash code.
-
getUnitSystem
Gets unit system for detected unit into provided string representation of a measurement.- Specified by:
getUnitSystemin classMeasureFormatter<Force,ForceUnit> - 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 force value and unit.- Specified by:
parsein classMeasureFormatter<Force,ForceUnit> - Parameters:
source- a string to be parsed.- Returns:
- a force containing a value and unit.
- Throws:
ParseException- if provided string cannot be parsed.UnknownUnitException- if unit cannot be determined.
-
findUnit
Attempts to determine a force unit within a measurement string representation.- Specified by:
findUnitin classMeasureFormatter<Force,ForceUnit> - Parameters:
source- a measurement string representation.- Returns:
- a force unit, or null if none can be determined.
-
formatAndConvert
Formats and converts provided force 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<Force,ForceUnit> - Parameters:
value- a force value.unit- a force unit.system- system unit to convert force to.- Returns:
- a string representation of force value and unit.
-
formatAndConvertMetric
Formats and converts provided force value and unit using metric unit system. Values whose magnitude is lower than 1000 newtons are represented in newtons, otherwise they are converted to kilonewtons.- Parameters:
value- a force value.unit- a force unit.- Returns:
- a string representation of force value and unit using metric unit system.
-
formatAndConvertImperial
Formats and converts provided force value and unit using imperial unit system. Pound-force is the only imperial force unit, hence any value is converted to it.- Parameters:
value- a force value.unit- a force unit.- Returns:
- a string representation of force value and unit using imperial unit system.
-
getUnitSymbol
Returns unit string representation.- Specified by:
getUnitSymbolin classMeasureFormatter<Force,ForceUnit> - Parameters:
unit- a force unit.- Returns:
- its string representation.
-