com.isti.quakewatch.util
Class QWUtils

java.lang.Object
  extended by com.isti.quakewatch.util.QWUtils

public class QWUtils
extends java.lang.Object

Class QWUtils contains a collection of static utility fields and methods for QuakeWatch.


Nested Class Summary
static class QWUtils.ElemAndMsgFmtSpec
          Class ElemAndMsgFmtSpec holds an element object and a message-format specifier (one of the 'QWIdentDataMsgRecord.MFMT_...' values).
 
Field Summary
static float FLOAT_ZERO_VAL
          Floating-point value below which is "nearly" zero.
static java.util.TimeZone gmtTimeZone
          Timezone object set to "GMT".
static double KM_TO_MILE
          Constant for converting kilometers to miles.
static double MILE_TO_KM
          Constant for converting miles to kilometers.
static java.lang.String SPACE_STR
          Single-space string.
static java.lang.String xmlDateFormat2String
          Alternate date format string for parsing (no trailing 'Z').
static java.lang.String xmlDateFormatString
          Date format string for parsing and formatting date/time values.
 
Method Summary
static java.lang.String convertFloatToString(double number, int numDigits)
          Formats an number to produce a string.
static java.lang.String convertFloatToString(double number, int minDigits, int maxDigits)
          Formats an number to produce a string.
static QWUtils.ElemAndMsgFmtSpec determineMessageFormat(org.jdom.Element dataMsgElemObj)
          Determines the format of the given message element and returns the lead element for the message.
static java.lang.String getDegMinStr(double value)
          Returns a string showing the given value in degrees and minutes.
static java.lang.String getDegMinStr(double value, java.lang.String degStr, java.lang.String minStr)
          Returns a string showing the given value in degrees and minutes.
static java.lang.String getMagnitudeDescStr(double magVal)
          Returns a descriptive string for the given magnitude.
static java.lang.String getTextForSignature(org.jdom.Element qwMsgElement)
          Returns the text to be used for a signature.
static java.text.DateFormat getXmlDateFormatter2Obj()
          Creates and returns a new date-formatter object that may be used to parse and format XML-date/time strings.
static java.text.DateFormat getXmlDateFormatterObj()
          Creates and returns a new date-formatter object that may be used to parse and format XML-date/time strings.
static boolean isNearlyEqual(float val1, float val2)
          Compares two floating-point values for near equality.
static EvtChEventType[] listStringToEventTypeArray(java.lang.String listStr)
          Converts the given list string of event domain and type names to an array of event-type objects.
static EvtChEventType[] listStringToEventTypeArray(java.lang.String listStr, java.lang.String extraDomainStr, java.lang.String extraTypeStr)
          Converts the given list string of event domain and type names to an array of event-type objects.
static TwoObjectMatcher listStringToMatcher(java.lang.String listStr)
          Converts the given list string of event domain and type names to a matcher object that may be used to match pairs of domain and type names against those in the list.
static java.util.Properties loadPropsFromFile(java.lang.String fileNameStr)
          Loads a set of properties from a file.
static java.lang.String magTypeCharToStr(char magCh)
          Translates the given magnitude-type character to a descriptive 1-3 character string.
static java.lang.String magTypeCharToStr(java.lang.String magCharStr)
          Translates the given magnitude-type character to a descriptive 1-3 character string.
static java.lang.Double parseStringDouble(java.lang.String str)
          Parses the given string into a floating-point number.
static java.lang.Integer parseStringInteger(java.lang.String str)
          Parses the given string into an integer number.
static java.lang.Long parseStringLong(java.lang.String str)
          Parses the given string into an long integer number.
static java.util.Date parseStringXmlDate(java.lang.String str)
          Parses the given string as an XML date string.
static java.lang.String typeArraytoListString(EvtChEventType[] list)
          Takes an array of EvtChEventType objects and returns a string of the array in list format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlDateFormatString

public static final java.lang.String xmlDateFormatString
Date format string for parsing and formatting date/time values.

See Also:
Constant Field Values

xmlDateFormat2String

public static final java.lang.String xmlDateFormat2String
Alternate date format string for parsing (no trailing 'Z').

See Also:
Constant Field Values

gmtTimeZone

public static final java.util.TimeZone gmtTimeZone
Timezone object set to "GMT".


KM_TO_MILE

public static final double KM_TO_MILE
Constant for converting kilometers to miles.

See Also:
Constant Field Values

MILE_TO_KM

public static final double MILE_TO_KM
Constant for converting miles to kilometers.

See Also:
Constant Field Values

FLOAT_ZERO_VAL

