Jeospace API

org.jeospace.text
Class AngleFormat

java.lang.Object
  extended byjava.text.Format
      extended byorg.jeospace.text.AngleFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class AngleFormat
extends java.text.Format

Formats Angle objects into readable strings and parses strings into Angle objects.

Version:
$Revision: 1.1.1.1 $
Author:
Rex Melton
See Also:
Affix, Angle, AngleNorm, AngleSign, AngleUnit, Mult, AngleFormatStyle, AngleFormatSymbols, Locale, Serialized Form

Nested Class Summary
static class AngleFormat.Field
          Defines constants that are used as attribute keys in the AttributedCharacterIterator returned from AngleFormat.formatToCharacterIterator and as field identifiers in FieldPosition.
 
Field Summary
protected  DecimalAngleUnit dau
           
protected  Affix directionAffix
          Identifier of the position of the sign symbol as prefix or suffix.
protected  FieldAttributor fieldAttributor
          The field attributor maps field positions within formatted strings and produces an attributed character iterator
protected  Angle fmtAngle
          Scratch Angle object for format methods
protected  boolean isDecimal
           
protected  boolean isSexagesimal
          Identifier of the units that the Angle representation should be formatted in.
protected  int maxDecimalPlaces
          The maximum number of decimal places that will be calculated for the decimal portion of the Angle.
protected  Mult maxMult
          The Mult object corresponding to the maximum number of decimal places that will be calculated for the decimal portion of the Angle.
protected  int minDecimalPlaces
          The minimum number of decimal places that will be calculated for the decimal portion of the Angle.
protected  Mult minMult
          The Mult object corresponding to the minimum number of decimal places that will be calculated for the decimal portion of the Angle.
protected  AngleNorm norm
          Identifier of the normalization type to be performed upon the Angle before formatting.
protected  SexagesimalAngleUnit sau
           
protected  AngleSignPair signPair
          The direction affix preference identifier
protected  AngleFormatSymbols symbols
          The symbols used in formatting.
protected  boolean truncateZeroDecimals
          Flag indicating that any trailing decimal zeros should be truncated during format.
protected  boolean truncateZeroFields
          Flag indicating that any leading zero value fields should be truncated during format.
protected  boolean usePositiveDirectionSymbol
          Flag indicating that if the AngleSign is positive the positive symbol should be used.
protected  AngleSign zeroSign
          The sign to use if the angle has a value of zero.
 
Constructor Summary
AngleFormat(Affix directionAffix, AngleSignPair signPair, AngleNorm norm, AngleUnit units, Mult mult)
          Construct an AngleFormat object.
AngleFormat(Affix directionAffix, AngleSignPair signPair, AngleNorm norm, AngleUnit units, Mult mult, java.util.Locale locale)
          Construct an AngleFormat object.
 
Method Summary
 java.lang.Object clone()
          Return a copy of this AngleFormat object.
 boolean equals(java.lang.Object obj)
          Compare two AngleFormats for equality.
 java.lang.String format(Angle angle)
          Format an Angle object into a human readable String.
 java.lang.StringBuffer format(Angle angle, java.lang.StringBuffer result, java.text.FieldPosition pos)
          Format an Angle object into a human readable string.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer result, java.text.FieldPosition pos)
          Overrides Format.
 java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
          Return the AttributedCharacterIterator describing the formatted value.
 AngleUnit getAngleUnits()
          Return the AngleUnit used in formatting.
 Affix getDirectionAffix()
          Return the directional affix setting.
 FieldAttributor getFieldAttributor()
          Return the FieldAttributor
static AngleFormat getInstance(AngleFormatStyle style)
          Return an AngleFormat object configured to the requested style and the default locale
static AngleFormat getInstance(AngleFormatStyle style, java.util.Locale locale)
          Return an AngleFormat object configured to the requested style and locale
 Mult getMaximumDecimalSize()
          Return the Mult object that cooresponds to the desired maximum number of decimal digits.
 Mult getMinimumDecimalSize()
          Return the Mult object that cooresponds to the desired minimum number of decimal digits.
 AngleNorm getNormalizationOption()
          Get the normalization option used in formatting.
 AngleSignPair getSignPair()
          Get the angle sign convention used in formatting.
 AngleFormatSymbols getSymbols()
          Get the symbols object used in formatting.
 boolean getTruncateZeroDecimals()
          Get the Truncate Zero Decimals option setting.
 boolean getTruncateZeroFields()
          Get the Truncate Zero Fields option setting.
 AngleSign getZeroAngleSign()
          Return the AngleSign value being used if the value of the angle is zero.
 int hashCode()
          Return the hash code for the AngleFormat object
 Angle parse(java.lang.String source)
          Not implemented.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          Not implemented.
