Methods Summary |
---|
public static java.lang.String | NEWLINE()
if ( NEWLINE_STR == null )
{
NEWLINE_STR = System.getProperty( "line.separator" );
}
return NEWLINE_STR;
|
public static java.lang.String | findAndStripPrefix(java.util.Set prefixes, java.lang.String s)
final String prefix = getPrefix( prefixes, s );
if ( prefix == null )
{
throw new IllegalArgumentException( s );
}
return stripPrefix( s, prefix );
|
public static java.lang.String | getMillisString(long nanos)
return getTimingString( nanos, TimeUnit.MILLISECONDS );
|
public static java.lang.String | getPrefix(java.util.Set prefixes, java.lang.String s)
String result = null;
for( final String prefix : prefixes )
{
if ( s.startsWith( prefix ) )
{
result = prefix;
break;
}
}
return result;
|
public static java.lang.String | getSecondsString(long nanos)
return getTimingString( nanos, TimeUnit.SECONDS );
|
public static java.lang.String | getTimingString(long nanos, java.util.concurrent.TimeUnit timeUnit)
String result = null;
if ( timeUnit == TimeUnit.NANOSECONDS )
{
result = String.format( NANOS_FORMAT, nanos );
}
else if ( timeUnit == TimeUnit.MICROSECONDS )
{
result = String.format( MICROS_FORMAT, micros(nanos) );
}
else if ( timeUnit == TimeUnit.MILLISECONDS )
{
result = String.format( MILLIS_FORMAT, millis(nanos) );
}
else if ( timeUnit == TimeUnit.SECONDS )
{
result = String.format( SECONDS_FORMAT, seconds(nanos) );
}
return result;
|
public static java.lang.String | getTimingString(long nanos)Get a String representing the specified number of nanoseconds, choosing
the appropriate units based on magnitude of the value.
final long seconds = nanos / (1000 * 1000 * 1000 );
final long millis = nanos % (1000 * 1000 * 1000 ) / ( 1000 * 1000);
final long micros = nanos % (1000 * 1000 ) / 1000;
final long nanosMod = nanos % 1000;
String runTimeString = null;
final long MICROSECOND = 1000;
final long MILLISECOND = 1000 * MICROSECOND;
if ( nanos < 10 * 1000 )
{
runTimeString = nanos + " nanoseconds";
}
else if ( nanos < 1000 * 10 * 1000 )
{
runTimeString = (nanos / MICROSECOND) + " microseconds";
}
else
{
runTimeString = (nanos / MILLISECOND ) + " milliseconds";
}
return runTimeString;
|
private static double | micros(long nanos)
return (double)nanos / 1000;
|
private static double | millis(long nanos)
return (double)nanos / (1000 * 1000 );
|
public static java.lang.String | quote(java.lang.Object o)
return( quote( o, QUOTE_CHAR ) );
|
public static java.lang.String | quote(java.lang.Object o, char leftHandChar)
final String s = o == null ? "null" : SmartStringifier.toString( o );
char leftChar = leftHandChar;
char rightChar = leftHandChar;
if ( leftHandChar == '(" )
{
rightChar = ')";
}
else if ( leftHandChar == '{" )
{
rightChar = '}";
}
else if ( leftHandChar == '[" )
{
rightChar = ']";
}
else if ( leftHandChar == '<" )
{
rightChar = '>";
}
else
{
// same char on both left and right
}
final String out = leftChar + s + rightChar;
return( out );
|
public static java.lang.String | replaceSuffix(java.lang.String s, java.lang.String fromSuffix, java.lang.String toSuffix)
if ( ! s.endsWith( fromSuffix ) )
{
throw new IllegalArgumentException( fromSuffix );
}
return( stripSuffix( s, fromSuffix ) + toSuffix );
|
private static double | seconds(long nanos)
return (double)nanos / (1000 * 1000 * (long)1000 );
|
public static java.lang.String | stripPrefix(java.lang.String s, java.lang.String prefix)
String result = s;
if ( s.startsWith( prefix ) )
{
result = s.substring( prefix.length(), s.length() );
}
return( result );
|
public static java.lang.String | stripPrefixAndSuffix(java.lang.String s, java.lang.String prefix, java.lang.String suffix)
return stripPrefix( stripSuffix( s, suffix ), prefix );
|
public static java.lang.String | stripSuffix(java.lang.String s, java.lang.String suffix)
String result = s;
if ( s.endsWith( suffix ) )
{
result = s.substring( 0, s.length() - suffix.length() );
}
return( result );
|
public static java.lang.String | toHexString(byte theByte)
String result = Integer.toHexString( ((int)theByte) & 0x000000FF );
if ( result.length() == 1 )
{
result = "0" + result;
}
return( result );
|
public static java.lang.String | toHexString(byte[] bytes)
return( toHexString( bytes, null ) );
|
public static java.lang.String | toHexString(byte[] bytes, java.lang.String delim)
final StringBuffer buf = new StringBuffer();
if ( bytes.length == 0 )
{
// nothing
}
else if ( delim == null || delim.length() == 0 )
{
for( int i = 0; i < bytes.length; ++i )
{
buf.append( toHexString( bytes[ i ] ) );
}
}
else
{
for( int i = 0; i < bytes.length; ++i )
{
buf.append( toHexString( bytes[ i ] ) + delim );
}
// remove trailing delim
buf.setLength( buf.length() - 1);
}
return( buf.toString() );
|
public static java.lang.String | toString(java.lang.Object o)
String s = null;
if ( o instanceof String )
{
s = (String)o;
}
else if ( o instanceof Throwable )
{
s = ExceptionUtil.toString( (Throwable)o );
}
else if ( o instanceof ObjectName )
{
s = JMXUtil.toString( (ObjectName)o );
}
else if ( o instanceof Attribute )
{
final Attribute a = (Attribute)o;
s = a.getName() + "=" + toString( a.getValue() );
}
else if ( o instanceof AttributeList )
{
final Map<String,Object> items = JMXUtil.attributeListToValueMap( (AttributeList)o );
s = "{" + MapUtil.toString( items ) + "}";
}
else if ( o instanceof byte[] )
{
final byte[] b = byte[].class.cast( o );
s = "byte[] of length " + b.length;
}
else if ( o == null )
{
s = "null";
}
else if ( o instanceof Object[] )
{
s = toString( ", ", (Object[])o );
}
else
{
s = "" + o;
}
return s;
|
public static java.lang.String | toString(java.lang.String[] args)
return toString( ", ", args );
|
public static java.lang.String | toString(java.lang.String delim, java.lang.String args)
return toString( delim, (Object[])args );
|
public static java.lang.String | toString(java.lang.String delim, java.lang.Object args)Turn an array (or varargs) set of Objects into a String
using the specified delimiter.
String result = null;
if ( args == null )
{
result = "" + null;
}
else if ( args.length == 0 )
{
result = "";
}
else if ( args.length == 1 )
{
result = toString( args[ 0 ] );
}
else
{
final StringBuilder builder = new StringBuilder();
for( int i = 0; i < args.length - 1; ++i )
{
builder.append( toString( args[ i ] ) );
builder.append( delim );
}
builder.append( toString( args[ args.length - 1 ] ) );
result = builder.toString();
}
return result;
|
public static java.lang.String | upperCaseFirstLetter(java.lang.String s)
String result = s;
if ( s.length() >= 1 )
{
result = s.substring( 0, 1 ).toUpperCase() + s.substring( 1, s.length() );
}
return( result );
|
private static java.lang.String | zeroPad(long num)
String result = null;
if ( num >= 100 )
result = "" + num;
else if ( num >= 10 )
result = "0" + num;
else
result = "00" + num;
return result;
|