|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.science.FormatUtil
public final class FormatUtil
Provides static utility methods to help in formatting/scaling of quantities.
This class is multithread safe: it is stateless.
Prefix
Nested Class Summary | |
---|---|
static class |
FormatUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Constructor Summary | |
---|---|
private |
FormatUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | |
---|---|
static String |
toEngineeringString(BigDecimal quantity,
Unit unit)
Returns
(i.e. all digits retained). |
static String |
toEngineeringString(BigDecimal quantity,
Unit unit,
int numberDigitsFractional)
Returns quantity expressed in enginnering notation with the exponent accounted for by the appropriate prefix of unit. |
static String |
toEngineeringString(double quantity,
Unit unit)
Returns
(i.e. all digits retained). |
static String |
toEngineeringString(double quantity,
Unit unit,
int numberDigitsFractional)
If quantity is NaN or infinite, then simply returns quantity + " " + unit.getSymbol() . |
static String |
toEngineeringTime(double time)
Convenience method that simply returns . |
static String |
toEngineeringTime(double time,
int numberDigitsFractional)
Convenience method that simply returns . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private FormatUtil()
Method Detail |
---|
public static String toEngineeringString(double quantity, Unit unit) throws IllegalArgumentException
toEngineeringString
(quantity, unit, -1)
(i.e. all digits retained).
quantity
- the number that is to be formattedunit
- the relevant Unit instance
IllegalArgumentException
- if unit == nullpublic static String toEngineeringString(BigDecimal quantity, Unit unit) throws IllegalArgumentException
toEngineeringString
(quantity, unit, -1)
(i.e. all digits retained).
quantity
- the number that is to be formattedunit
- the relevant Unit instance
IllegalArgumentException
- if unit == nullpublic static String toEngineeringString(double quantity, Unit unit, int numberDigitsFractional) throws IllegalArgumentException
quantity + " " + unit.getSymbol()
.
Else simply returns toEngineeringString
(BigDecimal.valueOf
(quantity), unit, numberDigitsFractional)
.
quantity
- the number that is to be formattedunit
- the relevant Unit instancenumberDigitsFractional
- is either -1 (meaning retain all digits),
or else is some value >= 0 which specifies how many digits after the decimal point are to be retained
IllegalArgumentException
- if unit == null; numberDigitsFractional < -1public static String toEngineeringString(BigDecimal quantity, Unit unit, int numberDigitsFractional) throws IllegalArgumentException
Unit.second
)Prefix.getScalePrefix
is used to determine the scaling factor.
quantity
- the number that is to be formattedunit
- the relevant Unit instancenumberDigitsFractional
- is either -1 (meaning retain all digits),
or else is some value >= 0 which specifies how many digits after the decimal point are to be retained
IllegalArgumentException
- if unit == null; numberDigitsFractional < -1public static String toEngineeringTime(double time)
toEngineeringTime
(time, -1)
.
time
- the time that is to be formatted; the units of this quantity must be in secondspublic static String toEngineeringTime(double time, int numberDigitsFractional) throws IllegalArgumentException
toEngineeringString
(time, Unit.second, numberDigitsFractional)
.
time
- the time that is to be formatted; the units of this quantity must be in secondsnumberDigitsFractional
- is either -1 (meaning retain all digits),
or else is some value >= 0 which specifies how many digits after the decimal point are to be retained
IllegalArgumentException
- if numberDigitsFractional < -1
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |