public class Utilities
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_ID_REGEX
The pattern defining the conventional PIRL/HiROC class ID.
|
static java.lang.String |
ID
Class identification name with source code version and date.
|
static java.lang.String |
PASSWORD_MASK
The text used to mask a password from unintended display.
|
Modifier and Type | Method and Description |
---|---|
static int |
getBinningIndex(int binning)
Gets the index of the binning factor in the HiRISE binning factor list.
|
static int |
getCcdNameIndex(java.lang.String ccdName)
Gets the index of the CCD name in the HiRISE CCD name list.
|
static java.text.DateFormat |
getDatabaseDateFormat()
Gets the database date format.
|
static java.text.DateFormat |
getDoyFormat()
Gets the day-of-year format.
|
static java.lang.String |
getExceptionMessage(java.lang.Throwable t)
Gets the exception message of a
Throwable . |
static java.lang.String |
getExceptionMessage(java.lang.Throwable t,
boolean sanitizePasswords)
Gets the exception message of a
Throwable . |
static java.text.DateFormat |
getShortDoyFormat()
Gets the short day-of-year format.
|
static int |
getStatusIndex(java.lang.String status)
Gets the index of the status in the observation status list.
|
static int |
getTargetNameIndex(java.lang.String targetName)
Gets the index of the target name in the observation target names list.
|
static int |
getTdiIndex(int tdi)
Gets the index of the TDU length in the HiRISE TDI length list.
|
static boolean |
isBundleFilename(java.lang.String filename) |
static boolean |
isDlinkFilename(java.lang.String filename) |
static boolean |
isFormalId(java.lang.String id)
Determines whether a piece of text is a valid, formal observation ID.
|
static boolean |
isMac()
Determines whether the Java VM is running on a Macintosh computer.
|
static boolean |
isPtfFilename(java.lang.String filename) |
static boolean |
isSasfFilename(java.lang.String filename) |
static boolean |
isSatfFilename(java.lang.String filename) |
static boolean |
isStateFilename(java.lang.String filename) |
static boolean |
isValidBinning(int binning)
Tests if the given binning factor is a valid HiRISE binning factor.
|
static boolean |
isValidCcdName(java.lang.String ccdName)
Tests if the given CCD name is a valid HiRISE CCD name.
|
static boolean |
isValidStatus(java.lang.String status)
Tests if the given status is a valid HiRISE observation status.
|
static boolean |
isValidTargetName(java.lang.String targetName)
Tests if the given target name is a valid HiRISE observation target name.
|
static boolean |
isValidTdi(int tdi)
Tests if the given TDI length is a valid HiRISE TDI length.
|
static java.util.Date |
j2000()
Gets the J2000 epoch.
|
static <T> java.lang.String |
listToString(java.util.List<T> list)
Creates a nice, English-language string from the elements of a list.
|
static <T> java.lang.String |
listToString(java.util.List<T> list,
java.lang.String sep)
Creates a nice, English-language string from the elements of a list.
|
static <K extends java.lang.Comparable<? super K>,V> |
makeSortedKeyList(java.util.Map<? extends K,V> map) |
static void |
openUrl(java.lang.String url,
java.awt.datatransfer.ClipboardOwner clipboardOwner)
Attempts to open an HTTP URL in an external browser.
|
static void |
openUrl(java.net.URL url,
java.awt.datatransfer.ClipboardOwner clipboardOwner)
Attempts to open an HTTP URL in an external browser.
|
static java.util.Date |
parseDate(java.lang.String text)
Parses an input piece of text as a date.
|
static double |
planetocentric_latitude(double planetographic_latitude)
Convert Martian planetographic latitude to planetocentric latitude.
|
static double |
planetographic_latitude(double planetocentric_latitude)
Convert Martian planetocentric latitude to planetographic latitude.
|
static void |
printBlue(java.io.PrintStream s,
java.lang.String t)
Prints the indicated text to the indicated print stream formatted with a
blue color.
|
static void |
printBold(java.io.PrintStream s,
java.lang.String t)
Prints the indicated text to the indicated print stream formatted with a
bold, black color.
|
static void |
printGreen(java.io.PrintStream s,
java.lang.String t)
Prints the indicated text to the indicated print stream formatted with a
green color.
|
static void |
printOrange(java.io.PrintStream s,
java.lang.String t)
Prints the indicated text to the indicated print stream formatted with a
orange color.
|
static void |
printRed(java.io.PrintStream s,
java.lang.String t)
Prints the indicated text to the indicated print stream formatted with a red
color.
|
static void |
printUsage(java.io.PrintStream stream,
java.lang.String id,
java.lang.String usage,
java.lang.String... messages) |
static java.lang.String |
sanitizePasswords(java.lang.String text)
Replaces password values in the input text with a mask.
|
static void |
setBlue(java.io.PrintStream s)
Sets the indicated print stream to format text with a bold, blue color.
|
static void |
setBold(java.io.PrintStream s)
Sets the indicated print stream to format text with a bold, black color.
|
static void |
setGreen(java.io.PrintStream s)
Sets the indicated print stream to format text with a bold, green color.
|
static void |
setNormal(java.io.PrintStream s)
Sets the indicated print stream to format text with its normal style.
|
static void |
setOrange(java.io.PrintStream s)
Sets the indicated print stream to format text with a bold, orange color.
|
static void |
setRed(java.io.PrintStream s)
Sets the indicated print stream to format text with a bold, red color.
|
static java.lang.String[] |
split(java.lang.String text)
Splits a string into substrings using the comma as a delimiter.
|
static java.lang.String |
stripClassId(java.lang.String text)
Strips the initial class ID from the input text if present.
|
static boolean |
testBrowserLauncher()
Tests whether a browser launcher utility is available.
|
static boolean |
testLs(java.lang.Double min,
java.lang.Double max,
java.lang.Double val)
Tests a given Ls value to determine whether it falls within the given Ls
range.
|
static java.util.List<java.lang.String> |
trimQuotes(java.util.List<java.lang.String> list)
Trims matched leading and trailing quotes from each element of the input
list.
|
static java.lang.String |
trimQuotes(java.lang.String text)
Trims matched leading and trailing quotes from the input text.
|
static void |
updateMacKeyBindings()
Updates the key bindings for text components on a Mac when the Java or
Nimbus look and feel is in use.
|
public static final java.lang.String ID
public static final java.lang.String PASSWORD_MASK
public static final java.lang.String CLASS_ID_REGEX
public static boolean testBrowserLauncher()
public static void openUrl(java.net.URL url, java.awt.datatransfer.ClipboardOwner clipboardOwner)
url
- the URL.public static void openUrl(java.lang.String url, java.awt.datatransfer.ClipboardOwner clipboardOwner)
url
- the URL text.public static java.lang.String getExceptionMessage(java.lang.Throwable t, boolean sanitizePasswords)
Throwable
. The exception messages of
chained exceptions, if any, are appended to the message. This method acts
recursively through an exception chain.
If sanitizePasswords is true, the final exception message will be sanitized of exposed passwords where possible.
t
- the throwable from which to extract message text.sanitizePasswords
- if true, sanitizes the final message
of exposed passwords.public static java.lang.String getExceptionMessage(java.lang.Throwable t)
Throwable
. The exception messages of
chained exceptions, if any, are appended to the message. This method acts
recursively through an exception chain.
An effort is made to sanitize the final exception message of exposed passwords.
t
- the throwable from which to extract message text.public static java.lang.String sanitizePasswords(java.lang.String text)
text
- the input text to sanitize.PASSWORD_MASK
public static java.lang.String stripClassId(java.lang.String text)
Prepending exception messages with the class ID is a PIRL/HiROC convention designed to make bug tracing easier for the developer, but the ID itself can create a potentially muddled error message for the operator.
The convention's pattern is to start the exception message with the class ID
of the class from which the exception was thrown, followed by a newline
character. This method uses the CLASS_ID_REGEX
to find this
initial class ID.
text
- the input text to strip.public static boolean isValidCcdName(java.lang.String ccdName)
ccdName
- the test CCD name.Instrument.CCD_NAMES
public static int getCcdNameIndex(java.lang.String ccdName)
Since these names are organized by CPMM number, this index itself is the CPMM number.
ccdName
- the test CCD name.Instrument.CCD_NAMES
public static boolean isValidBinning(int binning)
binning
- the test binning factor.Instrument.BINNING_FACTORS
public static int getBinningIndex(int binning)
binning
- the test binning factor.Instrument.BINNING_FACTORS
public static boolean isValidTdi(int tdi)
tdi
- the test TDI length.Instrument.TDI_STAGES
public static int getTdiIndex(int tdi)
tdi
- the test TDI length.Instrument.TDI_STAGES
public static boolean isValidStatus(java.lang.String status)
status
- the test status.Observation_Fields.STATUSES
public static int getStatusIndex(java.lang.String status)
status
- the test status.Observation_Fields.STATUSES
public static boolean isValidTargetName(java.lang.String targetName)
targetName
- the test target name.Observation_Fields.TARGET_NAMES
public static int getTargetNameIndex(java.lang.String targetName)
targetName
- the test target name.Observation_Fields.TARGET_NAMES
public static double planetocentric_latitude(double planetographic_latitude)
planetographic_latitude
- the planetographic latitude.public static double planetographic_latitude(double planetocentric_latitude)
planetocentric_latitude
- the planetocentric latitude.public static java.util.Date parseDate(java.lang.String text)
getDoyFormat()
, the day-of-year format without the milliseconds, getDatabaseDateFormat()
, and DateFormat.getInstance()
, in that order.
The timezone is assumed to be UTC.
If the method cannot parse the text, a null is returned.
text
- the input text.Date
object or null if it cannot be
parsed.public static java.util.Date j2000()
public static java.text.DateFormat getDoyFormat()
j2000()
epoch in day-of-year format
is 2000-001T00:00:00.000.public static java.text.DateFormat getShortDoyFormat()
getDoyFormat()
by the omission of the milliseconds field. The j2000()
epoch in day-of-year format is 2000-001T00:00:00.public static java.text.DateFormat getDatabaseDateFormat()
j2000()
epoch in this format is
2000-01-01 12:00:00.public static boolean isFormalId(java.lang.String id)
There are two categories of HiRISE observation ID used in operations. The
first is the so-called "formal" ID. It is an ID that can be represented by
the Observation_ID
class. The second is the so-called "loose" ID,
which is any arbitrary piece of text used to identify an observation. In
practice, a loose ID is used when an observation's orbit is unknown, which
takes place in the early stages of planning.
id
- the observation ID; may be null.public static boolean isMac()
public static void updateMacKeyBindings()
This method updates the key binding map for text components such that the Mac command key works for Copy, Cut, Paste, and Select All shortcuts. If the Java VM is not running on a Mac, or if the Java or Nimbus look and feel is not in use, this method does nothing.
public static java.lang.String[] split(java.lang.String text)
text
- the text to split.public static <T> java.lang.String listToString(java.util.List<T> list, java.lang.String sep)
Object.toString()
method is called on each element of the list, and
the input sep sequence is used to separate elements of the list.
The list uses the Oxford comma (or semicolon or, more accurately,
sep, whatever sep is).
For a list containing no elements, an empty string is returned.
For a list containing a single element, that element is returned.
For a list of two elements, e0 and e1, the returned text is e0 and e1.
For a list of three or more elements, the returned text is of the form e0, e1, ..., and eN.
If sep is null, the empty string, or simply whitespace, no separator character will be used. The "and" will not appear before the final element. Thus, a list of two elements becomes e0 e1, and list of three or more elements becomes e0 e1 ... eN.
list
- a list of elements to be converted to a string.sep
- the separator to use; if null or an empty string or
simply whitespace, a single space will be used as the separator, and
"and" will not appear before the last element.public static <T> java.lang.String listToString(java.util.List<T> list)
Object.toString()
method is called on each element of the list, and
the list includes the Oxford comma.
For a list containing no elements, an empty string is returned.
For a list containing a single element, that element is returned.
For a list of two elements, e0 and e1, the returned text is e0 and e1.
For a list of three or more elements, the returned text is of the form e0, e1, ..., and eN.
list
- a list of elements to be converted to a string.listToString(List,String)
public static java.lang.String trimQuotes(java.lang.String text)
text
- the text to trim.public static java.util.List<java.lang.String> trimQuotes(java.util.List<java.lang.String> list)
list
- the list of text to trim.trimQuotes(String)
public static <K extends java.lang.Comparable<? super K>,V> java.util.List<K> makeSortedKeyList(java.util.Map<? extends K,V> map)
public static void setRed(java.io.PrintStream s)
Sequence: \e[1;31m
s
- the output print stream.public static void setOrange(java.io.PrintStream s)
Sequence: \e[1;33m
s
- the output print stream.public static void setGreen(java.io.PrintStream s)
Sequence: \e[1;32m
s
- the output print stream.public static void setBlue(java.io.PrintStream s)
Sequence: \e[1;34m
s
- the output print stream.public static void setBold(java.io.PrintStream s)
Sequence: \e[1;30m
public static void setNormal(java.io.PrintStream s)
Sequence: \e[0m
s
- the output print stream.public static void printRed(java.io.PrintStream s, java.lang.String t)
s
- the output print stream.t
- the text.setRed(PrintStream)
,
setNormal(PrintStream)
public static void printOrange(java.io.PrintStream s, java.lang.String t)
s
- the output print stream.t
- the text.setOrange(PrintStream)
,
setNormal(PrintStream)
public static void printGreen(java.io.PrintStream s, java.lang.String t)
s
- the output print stream.t
- the text.setGreen(PrintStream)
,
setNormal(PrintStream)
public static void printBlue(java.io.PrintStream s, java.lang.String t)
s
- the output print stream.t
- the text.setBlue(PrintStream)
,
setNormal(PrintStream)
public static void printBold(java.io.PrintStream s, java.lang.String t)
s
- the output print stream.t
- the text.setBold(PrintStream)
,
setNormal(PrintStream)
public static boolean isStateFilename(java.lang.String filename)
public static boolean isDlinkFilename(java.lang.String filename)
public static boolean isPtfFilename(java.lang.String filename)
public static boolean isSatfFilename(java.lang.String filename)
public static boolean isSasfFilename(java.lang.String filename)
public static boolean isBundleFilename(java.lang.String filename)
public static void printUsage(java.io.PrintStream stream, java.lang.String id, java.lang.String usage, java.lang.String... messages)
public static boolean testLs(java.lang.Double min, java.lang.Double max, java.lang.Double val)
min
- the minimum Ls value.max
- the maximum Ls value.val
- the Ls value to test.Copyright \ (C) Arizona Board of Regents on behalf of the \ Planetary Image Research Laboratory, Lunar and \ Planetary Laboratory at the University of Arizona