Package com.norconex.commons.lang.unit
Class DataUnitFormatter
java.lang.Object
com.norconex.commons.lang.unit.DataUnitFormatter
- All Implemented Interfaces:
Serializable
Formats a data unit to a human-readable string.
As of 2.0.0, a distinction is made between decimal (default) and binary units. Also, units are now supported up to yotta (10008) or yobi (10248).
- Since:
- 1.4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DataUnit formatter using decimal notation, with default system locale, and without decimals.DataUnitFormatter(DataUnitFormatter formatter) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanFormats a data amount of the given unit to a human-readable representation.format(BigDecimal amount, DataUnit unit) Formats a data amount of the given unit to a human-readable representation.intinthashCode()booleanbooleansetBinaryNotation(boolean binaryNotation) setDecimalPrecision(int decimalPrecision) setFixedUnit(boolean fixedUnit) setRoundingMode(RoundingMode roundingMode) toString()withBinaryNotation(boolean binaryNotation) withDecimalPrecision(int decimalPrecision) withFixedUnit(boolean fixedUnit) withLocale(Locale locale) withRoundingMode(RoundingMode roundingMode)
-
Constructor Details
-
DataUnitFormatter
public DataUnitFormatter()Creates a new DataUnit formatter using decimal notation, with default system locale, and without decimals. -
DataUnitFormatter
Copy constructor. Passing anullformatter is the same as invokingDataUnitFormatter()without arguments- Parameters:
formatter- formatter to copy
-
-
Method Details
-
getLocale
-
setLocale
-
withLocale
-
getDecimalPrecision
public int getDecimalPrecision() -
setDecimalPrecision
-
withDecimalPrecision
-
isFixedUnit
public boolean isFixedUnit() -
setFixedUnit
-
withFixedUnit
-
isBinaryNotation
public boolean isBinaryNotation() -
setBinaryNotation
-
withBinaryNotation
-
getRoundingMode
-
setRoundingMode
-
withRoundingMode
-
format
Formats a data amount of the given unit to a human-readable representation.- Parameters:
amount- the amount to formatunit- the data unit type of the amount- Returns:
- formatted string
-
format
Formats a data amount of the given unit to a human-readable representation.- Parameters:
amount- the amount to formatunit- the data unit type of the amount- Returns:
- formatted string
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode()
-