jET
1.0beta1


prv.doman.util
Class DegreeFormat

java.lang.Object
  |
  +--java.text.Format
        |
        +--prv.doman.util.DegreeFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class DegreeFormat
extends java.text.Format

Formats and parse angle with specified pattern.

It formats integer and floating-point numbers. The full output may look like these:

23°35′03.234″
1,567°0′59″
0°00.500′
-24.75°
90°

So output seems to have at most four fields: degrees, minutes, seconds and the fractional part of seconds. Note that symbols and aren't the ASCII Quotation Mark (Unicode \u0022) and Apostrophe (Unicode \u0027), but Mathematical symbols: Prime (Unicode \u2033) and Double Prime (Unicode \u2032). Note that decimal separators and fraction dot might be localized.

The right order in format must be as follows: degrees, minutes, seconds. The fractional part is always at the and of output and it is optional. Optional are minutes and seconds also, but it is not possible to have format for examaple: degrees and seconds without minutes.

Patterns

The parttern is a string containing characters with special meanings:

DThe integer part of degree field.
dThe fractional part of degree field.
MThe integer part of minute field.
mThe fractional part of minute field.
SThe integer part of second fields.
sThe fractional part of second field.
.Fractional separator (localized).
° (Unicode \u00B0)Degree symbol.
′ (Unicode \u2032)Minute symbol
″ (Unicode \u2033)Second symbol.

Here are some expamples of patterns:

PatternExamples
360°
DDD.dd°008.55°241.08°
D°M.m′123°20.2′-3°2.0′
DDDMMSS18030000030000

For symbol customization use class DegreeFormatSymbols.

See Also:
Serialized Form

Field Summary
static int DEGREE_FIELD
          The degree field.
static int MINUTE_FIELD
          The minute field.
static int SECOND_FIELD
          The second field.
 
Constructor Summary
DegreeFormat()
          Constructs degree format with default pattern and symbols.
DegreeFormat(java.lang.String pattern)
          Constructs degree format with specified pattern.
DegreeFormat(java.lang.String pattern, DegreeFormatSymbols symbols)
          Constructs degree format with specified pattern and symbols.
 
Method Summary
 void applyPattern(java.lang.String pattern)
          Applies pattern to this format.
 java.lang.String format(double number)
          Formats simple double value.
 java.lang.StringBuffer format(double number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats floating point number using format's pattern and symbols.
 java.lang.String format(int number)
          Formats integer value.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Tries to format object with output redirected to string buffer and with position.
static java.util.Locale[] getAvailableLocales()
          Returns all available locales in Java Virtual Machine.
 DegreeFormatSymbols getDegreeFormatSymbols()
          Gets the format symbols of this format.
static DegreeFormat getInstance()
          Gets the instance of degree format class with default locale.
static DegreeFormat getInstance(java.util.Locale locale)
          Gets the instace of degree format class with specified locale.
 java.lang.Double parse(java.lang.String source, java.text.ParsePosition parsePosition)
          Parses string to find the double number representing.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition parsePosition)
          Parses string to find an object that representing value.
 void setDegreeFormatSymbols(DegreeFormatSymbols s)
          Sets for this format symbols.
 java.lang.String toPattern()
          Gets pattern of this format.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEGREE_FIELD

public static final int DEGREE_FIELD
The degree field.

See Also:
Constant Field Values

MINUTE_FIELD

public static final int MINUTE_FIELD
The minute field.

See Also:
Constant Field Values

SECOND_FIELD

public static final int SECOND_FIELD
The second field.

See Also:
Constant Field Values
Constructor Detail

DegreeFormat

public DegreeFormat()
Constructs degree format with default pattern and symbols. Default pattern is D°MM′SS″.


DegreeFormat

public DegreeFormat(java.lang.String pattern)
Constructs degree format with specified pattern. Symbols are default.

Parameters:
pattern - Pattern string.

DegreeFormat

public DegreeFormat(java.lang.String pattern,
                    DegreeFormatSymbols symbols)
Constructs degree format with specified pattern and symbols.

Parameters:
pattern - Pattern string.
symbols - Custom symbols.
Method Detail

setDegreeFormatSymbols

public void setDegreeFormatSymbols(DegreeFormatSymbols s)
Sets for this format symbols.

Parameters:
s - Degree format symbols.

getDegreeFormatSymbols

public DegreeFormatSymbols getDegreeFormatSymbols()
Gets the format symbols of this format.

Returns:
Degree format symbols.

applyPattern

public void applyPattern(java.lang.String pattern)
Applies pattern to this format. Check the pattern if it has correct syntax.

Parameters:
pattern - A pattern.
Throws:
java.lang.IllegalArgumentException - When pattern has illegal syntax.

toPattern

public java.lang.String toPattern()
Gets pattern of this format.

Returns:
A pattern.

getInstance

public static final DegreeFormat getInstance()
Gets the instance of degree format class with default locale. The pattern is default: D°MM″SS′.


getInstance

public static final DegreeFormat getInstance(java.util.Locale locale)
Gets the instace of degree format class with specified locale. The pattern is default: D°MM″SS′.

Parameters:
locale - lo

getAvailableLocales

public static java.util.Locale[] getAvailableLocales()
Returns all available locales in Java Virtual Machine.

Returns:
Array of locales.

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Tries to format object with output redirected to string buffer and with position. Object must be a number class.

Specified by:
format in class java.text.Format
Parameters:
obj - A number to format.
toAppendTo - String buffer where append to formatted output.
pos - Field position (unused).
Returns:
String buffer with appended formatted output.
Throws:
java.lang.IllegalArgumentException - When object is not a number.

format

public java.lang.String format(double number)
Formats simple double value.

Parameters:
number - Floating point number to format.
Returns:
String containing formatted output.

format

public java.lang.String format(int number)
Formats integer value.

Parameters:
number - Integer number to format.
Returns:
String containing formatted output.

format

public java.lang.StringBuffer format(double number,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats floating point number using format's pattern and symbols. The output will be redirected to string buffer and format starts a the field position.

Parameters:
number - Floating point number going to be formatted.
toAppendTo - String buffer where to append.
pos - Field position (unused).
Returns:
String buffer containing output.
Throws:
java.lang.NullPointerException - When position or string buffer is null.

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition parsePosition)
Parses string to find an object that representing value.

Specified by:
parseObject in class java.text.Format
Parameters:
source - String to parse.
parsePosition - Data structure of success or fail in parsing.
Returns:
An object (a double number).

parse

public java.lang.Double parse(java.lang.String source,
                              java.text.ParsePosition parsePosition)
Parses string to find the double number representing.

This method parses numbers:

Parameters:
source - String to parse.
parsePosition - Data structure to inviligate parsing progress.
Returns:
A double number.

jET
1.0beta1