| java.lang.Object java.text.DigitList
DigitList | final class DigitList implements Cloneable(Code) | | Digit List. Private to DecimalFormat.
Handles the transcoding
between numeric values and strings of characters. Only handles
non-negative numbers. The division of labor between DigitList and
DecimalFormat is that DigitList handles the radix 10 representation
issues; DecimalFormat handles the locale-specific issues such as
positive/negative, grouping, decimal point, currency, and so on.
A DigitList is really a representation of a floating point value.
It may be an integer value; we assume that a double has sufficient
precision to represent all digits of a long.
The DigitList representation consists of a string of characters,
which are the digits radix 10, from '0' to '9'. It also has a radix
10 exponent associated with it. The value represented by a DigitList
object can be computed by mulitplying the fraction f, where 0 <= f < 1,
derived by placing all the digits of the list to the right of the
decimal point, by 10^exponent.
See Also: Locale See Also: Format See Also: NumberFormat See Also: DecimalFormat See Also: ChoiceFormat See Also: MessageFormat version: 1.28, 11/17/03 author: Mark Davis, Alan Liu |
Field Summary | |
final public static int | DBL_DIG | final public static int | MAX_COUNT The maximum number of significant digits in an IEEE 754 double, that
is, in a Java double. | public int | count | public int | decimalAt These data members are intentionally public and can be set directly.
The value represented is given by placing the decimal point before
digits[decimalAt]. | public char[] | digits |
Method Summary | |
public void | append(char digit) Appends a digit to the list. | public void | clear() Clears out the digits. | public Object | clone() Creates a copy of this object. | public boolean | equals(Object obj) equality test between two digit lists. | boolean | fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero) Return true if the number represented by this object can fit into
a long. | final public double | getDouble() Utility routine to get the value of the digit list
If (count == 0) this throws a NumberFormatException, which
mimics Long.parseLong(). | final public long | getLong() Utility routine to get the value of the digit list. | public int | hashCode() Generates the hash code for the digit list. | boolean | isZero() Return true if the represented number is zero. | final public void | set(double source, int maximumFractionDigits) Set the digit list to a representation of the given double value. | final void | set(double source, int maximumDigits, boolean fixedPoint) Set the digit list to a representation of the given double value.
This method supports both fixed-point and exponential notation.
Parameters: source - Value to be converted; must not be Inf, -Inf, Nan,or a value <= 0. Parameters: maximumDigits - The most fractional or total digits which shouldbe converted. Parameters: fixedPoint - If true, then maximumDigits is the maximumfractional digits to be converted. | final public void | set(long source) | final public void | set(long source, int maximumDigits) Set the digit list to a representation of the given long value.
Parameters: source - Value to be converted; must be >= 0 or ==Long.MIN_VALUE. Parameters: maximumDigits - The most digits which should be converted.If maximumDigits is lower than the number of significant digitsin source, the representation will be rounded. | public String | toString() |
DBL_DIG | final public static int DBL_DIG(Code) | | |
MAX_COUNT | final public static int MAX_COUNT(Code) | | The maximum number of significant digits in an IEEE 754 double, that
is, in a Java double. This must not be increased, or garbage digits
will be generated, and should not be decreased, or accuracy will be lost.
|
decimalAt | public int decimalAt(Code) | | These data members are intentionally public and can be set directly.
The value represented is given by placing the decimal point before
digits[decimalAt]. If decimalAt is < 0, then leading zeros between
the decimal point and the first nonzero digit are implied. If decimalAt
is > count, then trailing zeros between the digits[count-1] and the
decimal point are implied.
Equivalently, the represented value is given by f * 10^decimalAt. Here
f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
the right of the decimal.
DigitList is normalized, so if it is non-zero, figits[0] is non-zero. We
don't allow denormalized numbers because our exponent is effectively of
unlimited magnitude. The count value contains the number of significant
digits present in digits[].
Zero is represented by any DigitList with count == 0 or with each digits[i]
for all i <= count == '0'.
|
digits | public char[] digits(Code) | | |
append | public void append(char digit)(Code) | | Appends a digit to the list. Ignores all digits over MAX_COUNT,
since they are not significant for either longs or doubles.
|
clear | public void clear()(Code) | | Clears out the digits.
Use before appending them.
Typically, you set a series of digits with append, then at the point
you hit the decimal point, you set myDigitList.decimalAt = myDigitList.count;
then go on appending digits.
|
clone | public Object clone()(Code) | | Creates a copy of this object.
a clone of this instance. |
equals | public boolean equals(Object obj)(Code) | | equality test between two digit lists.
|
fitsIntoLong | boolean fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero)(Code) | | Return true if the number represented by this object can fit into
a long.
Parameters: isPositive - true if this number should be regarded as positive Parameters: ignoreNegativeZero - true if -0 should be regarded as identical to+0; otherwise they are considered distinct true if this number fits into a Java long |
getDouble | final public double getDouble()(Code) | | Utility routine to get the value of the digit list
If (count == 0) this throws a NumberFormatException, which
mimics Long.parseLong().
|
getLong | final public long getLong()(Code) | | Utility routine to get the value of the digit list.
If (count == 0) this returns 0, unlike Long.parseLong().
|
hashCode | public int hashCode()(Code) | | Generates the hash code for the digit list.
|
isZero | boolean isZero()(Code) | | Return true if the represented number is zero.
|
set | final public void set(double source, int maximumFractionDigits)(Code) | | Set the digit list to a representation of the given double value.
This method supports fixed-point notation.
Parameters: source - Value to be converted; must not be Inf, -Inf, Nan,or a value <= 0. Parameters: maximumFractionDigits - The most fractional digits which shouldbe converted. |
set | final void set(double source, int maximumDigits, boolean fixedPoint)(Code) | | Set the digit list to a representation of the given double value.
This method supports both fixed-point and exponential notation.
Parameters: source - Value to be converted; must not be Inf, -Inf, Nan,or a value <= 0. Parameters: maximumDigits - The most fractional or total digits which shouldbe converted. Parameters: fixedPoint - If true, then maximumDigits is the maximumfractional digits to be converted. If false, total digits. |
set | final public void set(long source)(Code) | | Utility routine to set the value of the digit list from a long
|
set | final public void set(long source, int maximumDigits)(Code) | | Set the digit list to a representation of the given long value.
Parameters: source - Value to be converted; must be >= 0 or ==Long.MIN_VALUE. Parameters: maximumDigits - The most digits which should be converted.If maximumDigits is lower than the number of significant digitsin source, the representation will be rounded. Ignored if <= 0. |
|
|