protected  java.lang.String processAffix(AngleSign sign, boolean isZero)
          Return the directional affix that matches the style and angle value
 void setAngleUnits(AngleUnit units)
          Set the angle units to be used in formatting.
 void setDirectionAffix(Affix directionAffix)
          Set the directional affix setting.
 void setMaximumDecimalSize(Mult mult)
          Set the maximum number of decimal fractional digits allowed.
 void setMinimumDecimalSize(Mult mult)
          Set the minimum number of decimal fractional digits allowed.
 void setNormalizationOption(AngleNorm norm)
          Set the normalization option to be used in formatting.
 void setSignPair(AngleSignPair signPair)
          Set the angle sign convention to be used in formatting.
 void setSymbols(AngleFormatSymbols symbols)
          Set the symbols object to be used in formatting.
 void setTruncateZeroDecimals(boolean inValue)
          Set the option to eliminate trailing zero decimals.
 void setTruncateZeroFields(boolean inValue)
          Set the option to eliminate leading fields that have zero value.
 void setUsePositiveDirectionSymbol(boolean usePositive)
          Set the flag indicating that if the sign of the angle is positive the positive symbol should be used in formatting.
 void setZeroAngleSign(AngleSign zeroSign)
          Set the AngleSign value to be used if the value of the angle is zero.
 
Methods inherited from class java.text.Format
format, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

truncateZeroFields

protected boolean truncateZeroFields
Flag indicating that any leading zero value fields should be truncated during format.


truncateZeroDecimals

protected boolean truncateZeroDecimals
Flag indicating that any trailing decimal zeros should be truncated during format.


directionAffix

protected Affix directionAffix
Identifier of the position of the sign symbol as prefix or suffix.


norm

protected AngleNorm norm
Identifier of the normalization type to be performed upon the Angle before formatting.


isSexagesimal

protected boolean isSexagesimal
Identifier of the units that the Angle representation should be formatted in. For SexagesimalAngleUnits, this parameter specifies SexagesimalAngleType as well as the the least significant unit of the sexagesimal type that will be calculated for the Angle.


sau

protected SexagesimalAngleUnit sau

isDecimal

protected boolean isDecimal

dau

protected DecimalAngleUnit dau

symbols

protected AngleFormatSymbols symbols
The symbols used in formatting.


maxMult

protected Mult maxMult
The Mult object corresponding to the maximum number of decimal places that will be calculated for the decimal portion of the Angle.


maxDecimalPlaces

protected int maxDecimalPlaces
The maximum number of decimal places that will be calculated for the decimal portion of the Angle.


minMult

protected Mult minMult
The Mult object corresponding to the minimum number of decimal places that will be calculated for the decimal portion of the Angle.


minDecimalPlaces

protected int minDecimalPlaces
The minimum number of decimal places that will be calculated for the decimal portion of the Angle.


zeroSign

protected AngleSign zeroSign
The sign to use if the angle has a value of zero.


signPair

protected AngleSignPair signPair
The direction affix preference identifier


usePositiveDirectionSymbol

protected boolean usePositiveDirectionSymbol
Flag indicating that if the AngleSign is positive the positive symbol should be used.


fieldAttributor

protected FieldAttributor fieldAttributor
The field attributor maps field positions within formatted strings and produces an attributed character iterator


fmtAngle

protected Angle fmtAngle
Scratch Angle object for format methods

Constructor Detail

AngleFormat

public AngleFormat(Affix directionAffix,
                   AngleSignPair signPair,
                   AngleNorm norm,
                   AngleUnit units,
                   Mult mult)
Construct an AngleFormat object.

Parameters:
directionAffix - the directional affix setting.
signPair - the sign symbol convention identifier
norm - the normalization option.
units - the least significant units to use in formatting.
mult - the multiplier object that cooresponds to the desired maximum number of decimal digits.

AngleFormat

public AngleFormat(Affix directionAffix,
                   AngleSignPair signPair,
                   AngleNorm norm,
                   AngleUnit units,
                   Mult mult,
                   java.util.Locale locale)
Construct an AngleFormat object.