public static final float FLOAT_ZERO_VAL
Floating-point value below which is "nearly" zero.

See Also:
Constant Field Values

SPACE_STR

public static final java.lang.String SPACE_STR
Single-space string.

See Also:
Constant Field Values
Method Detail

loadPropsFromFile

public static java.util.Properties loadPropsFromFile(java.lang.String fileNameStr)
                                              throws java.io.FileNotFoundException,
                                                     java.io.IOException
Loads a set of properties from a file.

Parameters:
fileNameStr - the name of the input file.
Returns:
A new 'Properties' object containing the properties loaded from the file.
Throws:
java.io.FileNotFoundException - if the given file was not found.
java.io.IOException - if an error occurs while reading from the file.

getTextForSignature

public static java.lang.String getTextForSignature(org.jdom.Element qwMsgElement)
Returns the text to be used for a signature.

Parameters:
qwMsgElement - "QWmessage" element containing the message.
Returns:
the text to be used for a signature.

getXmlDateFormatterObj

public static java.text.DateFormat getXmlDateFormatterObj()
Creates and returns a new date-formatter object that may be used to parse and format XML-date/time strings. The format string is "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'".

Returns:
A new 'DateFormat' object.

getXmlDateFormatter2Obj

public static java.text.DateFormat getXmlDateFormatter2Obj()
Creates and returns a new date-formatter object that may be used to parse and format XML-date/time strings. The format string is "yyyy-MM-dd'T'HH:mm:ss.SSS" (no trailing 'Z').

Returns:
A new 'DateFormat' object.

parseStringDouble

public static java.lang.Double parseStringDouble(java.lang.String str)
Parses the given string into a floating-point number. The numeric string may have a leading '+' or '-' sign and will have leading and trailing whitespace trimmed before being parsed.

Parameters:
str - numeric string to parse.
Returns:
A 'Double' object containing the parsed value, or null if the value could not be parsed.

parseStringInteger

public static java.lang.Integer parseStringInteger(java.lang.String str)
Parses the given string into an integer number. The numeric string may have a leading '+' or '-' sign and will have leading and trailing whitespace trimmed before being parsed.

Parameters:
str - numeric string to parse.
Returns:
A 'Integer' object containing the parsed value, or null if the value could not be parsed.

parseStringLong

public static java.lang.Long parseStringLong(java.lang.String str)
Parses the given string into an long integer number. The numeric string may have a leading '+' or '-' sign and will have leading and trailing whitespace trimmed before being parsed.

Parameters:
str - numeric string to parse.
Returns:
A 'Long' object containing the parsed value, or null if the value could not be parsed.

parseStringXmlDate

public static java.util.Date parseStringXmlDate(java.lang.String str)
Parses the given string as an XML date string. This method is thread safe.

Parameters:
str - the date string to parse.
Returns:
A new 'Date' object, or null if the string could not be parsed as an XML date string.

convertFloatToString

public static java.lang.String convertFloatToString(double number,
                                                    int numDigits)
Formats an number to produce a string.

Parameters:
number - The number to format.
numDigits - the minimum and maximum number of fraction digits to be shown.
Returns:
Formatted string.

convertFloatToString

public static java.lang.String convertFloatToString(double number,
                                                    int minDigits,
                                                    int maxDigits)
Formats an number to produce a string.

Parameters:
number - The number to format.
minDigits - the minimum number of fraction digits to be shown.
maxDigits - the maximum number of fraction digits to be shown.
Returns:
Formatted string.

isNearlyEqual

public static boolean isNearlyEqual(float val1,
                                    float val2)
Compares two floating-point values for near equality.

Parameters:
val1 - first value.
val2 - second value.
Returns:
true if nearly equal, false if not.

listStringToEventTypeArray

public static EvtChEventType[] listStringToEventTypeArray(java.lang.String listStr,
                                                          java.lang.String extraDomainStr,
                                                          java.lang.String extraTypeStr)
