|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectFormat
RangeFormat
public class RangeFormat
Parses and formats ranges of the given type. The kind of ranges created
by the parse method is determined by the class of range components:
Date, then the parse method
will create DateRange objects.Number, then the parse method
will create MeasurementRange objects if the text to parse contains a
unit of measure, or NumberRange otherwise.
Range,
DateRange,
NumberRange,
MeasurementRange,
Serialized Form
| utility/geotk-utility (download) | View source code for this class |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class Format |
|---|
Format.Field |
| Field Summary | |
|---|---|
protected Class<?> |
elementClass
The type of the range components. |
protected Format |
elementFormat
The format to use for parsing and formatting the range components. |
static int |
MAX_VALUE_FIELD
The constant value for FieldPosition which designate the maximal value. |
static int |
MIN_VALUE_FIELD
The constant value for FieldPosition which designate the minimal value. |
static int |
UNIT_FIELD
The constant value for FieldPosition which designate the units of measurement. |
protected UnitFormat |
unitFormat
The format for units of measurement, or null if none. |
| Constructor Summary | |
|---|---|
RangeFormat()
Creates a new format for parsing and formatting number ranges using the default locale. |
|
RangeFormat(Locale locale)
Creates a new format for parsing and formatting number ranges using the given locale. |
|
RangeFormat(Locale locale,
Class<?> elementClass)
Creates a new format for parsing and formatting ranges of the given element class using the given locale. |
|
RangeFormat(Locale locale,
TimeZone timezone)
Creates a new format for parsing and formatting date ranges using the given locale and timezone. |
|
| Method Summary | |
|---|---|
StringBuffer |
format(Object range,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a Range and appends the resulting text to a given string buffer. |
String |
getElementPattern(boolean localized)
Returns the pattern used by elementFormat for formatting the minimum and
maximum values. |
static RangeFormat |
getInstance()
Constructs a new RangeFormat for the default locale. |
static RangeFormat |
getInstance(Locale locale)
Constructs a new RangeFormat for the specified locale. |
RangeSymbols |
getSymbols()
Returns the symbols used for parsing and formatting ranges. |
Range<?> |
parse(String source)
Parses text from the given string to produce a range. |
Range<?> |
parse(String source,
ParsePosition pos)
Parses text from a string to produce a range. |
Object |
parseObject(String source)
Parses text from a string to produce a range. |
Object |
parseObject(String source,
ParsePosition pos)
Parses text from a string to produce a range. |
void |
setElementPattern(String pattern,
boolean localized)
Sets the pattern to be used by elementFormat for formatting the minimum and
maximum values. |
void |
setSymbols(RangeSymbols symbols)
Sets the symbols to use for parsing and formatting ranges. |
| Methods inherited from class Format |
|---|
clone, format, formatToCharacterIterator |
| Methods inherited from class Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MIN_VALUE_FIELD
FieldPosition which designate the minimal value.
This constant can be combined with one of the *_FIELD constants defined
in NumberFormat or DateFormat classes for fetching the position
of a formatted field. For example in order to get the position where the fraction
digits of the minimal value begin, use:
FieldPosition pos = new FieldPosition(NumberFormat.FRACTION_FIELD | RangeFormat.MIN_VALUE_FIELD); rangeFormat.format(range, buffer, pos); int beginIndex = pos.getBeginIndex();
public static final int MAX_VALUE_FIELD
FieldPosition which designate the maximal value.
This constant can be combined with one of the *_FIELD constants defined
in NumberFormat or DateFormat classes for fetching the position
of a formatted field. For example in order to get the position where the fraction
digits of the maximal value begin, use:
FieldPosition pos = new FieldPosition(NumberFormat.FRACTION_FIELD | RangeFormat.MAX_VALUE_FIELD); rangeFormat.format(range, buffer, pos); int beginIndex = pos.getBeginIndex();
public static final int UNIT_FIELD
FieldPosition which designate the units of measurement.
This field can not be combined with other field masks.
protected final Class<?> elementClass
Number, Angle,
Date or a subclass of those types. This value determines the kind of range
to be created by the parse method:
NumberRange if the element class is assignable to Number.DateRange if the element class is assignable to Date.
protected final Format elementFormat
AngleFormat if the element class is assignable to Angle.NumberFormat if the element class is assignable to Number.DateFormat if the element class is assignable to Date.
protected final UnitFormat unitFormat
null if none. This is non-null if and
only if elementClass is assignable to Number but not to Angle.
| Constructor Detail |
|---|
public RangeFormat()
public RangeFormat(Locale locale)
locale - The locale for parsing and formatting range components.
public RangeFormat(Locale locale,
TimeZone timezone)
locale - The locale for parsing and formatting range components.timezone - The timezone for the date to be formatted.
public RangeFormat(Locale locale,
Class<?> elementClass)
throws IllegalArgumentException
Date.class or some subclass of Number.class.
locale - The locale for parsing and formatting range components.elementClass - The type of range components.
IllegalArgumentException - If the given type is not recognized by this constructor.| Method Detail |
|---|
public static RangeFormat getInstance()
RangeFormat for the default locale.
public static RangeFormat getInstance(Locale locale)
RangeFormat for the specified locale.
locale - The locale.
public RangeSymbols getSymbols()
public void setSymbols(RangeSymbols symbols)
symbols - The new symbols to use for this format.public String getElementPattern(boolean localized)
elementFormat for formatting the minimum and
maximum values. If the element format does not use pattern, returns null.
localized - true for returning the localized pattern, or false
for the unlocalized one.
null if the elementFormat doesn't use pattern.
public void setElementPattern(String pattern,
boolean localized)
elementFormat for formatting the minimum and
maximum values.
pattern - The new pattern.localized - true if the given pattern is localized.
IllegalStateException - If the elementFormat does not use pattern.
public StringBuffer format(Object range,
StringBuffer toAppendTo,
FieldPosition pos)
Range and appends the resulting text to a given string buffer. The default
implementation formats the range using the same rules than Range.toString(), except
that the values (numbers, angles or dates) are formatted using the Format object
appropriate for the locale given at construction time.
format in class Formatrange - The Range object to format.toAppendTo - Where the text is to be appended.pos - Identifies a field in the formatted text.
toAppendTo, with formatted text appended.
IllegalArgumentException - If this formatter can not format the given object.
public Object parseObject(String source)
throws ParseException
parse(String) with no additional work.
parseObject in class Formatsource - The text, part of which should be parsed.
null in case of error.
ParseException - If the given string can not be fully parsed.
public Object parseObject(String source,
ParsePosition pos)
parse(String, ParsePosition) with no additional work.
parseObject in class Formatsource - The text, part of which should be parsed.pos - Index and error index information as described above.
null in case of error.
public Range<?> parse(String source)
throws ParseException
source - The text to parse.
null).
ParseException - If the given string can not be fully parsed.
public Range<?> parse(String source,
ParsePosition pos)
pos. If parsing succeeds, then the index of pos is
updated to the index after the last character used, and the parsed range is returned. If
an error occurs, then the index of pos is not changed, the error index of pos
is set to the index of the character where the error occurred, and null is returned.
source - The text, part of which should be parsed.pos - Index and error index information as described above.
null in case of error.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||