Parameters:
directionAffix - the directional affix setting.
signPair - the sign symbol convention identifier
norm - the normalization option.
units - the least significant units to use in formatting.
mult - the multiplier object that cooresponds to the desired maximum number of decimal digits.
locale - the locale for determining the symbols and separators used
Method Detail

getInstance

public static AngleFormat getInstance(AngleFormatStyle style)
Return an AngleFormat object configured to the requested style and the default locale

Parameters:
style - the AngleFormatStyle object
Returns:
the configured AngleFormat object

getInstance

public static AngleFormat getInstance(AngleFormatStyle style,
                                      java.util.Locale locale)
Return an AngleFormat object configured to the requested style and locale

Parameters:
style - the AngleFormatStyle object
locale - the locale
Returns:
the configured AngleFormat object

setSignPair

public void setSignPair(AngleSignPair signPair)
Set the angle sign convention to be used in formatting.

Parameters:
signPair - the AngleSignPair to use in formatting.

getSignPair

public AngleSignPair getSignPair()
Get the angle sign convention used in formatting.

Returns:
the AngleSignPair used in formatting.

setUsePositiveDirectionSymbol

public void setUsePositiveDirectionSymbol(boolean usePositive)
Set the flag indicating that if the sign of the angle is positive the positive symbol should be used in formatting.

Parameters:
usePositive - the flag

setSymbols

public void setSymbols(AngleFormatSymbols symbols)
Set the symbols object to be used in formatting.

Parameters:
symbols - the AngleFormatSymbols to use in formatting.

getSymbols

public AngleFormatSymbols getSymbols()
Get the symbols object used in formatting.

Returns:
the AngleFormatSymbols used in formatting.

setNormalizationOption

public void setNormalizationOption(AngleNorm norm)
Set the normalization option to be used in formatting. A value of null is interpreted as AngleNorm.NONE.

Parameters:
norm - the AngleNorm option to use in formatting.

getNormalizationOption

public AngleNorm getNormalizationOption()
Get the normalization option used in formatting.

Returns:
the normalization option

setAngleUnits

public void setAngleUnits(AngleUnit units)
Set the angle units to be used in formatting.

Parameters:
units - the AngleUnit to use in formatting.

getAngleUnits

public AngleUnit getAngleUnits()
Return the AngleUnit used in formatting.

Returns:
the AngleUnit used in formatting.

setDirectionAffix

public void setDirectionAffix(Affix directionAffix)
Set the directional affix setting.

Parameters:
directionAffix - the directional affix setting.

getDirectionAffix

public Affix getDirectionAffix()
Return the directional affix setting.

Returns:
the directional affix setting.

setZeroAngleSign

public void setZeroAngleSign(AngleSign zeroSign)
Set the AngleSign value to be used if the value of the angle is zero. A parameter of AngleSign.POSITIVE or AngleSign.NEGATIVE will cause the positive or negative directional affix (respectively) to be included in the formatted string on the condition that the value of the angle is zero. A parameter of null will cause the directional affix to be excluded from the formatted string.

Parameters:
zeroSign - the default for the sign of the angle if the value of the angle is zero.

getZeroAngleSign

public AngleSign getZeroAngleSign()
Return the AngleSign value being used if the value of the angle is zero. A null value indicates the directional affix is excluded from formatting on the condition that the value of the angle is zero.

Returns:
zeroSign the default sign of the angle if the value of the angle is zero.

setMaximumDecimalSize

public void setMaximumDecimalSize(Mult mult)
Set the maximum number of decimal fractional digits allowed.

Parameters:
mult - the Mult object that cooresponds to the desired maximum number of decimal digits. The Mult object must be either Mult.NONE or represent a decimal value or an IllegalArgumentException is thrown. If the maximum decimal size setting represents fewer decimal digits than the minimum setting, then the maximum decimal size is silently set to be equal to the minimum.

getMaximumDecimalSize

public Mult getMaximumDecimalSize()
Return the Mult object that cooresponds to the desired maximum number of decimal digits.

Returns:
the Mult object that cooresponds to the desired maximum number of decimal digits.

setMinimumDecimalSize

public void setMinimumDecimalSize(Mult mult)
Set the minimum number of decimal fractional digits allowed.

Parameters:
mult - the Mult object that cooresponds to the desired minimum number of decimal digits. The Mult object must be either Mult.NONE or represent a decimal value or an IllegalArgumentException is thrown. If the maximum decimal size setting represents fewer decimal digits than the minimum setting, then the maximum decimal size is silently set to be equal to the minimum.

