public class UnitUtil extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UnitUtil.UnitPrefix |
Modifier and Type | Field and Description |
---|---|
static char |
MICRO_CHAR
Constants for special characters
|
static java.lang.String |
MICRO_STRING |
Constructor and Description |
---|
UnitUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
displayTimeAsStringWithComma(double valueInMs,
int precision)
Display the time with a comma and a given precision.
|
static java.lang.String |
displayTimeAsStringWithComma(double valueInMs,
int precision,
java.util.concurrent.TimeUnit unit)
Display the time with a comma and a given precision.
|
static java.lang.String |
displayTimeAsStringWithUnits(double valueInMs,
boolean displayZero)
Display the time with all the units.
|
static java.util.concurrent.TimeUnit |
getBestTimeUnit(double valueInMs)
Return the best unit to display the value.
|
static java.util.concurrent.TimeUnit |
getBestUnit(double valueInMs)
Deprecated.
Use
getBestTimeUnit(double) instead. |
static UnitUtil.UnitPrefix |
getBestUnit(double value,
UnitUtil.UnitPrefix currentUnit)
Get the best unit with the given value and
UnitUtil.UnitPrefix . |
static UnitUtil.UnitPrefix |
getBestUnit(double value,
UnitUtil.UnitPrefix currentUnit,
int dimension)
Get the best unit with the given value and
UnitUtil.UnitPrefix . |
static java.lang.String |
getBestUnitInMeters(double value,
int decimals,
UnitUtil.UnitPrefix currentUnit)
This method returns a string containing the value rounded to a specified
number of decimals and its best unit prefix.
|
static java.lang.String |
getBytesString(double value)
Return the specified value as "bytes" string :
1024 --> "1 KB" 1024*1000 --> "1 MB" 1024*1000*1000 --> "1 GB" ... |
static double |
getValueInUnit(double value,
UnitUtil.UnitPrefix currentUnit,
UnitUtil.UnitPrefix wantedUnit)
Return the value from a specific unit to another unit.
|
static double |
getValueInUnit(double value,
UnitUtil.UnitPrefix currentUnit,
UnitUtil.UnitPrefix wantedUnit,
int dimension)
Return the value from a specific unit to another unit.
|
public static final char MICRO_CHAR
public static final java.lang.String MICRO_STRING
public UnitUtil()
public static java.lang.String getBytesString(double value)
public static UnitUtil.UnitPrefix getBestUnit(double value, UnitUtil.UnitPrefix currentUnit, int dimension)
UnitUtil.UnitPrefix
.getBestTimeUnit(double)
or TimeUnit
methods.getBestUnit(0.01, UnitPrefix.MILLI, 1)
will return UnitPrefix.MICRO
value
- : value used to get the best unit.currentUnit
- : current unit of the value.dimension
- : current unit dimension.getValueInUnit(double, UnitPrefix, UnitPrefix)
public static UnitUtil.UnitPrefix getBestUnit(double value, UnitUtil.UnitPrefix currentUnit)
UnitUtil.UnitPrefix
. By best unit we adapt the
output unit so the value stay between 0.1 --> 100 range (for dimension 1).getBestTimeUnit(double)
or TimeUnit
methods.getBestUnit(0.01, UnitPrefix.MILLI, 1)
will return UnitPrefix.MICRO
value
- : value used to get the best unit.currentUnit
- : current unit of the value.getValueInUnit(double, UnitPrefix, UnitPrefix)
public static double getValueInUnit(double value, UnitUtil.UnitPrefix currentUnit, UnitUtil.UnitPrefix wantedUnit, int dimension)
getBestTimeUnit(double)
or TimeUnit
methods.UnitUtil.UnitPrefix.MILLI
UnitUtil.UnitPrefix.MICRO
value
- : Original value.currentUnit
- : current unitwantedUnit
- : wanted unitdimension
- : unit dimension.wantedUnit
unit.getBestUnit(double, UnitPrefix)
public static double getValueInUnit(double value, UnitUtil.UnitPrefix currentUnit, UnitUtil.UnitPrefix wantedUnit)
getBestTimeUnit(double)
or TimeUnit
methods.UnitUtil.UnitPrefix.MILLI
UnitUtil.UnitPrefix.MICRO
value
- : Original value.currentUnit
- : current unitwantedUnit
- : wanted unitwantedUnit
unit.getBestUnit(double, UnitPrefix)
public static java.lang.String getBestUnitInMeters(double value, int decimals, UnitUtil.UnitPrefix currentUnit)
value
- : value to displaydecimals
- : number of decimals to keepcurrentUnit
- : current unit prefix (Ex: UnitUtil.UnitPrefix.MILLI
)public static java.util.concurrent.TimeUnit getBestTimeUnit(double valueInMs)
TimeUnit.MILLISECONDS
TimeUnit.SECONDS
TimeUnit.MINUTES
valueInMs
- : value in milliseconds.TimeUnit
enumeration value.@Deprecated public static java.util.concurrent.TimeUnit getBestUnit(double valueInMs)
getBestTimeUnit(double)
instead.public static java.lang.String displayTimeAsStringWithComma(double valueInMs, int precision, java.util.concurrent.TimeUnit unit)
valueInMs
- : value in millisecondsprecision
- : number of decimals after commapublic static java.lang.String displayTimeAsStringWithComma(double valueInMs, int precision)
valueInMs
- : value in millisecondsprecision
- : number of decimals after commapublic static java.lang.String displayTimeAsStringWithUnits(double valueInMs, boolean displayZero)
valueInMs
- : value in millisecondsdisplayZero
- : Even if a unit is not relevant (equals to zero), it will be displayed.