Converts the given list string of event domain and type names to an array of event-type objects. The list string must be in the format "domain:type,domain:type...". Occurrences of the ':' and ',' characters not meant as separators may be "quoted" by preceding them with the backslash ('\') character. List items missing the ':' character will be considered to specify only a domain name (the type name will be an empty string).

Parameters:
listStr - the list string to use.
extraDomainStr - extra domain-name string to be appended to list (if given), or null for none.
extraTypeStr - extra type-name string to be appended to list (if given), or null for none.
Returns:
A new 'EvtChEventType' array, or null if no domain/type names were found in the list string.

listStringToEventTypeArray

public static EvtChEventType[] listStringToEventTypeArray(java.lang.String listStr)
Converts the given list string of event domain and type names to an array of event-type objects. The list string must be in the format "domain:type,domain:type...". Occurrences of the ':' and ',' characters not meant as separators may be "quoted" by preceding them with the backslash ('\') character. List items missing the ':' character will be considered to specify only a domain name (the type name will be an empty string).

Parameters:
listStr - the list string to use.
Returns:
A new 'EvtChEventType' array, or null if no domain/type names were found in the list string.

typeArraytoListString

public static java.lang.String typeArraytoListString(EvtChEventType[] list)
Takes an array of EvtChEventType objects and returns a string of the array in list format. The list string will be in the format "domain:type,domain:type...". Occurrences of the ':' and ',' characters not meant as separators may be "quoted" by preceding them with the backslash ('\') character. List items missing the ':' character will be considered to specify only a domain name (the type name will be an empty string).

Parameters:
list - the EvtChEventType list.
Returns:
The string for archiving.

listStringToMatcher

public static TwoObjectMatcher listStringToMatcher(java.lang.String listStr)
Converts the given list string of event domain and type names to a matcher object that may be used to match pairs of domain and type names against those in the list. The list string must be in the format "domain:type,domain:type...". Occurrences of the ':' and ',' characters not meant as separators may be "quoted" by preceding them with the backslash ('\') character. List items missing the ':' character will be considered to specify only a domain name (the type name will be an empty string).

Parameters:
listStr - the list string to use.
Returns:
A new 'TwoObjectMatcher' built from the list string items, or null if no domain/type names were found in the list string.

getDegMinStr

public static java.lang.String getDegMinStr(double value,
                                            java.lang.String degStr,
                                            java.lang.String minStr)
Returns a string showing the given value in degrees and minutes.

Parameters:
value - the value to use.
degStr - the tag string to use for the degrees value.
minStr - the tag string to use for the minutes value.
Returns:
The degrees/minutes string.

getDegMinStr

public static java.lang.String getDegMinStr(double value)
Returns a string showing the given value in degrees and minutes. The tags "deg" and "min" are used.

Parameters:
value - the value to use.
Returns:
The degrees/minutes string.

getMagnitudeDescStr

public static java.lang.String getMagnitudeDescStr(double magVal)
Returns a descriptive string for the given magnitude.

Parameters:
magVal - the magnitude value to use.
Returns:
A descriptive string for the given magnitude, in the form " (A xxx quake)".

magTypeCharToStr

public static java.lang.String magTypeCharToStr(char magCh)
Translates the given magnitude-type character to a descriptive 1-3 character string. The following characters are expected:
     B = body magnitude (Mb)
     C = duration magnitude (Md)
     D = duration magnitude (Md)
     E = energy magnitude (Me)
     G = local magnitude (Ml)
     I = "Tsuboi" moment magnitude (Mi)
     L = local magnitude (Ml)
     N = "Nuttli" surface wave magnitude (MbLg)
     O = moment magnitude (Mw)
     P = body magnitude (Mb)
     S = surface wave magnitude (Ms)
     T = teleseismic moment magnitude (Mt)
     W = regional moment magnitude (Mw)
 

Parameters:
magCh - the magnitude-character to use.
Returns:
A 1-3 character magnitude-type string, or an empty string if the magnitude type is not recognized.

magTypeCharToStr

public static java.lang.String magTypeCharToStr(java.lang.String magCharStr)
Translates the given magnitude-type character to a descriptive 1-3 character string. The following characters are expected:
     B = body magnitude (Mb)
     C = duration magnitude (Md)
     D = duration magnitude (Md)
     E = energy magnitude (Me)
     G = local magnitude (Ml)
     I = "Tsuboi" moment magnitude (Mi)
     L = local magnitude (Ml)
     N = "Nuttli" surface wave magnitude (MbLg)
     O = moment magnitude (Mw)
     P = body magnitude (Mb)
     S = surface wave magnitude (Ms)
     T = teleseismic moment magnitude (Mt)
     W = regional moment magnitude (Mw)
 

Parameters:
magCharStr - a string containing the magnitude-character to use.
Returns:
A 1-3 character magnitude-type string, or an empty string if the magnitude type is not recognized.

determineMessageFormat

public static QWUtils.ElemAndMsgFmtSpec determineMessageFormat(org.jdom.Element dataMsgElemObj)
Determines the format of the given message element and returns the lead element for the message.

Parameters:
dataMsgElemObj - 'DataMessage' element for message.
Returns:
A new 'ElemAndMsgFmtSpec' object containing the lead element and the message-format specifier (one of the 'QWIdentDataMsgRecord.MFMT_...' values).