com.isti.quakewatch.util
Class CubeMsgGenerator

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

public class CubeMsgGenerator
extends java.lang.Object

Class CubeMsgGenerator generates CUBE-format text messages from QuakeWatch message-record objects.


Field Summary
protected  java.text.DateFormat cubeDateFormatterObj
           
protected static java.lang.String DEF_LOCMETHOD_STR
           
protected static java.lang.String NEG_OVERFLOW_STR
           
protected static java.lang.String POS_OVERFLOW_STR
           
protected  java.lang.String prependDeclarationString
           
protected static java.lang.String SPACE_STR
           
 
Constructor Summary
CubeMsgGenerator()
           
 
Method Summary
static java.lang.String calcAppendCheckChar(java.lang.String str)
          Calculates the Menlo Park check char and appends it to the given string.
static char calcMenloCheckChar(java.lang.String str)
          Calculates and returns the "Menlo Park(USGS) check char (Nov.94)" code for the given String (excess 36 modulo 91).
 java.lang.String createMessage(QWMsgRecord recObj, boolean acceptXmlMsgsFlag, boolean acceptNonActualFlag)
          Creates a CUBE-format text message from the given message-record object.
static java.lang.String doubleToCubeStr(double val, double multiplier, int outLen)
          Converts the given value to a CUBE-format numeric string.
static java.lang.String doubleToCubeStr(java.lang.Double valObj, double multiplier, int outLen)
          Converts the given value to a CUBE-format numeric string.
static java.lang.String doubleToCubeStr(double val, int multiplier, int outLen, boolean addZerosFlag, boolean showPosFlag)
          Converts the given value to a CUBE-format numeric string.
static java.lang.String doubleToCubeStr(java.lang.Double valObj, int multiplier, int outLen, boolean addZerosFlag, boolean showPosFlag)
          Converts the given value to a CUBE-format numeric string.
 java.lang.String getPrependDeclarationString()
          Returns the string to be prepended when XML-format messages are generated.
static java.lang.String intToCubeStr(java.lang.Integer valObj, int outLen)
          Converts the given value to a CUBE-format numeric string.
static java.lang.String intToCubeStr(java.lang.Integer valObj, int outLen, java.lang.String noValStr)
          Converts the given value to a CUBE-format numeric string.
static java.lang.String nonNullStr(java.lang.String str)
          If the given string is null then returns an empty string, otherwise returns the given string.
 void setPrependDeclarationString(java.lang.String pDeclStr)
          Sets the string to be prepended when XML-format messages are generated.
static java.lang.String translateLocMethod(QWEQEventMsgRecord recObj)
          Translates the given message-record's location-method string to a CUBE-format code.
static java.lang.String translateMagType(QWEQEventMsgRecord recObj)
          Translates the given message-record's magnitude-type string to a CUBE-format code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPACE_STR

protected static final java.lang.String SPACE_STR
See Also:
Constant Field Values

cubeDateFormatterObj

protected final java.text.DateFormat cubeDateFormatterObj

POS_OVERFLOW_STR

protected static final java.lang.String POS_OVERFLOW_STR
See Also:
Constant Field Values

NEG_OVERFLOW_STR

protected static final java.lang.String NEG_OVERFLOW_STR
See Also:
Constant Field Values

DEF_LOCMETHOD_STR

protected static final java.lang.String DEF_LOCMETHOD_STR
See Also:
Constant Field Values

prependDeclarationString

protected java.lang.String prependDeclarationString
Constructor Detail

CubeMsgGenerator

public CubeMsgGenerator()
Method Detail

setPrependDeclarationString

public void setPrependDeclarationString(java.lang.String pDeclStr)
Sets the string to be prepended when XML-format messages are generated. This only applies to non-standard/invalid XML messages that may be outputted when the 'acceptXmlMsgFlag' parameter to the 'createMessage()' method is set to 'true'.

Parameters:
pDeclStr - string to be prepended, or null or an emptry string for none.

getPrependDeclarationString

public java.lang.String getPrependDeclarationString()
Returns the string to be prepended when XML-format messages are generated. This only applies to non-standard/invalid XML messages that may be outputted when the 'acceptXmlMsgFlag' parameter to the 'createMessage()' method is set to 'true'.

Returns:
The string to be prepended, or null for none.

createMessage

public java.lang.String createMessage(QWMsgRecord recObj,
                                      boolean acceptXmlMsgsFlag,
                                      boolean acceptNonActualFlag)
Creates a CUBE-format text message from the given message-record object.