getMinimumDecimalSize

public Mult getMinimumDecimalSize()
Return the Mult object that cooresponds to the desired minimum number of decimal digits.

Returns:
the Mult object that cooresponds to the desired minimum number of decimal digits.

setTruncateZeroFields

public void setTruncateZeroFields(boolean inValue)
Set the option to eliminate leading fields that have zero value.

Example: An angle value of 1 arc second will format into:

 1" when set true
 0°00'01" when set false
 

Parameters:
inValue - boolean true to eliminate leading zero fields, false to preserve leading zero fields. The default setting is false.

getTruncateZeroFields

public boolean getTruncateZeroFields()
Get the Truncate Zero Fields option setting.

Returns:
the boolean value of the option.

setTruncateZeroDecimals

public void setTruncateZeroDecimals(boolean inValue)
Set the option to eliminate trailing zero decimals.

Parameters:
inValue - boolean true to eliminate trailing zero decimals, false to preserve trailing zero decimals. The default setting is false.

getTruncateZeroDecimals

public boolean getTruncateZeroDecimals()
Get the Truncate Zero Decimals option setting.

Returns:
the boolean value of the option.

getFieldAttributor

public FieldAttributor getFieldAttributor()
Return the FieldAttributor

Returns:
the FieldAttributor.

format

public final java.lang.StringBuffer format(java.lang.Object obj,
                                           java.lang.StringBuffer result,
                                           java.text.FieldPosition pos)
Overrides Format. Format an Angle object into a human readable string.

Parameters:
obj - the object to format. Must be an Angle.
result - the string buffer in which to place the formatted string.
pos - an optional parameter for locating a specified field within the returned string buffer.
Returns:
the string buffer with the formatted string appended.
Throws:
java.lang.ClassCastException - if obj is not an Angle.
java.lang.NullPointerException - if obj is null.

format

public final java.lang.StringBuffer format(Angle angle,
                                           java.lang.StringBuffer result,
                                           java.text.FieldPosition pos)
Format an Angle object into a human readable string.

Parameters:
angle - the Angle object to format.
result - the string buffer in which to place the formatted string.
pos - an optional parameter for locating a specified field within the returned string buffer.
Returns:
the string buffer with the formatted string appended.
Throws:
java.lang.NullPointerException - if angle is null.

formatToCharacterIterator

public java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
Return the AttributedCharacterIterator describing the formatted value. The returned iterator will contain positioning attributes as enumerated in AngleFormat.FIELD.

Parameters:
obj - the object to format. Must be an Angle.
Returns:
the AttributedCharacterIterator describing the formatted value.
Throws:
java.lang.ClassCastException - if obj is not an Angle.
java.lang.NullPointerException - if obj is null.

format

public java.lang.String format(Angle angle)
Format an Angle object into a human readable String.

Parameters:
angle - the Angle object to format.
Returns:
the formatted string representing the Angle object.
Throws:
java.lang.NullPointerException - if angle is null.

processAffix

protected java.lang.String processAffix(AngleSign sign,
                                        boolean isZero)
Return the directional affix that matches the style and angle value

Parameters:
sign - the sign of the angle value
isZero - the flag to indicate that the angle value is 0
Returns:
the directional affix string

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition pos)
Not implemented. Returns null.

Overrides Format. Parse the passed String into an Angle object.

Parameters:
source - the string to parse.
pos - a ParsePosition object with index and error index information.
Returns:
the Angle object.

parse

public Angle parse(java.lang.String source)
            throws java.text.ParseException
Not implemented. Returns null.

Parse the passed String into an Angle object.

Parameters:
source - the string to parse.
Returns:
the Angle object.
Throws:
java.text.ParseException

clone

public java.lang.Object clone()
Return a copy of this AngleFormat object. Overrides Cloneable.

Returns:
a copy of this AngleFormat object.

hashCode

public int hashCode()
Return the hash code for the AngleFormat object

Returns:
the hash code

equals

public boolean equals(java.lang.Object obj)
Compare two AngleFormats for equality. The result is true if and only if the argument object is not null, is an AngleFormat object and represents an AngleFormat of the same type and style with the same formatting symbols.

Two AngleFormat objects are equal only when the format method will produce identical results with equal Angle objects as arguments.


Jeospace API

Copyright © 2006 - jeospace.org