public abstract class Base extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Base.LoggingWriter
Inner class for over-riding the destination of log(), out() and err()
calls.
|
static class |
Base.StackFrame
A class that provides "stack frame" information from a line of a stack
trace.
|
Modifier and Type | Field and Description |
---|---|
static int |
LOG_ALWAYS
It is expected that items with a log level of 0 will always be logged.
|
static int |
LOG_DEBUG
As of Coherence 3.2, the default logging level is 5, so using the level
of 5 will show up in the logs by default as a debug message.
|
static int |
LOG_ERR
Log level 1 indicates an error.
|
static int |
LOG_INFO
Log level 3 indicates information that should likely be logged.
|
static int |
LOG_MAX
The maximum logging level indicator.
|
static int |
LOG_MIN
The minimum logging level indicator.
|
static int |
LOG_QUIET
As of Coherence 3.2, the default logging level is 5, so using a level
higher than 5 will be "quiet" by default, meaning that it will not show
up in the logs unless the configured logging level is increased.
|
static int |
LOG_WARN
Log level 2 indicates a warning.
|
static int |
POWER_0
Integer constant representing an exponent of zero.
|
static int |
POWER_G
Integer constant representing an exponent of 30.
|
static int |
POWER_K
Integer constant representing an exponent of 10.
|
static int |
POWER_M
Integer constant representing an exponent of 20.
|
static int |
POWER_T
Integer constant representing an exponent of 40.
|
static int |
UNIT_D
Integer constant representing a unit of days.
|
static int |
UNIT_H
Integer constant representing a unit of hours.
|
static int |
UNIT_M
Integer constant representing a unit of minutes.
|
static int |
UNIT_MS
Integer constant representing a unit of milliseconds.
|
static int |
UNIT_NS
Integer constant representing a unit of nanoseconds.
|
static int |
UNIT_S
Integer constant representing a unit of seconds.
|
static int |
UNIT_US
Integer constant representing a unit of microseconds.
|
Constructor and Description |
---|
Base() |
Modifier and Type | Method and Description |
---|---|
static RuntimeException |
azzert()
Definite assertion failure.
|
static void |
azzert(boolean f)
Test an assertion.
|
static void |
azzert(boolean f,
String s)
Test an assertion, and print the specified message if the assertion
fails.
|
static void |
azzertFailed(String sMsg)
Throw an assertion exception.
|
static String |
breakLines(String sText,
int nWidth,
String sIndent)
Breaks the specified string into a multi-line string.
|
static String |
breakLines(String sText,
int nWidth,
String sIndent,
boolean fFirstLine)
Breaks the specified string into a multi-line string.
|
static String |
capitalize(String s)
Capitalize a string.
|
static void |
checkNotEmpty(String s,
String sName)
Check that the specified string is neither a null nor an empty string.
|
static <T> T |
checkNotNull(T o,
String sName)
Check that the specified object is non-null and return it.
|
static void |
checkRange(long lValue,
long lFrom,
long lTo,
String sName)
Check the range of a value.
|
static long |
computeSafeWaitTime(long ldtTimeout)
compute the number of milliseconds until the specified time.
|
static int |
decimalValue(char ch)
Returns the integer value of a decimal digit.
|
static String |
dup(char ch,
int cch)
Create a String of the specified length containing the specified
character.
|
static String |
dup(String s,
int c)
Create a String which is a duplicate of the specified number of the
passed String.
|
static BigDecimal |
ensureBigDecimal(Number num)
Ensure the specified Number is a BigDecimal value or convert it into a
new BigDecimal object.
|
static ClassLoader |
ensureClassLoader(ClassLoader loader)
Obtain a non-null ClassLoader.
|
static RuntimeException |
ensureRuntimeException(Throwable e)
Convert the passed exception to a RuntimeException if necessary.
|
static RuntimeException |
ensureRuntimeException(Throwable e,
String s)
Convert the passed exception to a RuntimeException if necessary.
|
static boolean |
equals(Object o1,
Object o2)
Compare two references for equality.
|
static boolean |
equalsDeep(Object o1,
Object o2)
Deeply compare two references for equality.
|
static void |
err()
Prints a blank line to the trace Writer.
|
static void |
err(Class clz)
Prints the passed class information to the trace Writer.
|
static void |
err(Object o)
Prints the passed Object to the trace Writer.
|
static void |
err(String s)
Prints the passed String value to the trace Writer.
|
static void |
err(Throwable e)
Prints the passed exception information to the trace Writer.
|
static int |
escape(char ch,
char[] ach,
int of)
Format a char to a printable escape if necessary, putting the result
into the passed array.
|
static String |
formatDateTime(long ldt)
Format a long value into a human readable date/time string.
|
static Base.StackFrame |
getCallerStackFrame()
Get the StackFrame information for the caller of the current method.
|
static com.oracle.coherence.common.util.CommonMonitor |
getCommonMonitor(int i)
Return the common monitor associated with the specified integer value.
|
static com.oracle.coherence.common.util.CommonMonitor |
getCommonMonitor(long l)
Return the common monitor associated with the specified long value.
|
static com.oracle.coherence.common.util.CommonMonitor |
getCommonMonitor(Object o)
Return the common monitor associated with the specified object based on
its identity hashCode.
|
static ClassLoader |
getContextClassLoader()
Try to determine the ClassLoader that supports the current context.
|
static ClassLoader |
getContextClassLoader(Object o)
Try to determine the ClassLoader that supports the current context.
|
static String |
getDeepMessage(Throwable t,
String sDelim)
Extract a throwable's message, and all causal messages.
|
static PrintWriter |
getErr()
Obtains the current writer used for tracing.
|
static long |
getLastSafeTimeMillis()
Returns the last "safe" time as computed by a previous call to
the
getSafeTimeMillis() method. |
static PrintWriter |
getLog()
Obtains the current writer used for logging.
|
static int |
getMaxDecDigits(int n)
Calculate the number of decimal digits needed to display the passed
value.
|
static int |
getMaxHexDigits(int n)
Calculate the number of hex digits needed to display the passed value.
|
static Throwable |
getOriginalException(RuntimeException e)
Unwind the wrapper (runtime) exception to extract the original
|
static PrintWriter |
getOut()
Obtains the current writer used for printing.
|
static int |
getProcessRandom()
Return a random number assigned to this process.
|
static Random |
getRandom()
Obtain a Random object that can be used to get random values.
|
static Binary |
getRandomBinary(int cbMin,
int cbMax)
Generates a random-length Binary within the length bounds provided
whose contents are random bytes.
|
static Binary |
getRandomBinary(int cbMin,
int cbMax,
byte... abHead)
Generates a random-length Binary including
abHead at the head of
the Binary, in addition to random bytes within the length bounds provided. |
static String |
getRandomString(int cchMin,
int cchMax,
boolean fAscii)
Generates a random-length String within the length bounds provided.
|
static long |
getSafeTimeMillis()
Returns a "safe" current time in milliseconds.
|
static Base.StackFrame |
getStackFrame()
Get the StackFrame information for the current method.
|
static Base.StackFrame[] |
getStackFrames()
Iterate the StackFrame information for all callers, going from the
inside outwards, and starting with the caller of this method.
|
static String |
getStackTrace()
Build a stack trace for the current thread.
|
static String |
getStackTrace(Throwable e)
Build a stack trace for the passed exception that does not include
the exception description itself.
|
static ThreadFactory |
getThreadFactory()
Return the configured thread factory.
|
static TimeZone |
getTimeZone(String sId)
Gets the
TimeZone for the given ID. |
static long |
getUpTimeMillis()
Return the number of milliseconds which have elapsed since the JVM was
started.
|
static int |
hashCode(Object o)
Return the hash code for the supplied object or 0 for null.
|
static int |
hexValue(char ch)
Returns the integer value of a hexadecimal digit.
|
static String |
indentString(String sText,
String sIndent)
Indent the passed multi-line string.
|
static String |
indentString(String sText,
String sIndent,
boolean fFirstLine)
Textually indent the passed multi-line string.
|
static boolean |
isDecimal(char ch)
Returns true if the passed character is a decimal digit.
|
static boolean |
isHex(char ch)
Returns true if the passed character is a hexadecimal digit.
|
static boolean |
isLogEcho()
Determine if the log is echoed to the console.
|
static boolean |
isOctal(char ch)
Returns true if the passed character is an octal digit.
|
static void |
log()
Prints a blank line to the log.
|
static void |
log(Class clz)
Prints the passed class information to the log.
|
static void |
log(Object o)
Prints the passed Object to the log.
|
static void |
log(String s)
Prints the passed String value to the log.
|
static void |
log(Throwable e)
Prints the passed exception information to the log.
|
static Integer |
makeInteger(int n)
Deprecated.
|
static Long |
makeLong(long n)
Deprecated.
|
static Thread |
makeThread(ThreadGroup group,
Runnable runnable,
String sName)
Create a Thread with the specified group, runnable, and name, using
the configured ThreadFactory, as specified by the
tangosol.coherence.threadfactory system property.
|
static int |
mod(int n,
int m)
Calculate a modulo of two integer numbers.
|
static long |
mod(long n,
long m)
Calculate a modulo of two long numbers.
|
static int |
octalValue(char ch)
Returns the integer value of an octal digit.
|
static void |
out()
Prints a blank line.
|
static void |
out(Class clz)
Prints the passed class information.
|
static void |
out(Object o)
Prints the passed Object.
|
static void |
out(String s)
Prints the passed String value.
|
static void |
out(Throwable e)
Prints the passed exception information.
|
static long |
pad(long lMin,
long lMultiple)
Return the smallest value that is not less than the first argument and
is a multiple of the second argument.
|
static long |
parseBandwidth(String s)
Parse the given string representation of a number of bytes per second.
|
static long |
parseBandwidth(String s,
int nDefaultPower)
Parse the given string representation of a number of bytes per second.
|
static String[] |
parseDelimitedString(String s,
char chDelim)
Parse a character-delimited String into an array of Strings.
|
static int |
parseHex(char ch)
Return the integer value of a hexadecimal digit.
|
static byte[] |
parseHex(String s)
Parse the passed String of hexadecimal characters into a binary
value.
|
static long |
parseMemorySize(String s)
Parse the given string representation of a number of bytes.
|
static long |
parseMemorySize(String s,
int nDefaultPower)
Parse the given string representation of a number of bytes.
|
static float |
parsePercentage(String s)
Parse the given string representation of a percentage value and return
its value as a float in the inclusive range of 0.0 and 1.0.
|
static long |
parseTime(String s)
Parse the given string representation of a time duration and return its
value as a number of milliseconds.
|
static long |
parseTime(String s,
int nDefaultUnit)
Parse the given string representation of a time duration and return its
value as a number of milliseconds.
|
static long |
parseTimeNanos(String s)
Parse the given string representation of a time duration and return its
value as a number of nanoseconds.
|
static long |
parseTimeNanos(String s,
int nDefaultUnit)
Parse the given string representation of a time duration and return its
value as a number of nanoseconds.
|
static String |
printStackTrace(Throwable e)
Build a stack trace for the passed exception.
|
static List |
randomize(Collection coll)
Randomize the order of the elements within the passed collection.
|
static int[] |
randomize(int[] a)
Randomize the order of the elements within the passed array.
|
static long[] |
randomize(long[] a)
Randomize the order of the elements within the passed array.
|
static Object[] |
randomize(Object[] a)
Randomize the order of the elements within the passed array.
|
static byte[] |
read(DataInput stream)
Read the contents out of the passed stream and return the result as a
byte array.
|
static byte[] |
read(DataInputStream stream)
Read the contents out of the passed stream and return the result as a
byte array.
|
static byte[] |
read(File file)
Read the contents out of the specified file and return the result as a
byte array.
|
static byte[] |
read(InputStream stream)
Read the contents out of the passed stream and return the result as a
byte array.
|
static int |
read(InputStream stream,
byte[] ab)
Read the contents out of the passed stream into the passed byte array
and return the length read.
|
static String |
read(Reader reader)
Read the contents out of the passed Reader and return the result as a
String.
|
static byte[] |
read(URL url)
Read the contents of the specified URL and return the result as a
byte array.
|
static String |
replace(String sText,
String sFrom,
String sTo)
Replace all occurrences of the specified substring in the specified
string.
|
static void |
setErr(PrintWriter writer)
Sets the current writer used for tracing.
|
static void |
setLog(PrintWriter writer)
Sets the current writer used for logging.
|
static void |
setLogEcho(boolean fEcho)
Specify whether the log should echo to the console.
|
static void |
setOut(PrintWriter writer)
Sets the current writer used for printing.
|
static void |
sleep(long cMillis)
Convenience method for
Thread.sleep(long) . |
static String |
toBandwidthString(long cbps)
Format the passed bandwidth (in bytes per second) as a String that can
be parsed by
parseBandwidth(java.lang.String) such that
cb==parseBandwidth(toBandwidthString(cb)) holds true for
all legal values of cbps. |
static String |
toBandwidthString(long cbps,
boolean fExact)
Format the passed bandwidth (in bytes per second) as a String.
|
static String |
toCharEscape(char ch)
Format a char to a printable escape if necessary.
|
static int |
toCrc(byte[] ab)
Calculate a CRC32 value from a byte array.
|
static int |
toCrc(byte[] ab,
int of,
int cb)
Calculate a CRC32 value from a portion of a byte array.
|
static int |
toCrc(byte[] ab,
int of,
int cb,
int nCrc)
Continue to calculate a CRC32 value from a portion of a byte array.
|
static int |
toCrc(ByteSequence seq)
Calculate a CRC32 value from a ByteSequence.
|
static int |
toCrc(ByteSequence seq,
int of,
int cb,
int nCrc)
Continue to calculate a CRC32 value from a portion of a ByteSequence .
|
static String |
toDecString(int n,
int cDigits)
Format the passed non-negative integer as a fixed-length decimal string.
|
static String |
toDelimitedString(int[] an,
String sDelim)
Format the content of the passed integer array as a delimited string.
|
static String |
toDelimitedString(Iterator iter,
String sDelim)
Format the content of the passed Iterator as a delimited string.
|
static String |
toDelimitedString(long[] al,
String sDelim)
Format the content of the passed long array as a delimited string.
|
static String |
toDelimitedString(Object[] ao,
String sDelim)
Format the content of the passed Object array as a delimited string.
|
static String |
toHex(byte[] ab)
Convert a byte array to the hex sequence of 2 hex digits per byte.
|
static String |
toHex(int b)
Convert a byte to the hex sequence of 2 hex digits.
|
static String |
toHexDump(byte[] ab,
int cBytesPerLine)
Convert a byte array to a hex dump.
|
static String |
toHexEscape(byte b)
Convert a byte to a hex sequence of '0' + 'x' + 2 hex digits.
|
static String |
toHexEscape(byte[] ab)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits
per byte.
|
static String |
toHexEscape(byte[] ab,
int of,
int cb)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits
per byte.
|
static String |
toHexEscape(ByteSequence seq,
int of,
int cb)
Convert a ByteSequence to a hex sequence of '0' + 'x' + 2 hex digits
per byte.
|
static String |
toHexString(int n,
int cDigits)
Format the passed integer as a fixed-length hex string.
|
static String |
toMemorySizeString(long cb)
Format the passed memory size (in bytes) as a String that can be
parsed by
parseMemorySize(java.lang.String) such that
cb==parseMemorySize(toMemorySizeString(cb)) holds true for
all legal values of cb. |
static String |
toMemorySizeString(long cb,
boolean fExact)
Format the passed memory size (in bytes) as a String.
|
static String |
toQuotedCharEscape(char ch)
Format a char to a printable escape if necessary as it would
appear (quoted) in Java source code.
|
static String |
toQuotedStringEscape(String s)
Format a String as it would appear (quoted) in Java source code,
escaping characters as necessary.
|
static String |
toSqlString(String s)
Escapes the string for SQL.
|
static String |
toString(Class clz)
Formats Class information for debug output purposes.
|
static String |
toString(double dfl,
int cMinDigits)
Format a double value as a String.
|
static String |
toStringEscape(String s)
Format a String escaping characters as necessary.
|
static String |
toUnicodeEscape(char ch)
Format a Unicode character to the Unicode escape sequence of '\'
+ 'u' + 4 hex digits.
|
static void |
trace(boolean fVal)
Display the value of a boolean expression.
|
static void |
trace(byte[] ab)
Display the value of a byte array expression.
|
static void |
trace(char chVal)
Display the value of a char expression.
|
static void |
trace(double dflVal)
Display the value of a double expression.
|
static void |
trace(float flVal)
Display the value of a float expression.
|
static void |
trace(int nVal)
Display the value of an int expression.
|
static void |
trace(long lVal)
Display the value of a long expression.
|
static void |
trace(Object oVal)
Display the value of an Object expression.
|
static void |
trace(String sVal)
Display the value of a String expression.
|
static String |
truncateString(Collection coll,
int cLimit)
Provide a string representation of elements within the collection until
the concatenated string length exceeds
cLimit . |
static String |
truncateString(String s,
int cLimit)
Truncate a string to the specified character count.
|
static void |
wait(Object o,
long cMillis)
Convenience method for
Object.wait(long) . |
public static final int UNIT_NS
parseTimeNanos(String, int)
,
Constant Field Valuespublic static final int UNIT_US
parseTimeNanos(String, int)
,
Constant Field Valuespublic static final int UNIT_MS
parseTime(String, int)
,
Constant Field Valuespublic static final int UNIT_S
parseTime(String, int)
,
Constant Field Valuespublic static final int UNIT_M
parseTime(String, int)
,
Constant Field Valuespublic static final int UNIT_H
parseTime(String, int)
,
Constant Field Valuespublic static final int UNIT_D
parseTime(String, int)
,
Constant Field Valuespublic static final int POWER_0
public static final int POWER_K
public static final int POWER_M
public static final int POWER_G
public static final int POWER_T
public static final int LOG_MIN
public static final int LOG_MAX
public static final int LOG_ALWAYS
public static final int LOG_ERR
public static final int LOG_WARN
public static final int LOG_INFO
public static final int LOG_DEBUG
public static final int LOG_QUIET
public static void trace(boolean fVal)
fVal
- the boolean valuepublic static void trace(char chVal)
chVal
- the char valuepublic static void trace(int nVal)
nVal
- the int valuepublic static void trace(long lVal)
lVal
- the long valuepublic static void trace(float flVal)
flVal
- the float valuepublic static void trace(double dflVal)
dflVal
- the double valuepublic static void trace(byte[] ab)
ab
- the byte array valuepublic static void trace(String sVal)
sVal
- the String valuepublic static void trace(Object oVal)
oVal
- the Object valuepublic static RuntimeException azzert()
public static void azzert(boolean f)
f
- the boolean to be checkedpublic static void azzert(boolean f, String s)
f
- the boolean to be checkeds
- the assertion messagepublic static void azzertFailed(String sMsg)
sMsg
- the assertion messagepublic static RuntimeException ensureRuntimeException(Throwable e)
e
- any Throwable objectpublic static RuntimeException ensureRuntimeException(Throwable e, String s)
e
- any Throwable objects
- an additional descriptionpublic static Throwable getOriginalException(RuntimeException e)
e
- Runtime exception (wrapper)public static void out()
public static void out(Object o)
o
- the Object to print.public static void out(String s)
s
- the String to print.public static void out(Class clz)
clz
- the class object to print.public static void out(Throwable e)
e
- the Throwable object to print.public static void err()
public static void err(Object o)
o
- the Object to print.public static void err(String s)
s
- the String to print.public static void err(Class clz)
clz
- the class object to print.public static void err(Throwable e)
e
- the Throwable object to print.public static void log()
public static void log(Object o)
o
- the Object to print.public static void log(String s)
s
- the String to print.public static void log(Class clz)
clz
- the class object to print.public static void log(Throwable e)
e
- the Throwable object to print.public static ClassLoader ensureClassLoader(ClassLoader loader)
loader
- a ClassLoader (may be null)public static ClassLoader getContextClassLoader()
public static ClassLoader getContextClassLoader(Object o)
o
- the calling object, or any object out of the application
that is requesting the class loaderpublic static Base.StackFrame getCallerStackFrame()
public static Base.StackFrame getStackFrame()
public static Base.StackFrame[] getStackFrames()
public static String getStackTrace()
public static String getStackTrace(Throwable e)
e
- a Throwable object that contains stack trace informationpublic static String getDeepMessage(Throwable t, String sDelim)
t
- the throwablesDelim
- the delimiter to include between messagespublic static String printStackTrace(Throwable e)
e
- a Throwable object that contains stack trace informationpublic static BigDecimal ensureBigDecimal(Number num)
num
- a Number objectpublic static Thread makeThread(ThreadGroup group, Runnable runnable, String sName)
group
- (optional) the thread's thread grouprunnable
- (optional) the thread's runnablesName
- (optional) the thread's namepublic static ThreadFactory getThreadFactory()
public static void sleep(long cMillis)
Thread.sleep(long)
.
If the thread is interrupted before the sleep time expires, a RuntimeException is thrown and the thread's interrupt state is set.
cMillis
- the maximum time to wait in millisecondspublic static void wait(Object o, long cMillis)
Object.wait(long)
.
If the thread is interrupted before being notified or the wait time expires, a RuntimeException is thrown and the thread's interrupt state is set.
o
- the Object to wait forcMillis
- the maximum time to wait in millisecondspublic static com.oracle.coherence.common.util.CommonMonitor getCommonMonitor(int i)
i
- the common monitor identifierCommonMonitor
public static com.oracle.coherence.common.util.CommonMonitor getCommonMonitor(long l)
l
- the common monitor identifierCommonMonitor
public static com.oracle.coherence.common.util.CommonMonitor getCommonMonitor(Object o)
o
- the object to obtain a common monitor forCommonMonitor
public static String toString(Class clz)
clz
- the Class to print information forpublic static boolean isDecimal(char ch)
ch
- The character to checktrue
if the passed character is a decimal digitpublic static int decimalValue(char ch)
ch
- The character to convertpublic static int getMaxDecDigits(int n)
n
- the valuepublic static String toDecString(int n, int cDigits)
n
- the valuecDigits
- the length of the resulting decimal stringpublic static long pad(long lMin, long lMultiple)
lMin
- the smallest value to returnlMultiple
- the return value will be a multiple of this argumentpublic static boolean isOctal(char ch)
ch
- The character to checktrue
if the passed character is an octal digitpublic static int octalValue(char ch)
ch
- The character to convertpublic static boolean isHex(char ch)
ch
- The character to checktrue
if the passed character is a hexadecimal digitpublic static int hexValue(char ch)
ch
- The character to convertpublic static int getMaxHexDigits(int n)
n
- the valuepublic static String toHexString(int n, int cDigits)
n
- the valuecDigits
- the length of the resulting hex stringpublic static String toHex(int b)
b
- the bytepublic static String toHex(byte[] ab)
ab
- the byte arraypublic static String toHexEscape(byte b)
b
- the bytepublic static String toHexEscape(byte[] ab)
ab
- the byte arraypublic static String toHexEscape(byte[] ab, int of, int cb)
ab
- the byte arrayof
- the offset into arraycb
- the number of bytes to convertpublic static String toHexEscape(ByteSequence seq, int of, int cb)
seq
- the ByteSequenceof
- the offset into the byte sequencecb
- the number of bytes to convertpublic static String toHexDump(byte[] ab, int cBytesPerLine)
ab
- the byte array to format as a hex stringcBytesPerLine
- the number of bytes to display on a linepublic static byte[] parseHex(String s)
s
- the hex String to evaluatepublic static int parseHex(char ch)
ch
- the hex character to evaluatepublic static String toString(double dfl, int cMinDigits)
dfl
- a double valuecMinDigits
- the minimum number of digits of precision to displaypublic static String toUnicodeEscape(char ch)
ch
- the characterpublic static String toCharEscape(char ch)
ch
- the charpublic static String toQuotedCharEscape(char ch)
ch
- the characterpublic static String toStringEscape(String s)
s
- the Stringpublic static String toQuotedStringEscape(String s)
s
- the Stringpublic static int escape(char ch, char[] ach, int of)
ch
- the character to formatach
- the array of characters to format intoof
- the offset in the array to format atpublic static String toSqlString(String s)
s
- the String to escapepublic static String indentString(String sText, String sIndent)
sText
- the string to indentsIndent
- a string used to indent each linepublic static String indentString(String sText, String sIndent, boolean fFirstLine)
sText
- the string to indentsIndent
- a string used to indent each linefFirstLine
- true indents all lines;
false indents all but the firstpublic static String breakLines(String sText, int nWidth, String sIndent)
sText
- the string to breaknWidth
- the max width of resulting lines (including the indent)sIndent
- a string used to indent each linepublic static String breakLines(String sText, int nWidth, String sIndent, boolean fFirstLine)
sText
- the string to breaknWidth
- the max width of resulting lines (including the
indent)sIndent
- a string used to indent each linefFirstLine
- if true indents all lines;
otherwise indents all but the firstpublic static String dup(char ch, int cch)
ch
- the character to fill the String withcch
- the length of the Stringpublic static String dup(String s, int c)
s
- the String to fill the new String withc
- the number of duplicates to put into the new Stringpublic static String replace(String sText, String sFrom, String sTo)
sText
- string to changesFrom
- pattern to change fromsTo
- pattern to change topublic static String[] parseDelimitedString(String s, char chDelim)
s
- character-delimited String to parsechDelim
- character delimiterpublic static String toDelimitedString(int[] an, String sDelim)
an
- the arraysDelim
- the delimiterpublic static String toDelimitedString(long[] al, String sDelim)
al
- the arraysDelim
- the delimiterpublic static String toDelimitedString(Object[] ao, String sDelim)
ao
- the arraysDelim
- the delimiterpublic static String toDelimitedString(Iterator iter, String sDelim)
iter
- the IteratorsDelim
- the delimiterpublic static String capitalize(String s)
s
- the string to capitalizepublic static String truncateString(String s, int cLimit)
s
- the String to be truncatedcLimit
- expected character countpublic static String truncateString(Collection coll, int cLimit)
cLimit
.coll
- the collection of elements to describecLimit
- expected character countpublic static long parseBandwidth(String s)
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
If the string value does not contain a factor, a factor of one is assumed.
The optional last three characters indicate the unit of measure, [b][P|p][S|s] in the case of bits per second and [B][P|p][S|s] in the case of bytes per second. If the string value does not contain a unit, a unit of bits per second is assumed.
s
- a string with the format:
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?public static long parseBandwidth(String s, int nDefaultPower)
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
If the string value does not contain an explicit or implicit factor, a factor calculated by raising 2 to the given default power is used. The default power can be one of:
The optional last three characters indicate the unit of measure, [b][P|p][S|s] in the case of bits per second and [B][P|p][S|s] in the case of bytes per second. If the string value does not contain a unit, a unit of bits per second is assumed.
s
- a string with the format:
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?nDefaultPower
- the exponent used to calculate the factor used in
the conversion if one is not implied by the given
stringpublic static String toBandwidthString(long cbps)
parseBandwidth(java.lang.String)
such that
cb==parseBandwidth(toBandwidthString(cb)) holds true for
all legal values of cbps.cbps
- the number of bytes per secondpublic static String toBandwidthString(long cbps, boolean fExact)
cbps
- the number of bytes per secondfExact
- true if the String representation must be exact, or
false if it can be an approximationpublic static long parseMemorySize(String s)
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
If the string value does not contain a factor, a factor of one is assumed.
The optional last character B or b indicates a unit of bytes.
s
- a string with the format
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?public static long parseMemorySize(String s, int nDefaultPower)
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
If the string value does not contain an explicit or implicit factor, a factor calculated by raising 2 to the given default power is used. The default power can be one of:
The optional last character B or b indicates a unit of bytes.
s
- a string with the format
[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?nDefaultPower
- the exponent used to calculate the factor used in
the conversion if one is not implied by the given
stringpublic static String toMemorySizeString(long cb)
parseMemorySize(java.lang.String)
such that
cb==parseMemorySize(toMemorySizeString(cb)) holds true for
all legal values of cb.cb
- the number of bytes of memorypublic static String toMemorySizeString(long cb, boolean fExact)
cb
- the number of bytes of memoryfExact
- true if the String representation must be exact, or
false if it can be an approximationpublic static long parseTime(String s)
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
If the string value does not contain a unit, a unit of milliseconds is assumed.
s
- a string with the format
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?parseTimeNanos(String)
public static long parseTime(String s, int nDefaultUnit)
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
If the string value does not contain a unit, the specified default unit is assumed. The default unit can be one of:
s
- a string with the format
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?nDefaultUnit
- the unit to use in the conversion to milliseconds
if one is not specified in the supplied stringparseTimeNanos(String, int)
public static long parseTimeNanos(String s)
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
If the string value does not contain a unit, a unit of nanoseconds is assumed.
s
- a string with the format
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?public static long parseTimeNanos(String s, int nDefaultUnit)
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
If the string value does not contain a unit, the specified default unit is assumed. The default unit can be one of:
s
- a string with the format
[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?nDefaultUnit
- the unit to use in the conversion to nanoseconds
if one is not specified in the supplied stringpublic static String formatDateTime(long ldt)
ldt
- a Java long containing a date/time valuepublic static float parsePercentage(String s)
[\d]+[[.][\d]+]?[%]
where the digits are within the closed interval [0.0, 100.0].
s
- a string with the format [\d]+[[.][\d]+]?[%]public static int hashCode(Object o)
o
- the object to hashpublic static boolean equals(Object o1, Object o2)
o1
- an objecto2
- an object to be compared with o1 for references equalitypublic static boolean equalsDeep(Object o1, Object o2)
o1
- an objecto2
- an ojbect to be compared with o1 for deeply equalitypublic static int toCrc(byte[] ab)
ab
- an array of bytespublic static int toCrc(byte[] ab, int of, int cb)
ab
- an array of bytesof
- the offset into the arraycb
- the number of bytes to evaluatepublic static int toCrc(byte[] ab, int of, int cb, int nCrc)
ab
- an array of bytesof
- the offset into the arraycb
- the number of bytes to evaluatenCrc
- the previous CRC valuepublic static int toCrc(ByteSequence seq)
seq
- a ByteSequencepublic static int toCrc(ByteSequence seq, int of, int cb, int nCrc)
seq
- a ByteSequenceof
- the offset into the ByteSequencecb
- the number of bytes to evaluatenCrc
- the previous CRC valuepublic static long getUpTimeMillis()
public static long getSafeTimeMillis()
SafeClock
public static long getLastSafeTimeMillis()
getSafeTimeMillis()
method.SafeClock
public static long computeSafeWaitTime(long ldtTimeout)
Note: this method will only return zero if ldtTimeout == Long.MAX_VALUE.
ldtTimeout
- the timeout as computed by getSafeTimeMillis()
public static TimeZone getTimeZone(String sId)
TimeZone
for the given ID.
This method will cache returned TimeZones to avoid the contention
caused by the TimeZone.getTimeZone(String)
implementation.
sId
- the ID for a TimeZone
TimeZone
, or the GMT zone if the
given ID cannot be understood.TimeZone.getTimeZone(String)
@Deprecated public static Integer makeInteger(int n)
Integer.valueOf(int)
n
- an int@Deprecated public static Long makeLong(long n)
Long.valueOf(long)
n
- a longpublic static int getProcessRandom()
This value will remain the same across invocations, but is generally different across JVMs.
public static Random getRandom()
public static List randomize(Collection coll)
coll
- the Collection to randomize; the passed Collection is not
alteredpublic static Object[] randomize(Object[] a)
a
- an array of objects to randomizepublic static int[] randomize(int[] a)
a
- an array of int values to randomizepublic static long[] randomize(long[] a)
a
- an array of long values to randomizepublic static Binary getRandomBinary(int cbMin, int cbMax)
cbMin
- the minimum number of bytes in the resulting BinarycbMax
- the maximum number of bytes in the resulting Binarypublic static Binary getRandomBinary(int cbMin, int cbMax, byte... abHead)
abHead
at the head of
the Binary, in addition to random bytes within the length bounds provided.cbMin
- the minimum number of bytes in the resulting BinarycbMax
- the maximum number of bytes in the resulting BinaryabHead
- the head of the returned Binary[len(abHead) + cbMin, cbMax]
public static String getRandomString(int cchMin, int cchMax, boolean fAscii)
cchMin
- the minimum length of the resulting StringcchMax
- the maximum length of the resulting StringfAscii
- true if the resulting String should contain only ASCII
valuespublic static void checkRange(long lValue, long lFrom, long lTo, String sName)
lValue
- the value to checklFrom
- the lower limit of the range (inclusive)lTo
- the upper limit of the range (inclusive)sName
- the display name of the valueIllegalArgumentException
- if the value is out of rangepublic static <T> T checkNotNull(T o, String sName)
T
- the type parameter for the object to checko
- the object to checksName
- the name of the corresponding parameterIllegalArgumentException
- if o is nullpublic static void checkNotEmpty(String s, String sName)
s
- the string to checksName
- the name of the corresponding parameterIllegalArgumentException
- if s is null or empty stringpublic static int mod(int n, int m)
n % m
).
For a negative dividend the result is still positive and equals to
(n % m + m
).n
- the dividendm
- the divisor (must be positive)public static long mod(long n, long m)
n % m
).
For a negative dividend the result is still positive and equals to
(n % m + m
).n
- the dividendm
- the divisor (must be positive)public static PrintWriter getOut()
public static void setOut(PrintWriter writer)
writer
- the java.io.PrintWriter instance to use for printing;
may be nullpublic static PrintWriter getErr()
public static void setErr(PrintWriter writer)
writer
- the java.io.PrintWriter instance to use for tracing; may
be nullpublic static PrintWriter getLog()
public static void setLog(PrintWriter writer)
writer
- the java.io.PrintWriter instance to use for logging; may
be nullpublic static boolean isLogEcho()
public static void setLogEcho(boolean fEcho)
fEcho
- true if the log should echo to the consolepublic static int read(InputStream stream, byte[] ab) throws IOException
stream
- a java.io.InputStream object to read fromab
- a byte array to read intoIOException
- if an I/O error occurspublic static byte[] read(InputStream stream) throws IOException
stream
- a java.io.InputStream object to read fromIOException
- if an I/O error occurspublic static byte[] read(DataInput stream) throws IOException
stream
- a java.io.DataInput object to read fromIOException
- if an I/O error occurspublic static byte[] read(DataInputStream stream) throws IOException
stream
- a java.io.DataInputStream object to read fromIOException
- if an I/O error occurspublic static String read(Reader reader) throws IOException
reader
- a java.io.Reader object to read fromIOException
- if an I/O error occurspublic static byte[] read(File file) throws IOException
file
- the java.io.File object to read the contents ofIOException
- if an I/O error occurspublic static byte[] read(URL url) throws IOException
url
- the java.net.URL object to read the contents ofIOException
- if an I/O error occurs