Parameters:
recObj - message-record object to use.
acceptXmlMsgsFlag - true to accept non-standard/invalid messages and return the XML-message text.
acceptNonActualFlag - true to accept messages with Event|Usage set to non-Actual value.
Returns:
A new CUBE-format text message string, an empty string if 'acceptNonActualFlag'==false and the message contained an Event|Usage element with a value other than "Actual", or null if a message string could not be created.

doubleToCubeStr

public static java.lang.String doubleToCubeStr(double val,
                                               int multiplier,
                                               int outLen,
                                               boolean addZerosFlag,
                                               boolean showPosFlag)
Converts the given value to a CUBE-format numeric string.

Parameters:
val - value to convert.
multiplier - power-of-ten multiplier to apply to value.
outLen - desired length of output string.
addZerosFlag - true to add leading zero(s) to make string look like original floating-point value without the decimal point.
showPosFlag - true to show leading plus sign ('+') if positive value.
Returns:
Numeric-string representation of value.

doubleToCubeStr

public static java.lang.String doubleToCubeStr(java.lang.Double valObj,
                                               int multiplier,
                                               int outLen,
                                               boolean addZerosFlag,
                                               boolean showPosFlag)
Converts the given value to a CUBE-format numeric string.

Parameters:
valObj - value object to convert, or null if none.
multiplier - power-of-ten multiplier to apply to value.
outLen - desired length of output string.
addZerosFlag - true to add leading zero(s) to make string look like original floating-point value without the decimal point.
showPosFlag - true to show leading plus sign ('+') if positive value.
Returns:
Numeric-string representation of value, or a string containing all spaces if no value given.

doubleToCubeStr

public static java.lang.String doubleToCubeStr(double val,
                                               double multiplier,
                                               int outLen)
Converts the given value to a CUBE-format numeric string.

Parameters:
val - value to convert.
multiplier - multiplier to apply to value.
outLen - desired length of output string.
Returns:
Numeric-string representation of value.

doubleToCubeStr

public static java.lang.String doubleToCubeStr(java.lang.Double valObj,
                                               double multiplier,
                                               int outLen)
Converts the given value to a CUBE-format numeric string.

Parameters:
valObj - value object to convert, or null if none.
multiplier - multiplier to apply to value.
outLen - desired length of output string.
Returns:
Numeric-string representation of value, or a string containing all spaces if no value given.

intToCubeStr

public static java.lang.String intToCubeStr(java.lang.Integer valObj,
                                            int outLen,
                                            java.lang.String noValStr)
Converts the given value to a CUBE-format numeric string.

Parameters:
valObj - value object to convert, or null if none.
outLen - desired length of output string.
noValStr - string to return if no value was given, or null for none.
Returns:
Numeric-string representation of value, or a string containing all spaces (or 'noValStr') if no value given.

intToCubeStr

public static java.lang.String intToCubeStr(java.lang.Integer valObj,
                                            int outLen)
Converts the given value to a CUBE-format numeric string.

Parameters:
valObj - value object to convert, or null if none.
outLen - desired length of output string.
Returns:
Numeric-string representation of value, or a string containing all spaces if no value given.

translateMagType

public static java.lang.String translateMagType(QWEQEventMsgRecord recObj)
Translates the given message-record's magnitude-type string to a CUBE-format code.

Parameters:
recObj - event record containing magnitude-type string to use.
Returns:
The single-character CUBE-format magnitude-type string, or a string containing a single space if none.

translateLocMethod

public static java.lang.String translateLocMethod(QWEQEventMsgRecord recObj)
Translates the given message-record's location-method string to a CUBE-format code.

Parameters:
recObj - event record containing location-method string to use.
Returns:
The single-character CUBE-format location-method-code string, or a string containing a the default character ('U') if none.

calcAppendCheckChar

public static java.lang.String calcAppendCheckChar(java.lang.String str)
Calculates the Menlo Park check char and appends it to the given string.

Parameters:
str - string to use.
Returns:
The given string with the Menlo Park check char apppended to the end.

calcMenloCheckChar

public static char calcMenloCheckChar(java.lang.String str)
Calculates and returns the "Menlo Park(USGS) check char (Nov.94)" code for the given String (excess 36 modulo 91).

Parameters:
str - the string to use.
Returns:
the check character.

nonNullStr

public static java.lang.String nonNullStr(java.lang.String str)
If the given string is null then returns an empty string, otherwise returns the given string.

Parameters:
str - given string.
Returns:
The given string, or an empty string if the given string is null.