Build 1.0_r1(from source)

java.text
Class ChoiceFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.NumberFormat
          extended by java.text.ChoiceFormat
All Implemented Interfaces:
Serializable, Cloneable

public class ChoiceFormat
extends NumberFormat

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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.NumberFormat
NumberFormat.Field
 
Field Summary
 
Fields inherited from class java.text.NumberFormat
FRACTION_FIELD, INTEGER_FIELD
 
Constructor Summary
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.
 
Method Summary
 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.
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.
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.
 
Methods inherited from class java.text.NumberFormat
format, format, format, getAvailableLocales, getCurrency, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPattern, getPercentInstance, getPercentInstance, isGroupingUsed, isParseIntegerOnly, parse, parseObject, setCurrency, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly
 
Methods inherited from class java.text.Format
convertPattern, format, formatToCharacterIterator, getBundle, parseObject, upTo, upToWithQuotes
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChoiceFormat

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.

ChoiceFormat

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
Method Detail

applyPattern

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

clone

public Object clone()
Returns a new instance of ChoiceFormat with the same ranges and strings as this ChoiceFormat.

Overrides:
clone in class NumberFormat
Returns:
a shallow copy of this ChoiceFormat
See Also:
Cloneable

equals

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.

Overrides:
equals in class NumberFormat
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this ChoiceFormat, false otherwise
See Also:
hashCode()

format

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.

Specified by:
format in class NumberFormat
Parameters:
value - the double to format
buffer - the StringBuffer
field - a FieldPosition which is ignored
Returns:
the StringBuffer parameter buffer

format

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.

Specified by:
format in class NumberFormat
Parameters:
value - the long to format
buffer - the StringBuffer
field - a FieldPosition which is ignored
Returns:
the StringBuffer parameter buffer

getFormats

public Object[] getFormats()
Returns the Strings associated with the ranges of this ChoiceFormat.

Returns:
an array of String

getLimits

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.

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Overrides:
hashCode in class NumberFormat
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

nextDouble

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

nextDouble

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

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.

Specified by:
parse in class NumberFormat
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

previousDouble

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

setChoices

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.

toPattern

public String toPattern()
Returns the pattern of this ChoiceFormat which specified the ranges and their associated strings.

Returns:
the pattern

Build 1.0_r1(from source)

Please submit a feedback, bug or feature