java.text.ChoiceFormat
ChoiceFormat is used to associate strings with ranges of double values. The
strings and ranges are either specified using arrays or with a pattern which
is parsed to determine the Strings and ranges.
Summary
Public Constructors
Public Methods
clone,
equals,
format,
format,
format,
format,
format,
getAvailableLocales,
getCurrency,
getCurrencyInstance,
getCurrencyInstance,
getInstance,
getInstance,
getIntegerInstance,
getIntegerInstance,
getMaximumFractionDigits,
getMaximumIntegerDigits,
getMinimumFractionDigits,
getMinimumIntegerDigits,
getNumberInstance,
getNumberInstance,
getPercentInstance,
getPercentInstance,
hashCode,
isGroupingUsed,
isParseIntegerOnly,
parse,
parse,
parseObject,
setCurrency,
setGroupingUsed,
setMaximumFractionDigits,
setMaximumIntegerDigits,
setMinimumFractionDigits,
setMinimumIntegerDigits,
setParseIntegerOnly
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
ChoiceFormat(double[] limits, String[] formats)
Constructs a new ChoiceFormat with the specified ranges and associated
strings.
Parameters
limits
| an array of double, the ranges are greater or equal to the
value in lower index up to less than the value in the next
higher index. The bounds of the lowest and highest indexes are
negative and positive infinity. |
formats
| the strings associated with the ranges. The lower bound of the
associated range is at the same index as the string.
|
public
ChoiceFormat(String template)
Constructs a new ChoiceFormat with the strings and ranges parsed from the
specified pattern.
Parameters
template
| the pattern of strings and ranges |
Public Methods
public
void
applyPattern(String template)
Parses the pattern to determine new strings and ranges for this
ChoiceFormat.
Parameters
template
| the pattern of strings and ranges |
public
Object
clone()
Returns a new instance of ChoiceFormat with the same ranges and strings
as this ChoiceFormat.
Returns
- a shallow copy of this ChoiceFormat
public
boolean
equals(Object object)
Compares the specified object to this ChoiceFormat and answer if they are
equal. The object must be an instance of ChoiceFormat and have the same
limits and formats.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this ChoiceFormat, false
otherwise
Appends to the specified StringBuffer the string associated with the
range in which the specified double value fits.
Parameters
value
| the double to format |
buffer
| the StringBuffer |
field
| a FieldPosition which is ignored |
Returns
- the StringBuffer parameter
buffer
Appends to the specified StringBuffer the string associated with the
range in which the specified long value fits.
Parameters
value
| the long to format |
buffer
| the StringBuffer |
field
| a FieldPosition which is ignored |
Returns
- the StringBuffer parameter
buffer
public
Object[]
getFormats()
Returns the Strings associated with the ranges of this ChoiceFormat.
public
double[]
getLimits()
Returns the ranges of this ChoiceFormat.
Returns
- an array of double, the ranges are greater or equal to the value
in lower index up to less than the value in the next higher
index. The bounds of the lowest and highest indexes are negative
and positive infinity.
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
static
final
double
nextDouble(double value)
Returns the double value which is closest to the specified double but
larger.
Returns
- the next larger double value
public
static
double
nextDouble(double value, boolean increment)
Returns the double value which is closest to the specified double but
either larger or smaller as specified.
Parameters
value
| a double value |
increment
| true to get a larger value, false to get a smaller value |
Returns
- the next larger or smaller double value
Parse a Double from the specified String starting at the index specified
by the ParsePosition. The String is compared to the strings of this
ChoiceFormat and if a match occurs, the answer is the lower bound of the
corresponding range. If the string is successfully parsed, the index of
the ParsePosition is updated to the index following the parsed text.
Parameters
string
| the String to parse |
position
| the ParsePosition, updated on return with the index following
the parsed text, or on error the index is unchanged and the
error index is set to the index where the error occurred |
Returns
- a Double resulting from the parse, or Double.NaN if there is an
error
public
static
final
double
previousDouble(double value)
Returns the double value which is closest to the specified double but
smaller.
Returns
- the next smaller double value
public
void
setChoices(double[] limits, String[] formats)
Sets the ranges and associated strings of this ChoiceFormat.
Parameters
limits
| an array of double, the ranges are greater or equal to the
value in lower index up to less than the value in the next
higher index. The bounds of the lowest and highest indexes are
negative and positive infinity. |
formats
| the strings associated with the ranges. The lower bound of the
range is at the same index as the string.
|
public
String
toPattern()
Returns the pattern of this ChoiceFormat which specified the ranges and
their associated strings.