public class ASTAngle
extends java.lang.Object
This class is primarily used for determining whether a string has a valid angle. Methods provided include validation routines in which an angle can be expressed in DMS format (###d ##m ##.##s) or decimal format. When expressed in DMS format, the d, m, and s values are optional as long as one is provided. They must be given in the correct order (i.e., 5m 30d is invalid because degrees must be specified before minutes). The angle object maintains the object's value in both DMS and decimal format so that either format can be readily obtained directly from the object.
Note that to handle situations where the angle is negative but the integer degrees is 0 (e.g., -0d 13m 14.45s), the bNeg field is used to indicate whether the DMS format of the value is negative. The decimal value of the angle will be negative or positive as required and kept in synch with the bNeg field. Also note that due to roundoff errors, it is possible that minutes and seconds can exceed the value 60.
Copyright (c) 2018
Constructor and Description |
---|
ASTAngle()
Class constructor for creating an angle object.
|
ASTAngle(double decValue)
Class constructor for creating an angle object.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
angleToStr(ASTAngle angleObj,
boolean formatFlag)
Convert an angle object to DMS or decimal string format
depending upon the formatFlag.
|
static java.lang.String |
angleToStr(boolean neg,
int d,
int m,
double s,
boolean formatFlag)
Convert an angle object to DMS or decimal string format
depending upon the formatFlag.
|
static java.lang.String |
angleToStr(double angle,
boolean formatFlag)
Convert an angle object to DMS or decimal string format
depending upon the formatFlag.
|
static ASTAngle |
DecToDMS(double decValue)
Convert a decimal angle to DMS format
|
static double |
DMStoDec(boolean neg,
int d,
int m,
double s)
Convert individual DMS values to a decimal value.
|
double |
getDecAngle()
Gets the decimal value of the angle
|
int |
getDegrees()
Gets the 'degrees' portion of the angle
|
int |
getMinutes()
Gets the 'minutes' portion of the angle
|
double |
getSeconds()
Gets the 'seconds' portion of the angle
|
boolean |
isNegAngle()
Determines whether the angle is negative.
|
static ASTAngle |
isValidAngle(java.lang.String inputStr)
Validate a string that may be in either DMS or decimal
format.
|
static ASTAngle |
isValidAngle(java.lang.String inputStr,
boolean flag)
Validate a string that may be in either DMS or decimal
format.
|
boolean |
isValidAngleObj()
Returns whether the object is a valid angle.
|
static ASTAngle |
isValidDecAngle(java.lang.String inputStr)
Validate that a string contains a valid decimal format value
Don't display any error messages unless flag is SHOW_ERRORS.
|
static ASTAngle |
isValidDecAngle(java.lang.String inputStr,
boolean flag)
Validate that a string contains a valid decimal format value
Don't display any error messages unless flag is SHOW_ERRORS.
|
static ASTAngle |
isValidDMSAngle(java.lang.String inputStr)
Validate that a string contains a valid DMS format value.
|
static ASTAngle |
isValidDMSAngle(java.lang.String inputStr,
boolean flag)
Validate that a string contains a valid DMS format value.
|
void |
setDecAngle(double decValue)
Define 'set' accessors for the object's fields.
|
public ASTAngle()
Since much of the usage of this class involves validating that a string has a valid angle, assume a new object is invalid until it is proven otherwise.
This method is overloaded to allow passing in an initial value or taking only the defaults.
public ASTAngle(double decValue)
Since much of the usage of this class involves validating that a string has a valid angle, assume a new object is invalid until it is proven otherwise.
This method is overloaded to allow passing in an initial value or taking only the defaults.
decValue
- angle value to give the objectpublic boolean isValidAngleObj()
public double getDecAngle()
public boolean isNegAngle()
This is needed because an angle such as -0d 15m 30s is valid, but some variable is required to indicate that the value is negative.
public int getDegrees()
public int getMinutes()
public double getSeconds()
public void setDecAngle(double decValue)
decValue
- value to assign to the objectpublic static ASTAngle isValidAngle(java.lang.String inputStr)
This method is overloaded to make the flag input parameter optional. The default is to show error messages.
inputStr
- string to be validatedpublic static ASTAngle isValidAngle(java.lang.String inputStr, boolean flag)
This method is overloaded to make the flag input parameter optional. The default is to show error messages.
inputStr
- string to be validatedflag
- flag indicating whether to display error messagepublic static ASTAngle isValidDecAngle(java.lang.String inputStr)
This method is overloaded to allow the flag input parameter to be optional. The default is to show errors.
inputStr
- string to be validatedpublic static ASTAngle isValidDecAngle(java.lang.String inputStr, boolean flag)
This method is overloaded to allow the flag input parameter to be optional. The default is to show errors.
inputStr
- string to be validatedflag
- whether to display error messagespublic static ASTAngle isValidDMSAngle(java.lang.String inputStr)
This method is overloaded to allow the flag input parameter to be optional. The default is to show errors.
inputStr
- string to be validatedpublic static ASTAngle isValidDMSAngle(java.lang.String inputStr, boolean flag)
This method is overloaded to allow the flag input parameter to be optional. The default is to show errors.
inputStr
- string to be validatedflag
- whether to display error messagespublic static java.lang.String angleToStr(ASTAngle angleObj, boolean formatFlag)
This method is overloaded to allow flexibility in how the angle is passed: as an object, as a decimal value, or by neg, d, m, s.
angleObj
- angle object to be convertedformatFlag
- either DMSFORMAT or DECFORMATpublic static java.lang.String angleToStr(double angle, boolean formatFlag)
This method is overloaded to allow flexibility in how the angle is passed: as an object, as a decimal value, or by neg, d, m, s.
angle
- angle as a decimal valueformatFlag
- either DMSFORMAT or DECFORMATpublic static java.lang.String angleToStr(boolean neg, int d, int m, double s, boolean formatFlag)
This method is overloaded to allow flexibility in how the angle is passed: as an object, as a decimal value, or by neg, d, m, s.
neg
- true if angle is negatived
- degreesm
- minutess
- secondsformatFlag
- either DMSFORMAT or DECFORMATpublic static ASTAngle DecToDMS(double decValue)
decValue
- decimal angle to be convertedpublic static double DMStoDec(boolean neg, int d, int m, double s)
The neg flag is required because the integer degrees could be 0 and we may want -0d angles.
neg
- true if the angle is negatived
- degreesm
- minutess
- seconds