加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090226040124/http://developer.android.com:80/reference/java/text/ChoiceFormat.html
public class

ChoiceFormat

extends NumberFormat
java.lang.Object
   ↳ java.text.Format
     ↳ java.text.NumberFormat
       ↳ java.text.ChoiceFormat

Class Overview

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

[Expand]
Inherited Constants
From class java.text.NumberFormat
Public Constructors
ChoiceFormat(double[] limits, String[] formats)
Constructs a new ChoiceFormat with the specified ranges and associated strings.
ChoiceFormat(String template)
Constructs a new ChoiceFormat with the strings and ranges parsed from the specified pattern.
Public Methods
void applyPattern(String template)
Parses the pattern to determine new strings and ranges for this ChoiceFormat.
Object clone()
Returns a new instance of ChoiceFormat with the same ranges and strings as this ChoiceFormat.
boolean equals(Object object)
Compares the specified object to this ChoiceFormat and answer if they are equal.
StringBuffer format(double value, StringBuffer buffer, FieldPosition field)
Appends to the specified StringBuffer the string associated with the range in which the specified double value fits.
StringBuffer format(long value, StringBuffer buffer, FieldPosition field)
Appends to the specified StringBuffer the string associated with the range in which the specified long value fits.
Object[] getFormats()
Returns the Strings associated with the ranges of this ChoiceFormat.
double[] getLimits()
Returns the ranges of this ChoiceFormat.
int hashCode()
Returns an integer hash code for the receiver.
final static double nextDouble(double value)
Returns the double value which is closest to the specified double but larger.
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.
Number parse(String string, ParsePosition position)
Parse a Double from the specified String starting at the index specified by the ParsePosition.
final static double previousDouble(double value)
Returns the double value which is closest to the specified double but smaller.
void setChoices(double[] limits, String[] formats)
Sets the ranges and associated strings of this ChoiceFormat.
String toPattern()
Returns the pattern of this ChoiceFormat which specified the ranges and their associated strings.
[Expand]
Inherited Methods
From class java.text.NumberFormat
From class java.text.Format
From class java.lang.Object

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
Throws
IllegalArgumentException then an error occurs parsing the pattern

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
Throws
IllegalArgumentException then an error occurs parsing the pattern

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
See Also

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
See Also

public StringBuffer format (double value, StringBuffer buffer, FieldPosition field)

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

public StringBuffer format (long value, StringBuffer buffer, FieldPosition field)

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.

Returns
  • an array of String

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.

Returns
  • the receiver's hash
See Also

public static final double nextDouble (double value)

Returns the double value which is closest to the specified double but larger.

Parameters
value a double value
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

public Number parse (String string, ParsePosition position)

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.

Parameters
value a double value
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.

Returns
  • the pattern