public final class PrettyPrinter extends Object
toString(Object)
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY_ELLIPSIS
If an array is larger than this threshold (10), then it is printed as
{ elem-0, elem-1, elem-2, ... }
|
static int |
CHAR_ARRAY_ELLIPSIS
If a char array is larger than this threshold (20), then it is printed as
'abc'...
|
static int |
CHAR_SEQUENCE_ELLIPSIS
If a char sequence is longer than this threshold (100), then it is printed as
"abc"...
|
static int |
TOTAL_LENGTH_ELLIPSIS
If the length of the output exceeds this threshold (1024), then all remaining array
elements are printed as
"abc"...
|
Modifier and Type | Method and Description |
---|---|
static String |
codePointToJavaLiteral(int codePoint)
Converts the codePoint into a JAVA char literal (e.g.
|
static String |
codePointToString(int cp)
Deprecated.
Use
codePointToJavaLiteral(int) instead |
static String |
toJavaArrayInitializer(Object array)
Converts an array into a Java array initializer.
|
static String |
toJavaCharLiteral(char c)
Converts a
char into a Java character literal, like '\n' . |
static String |
toJavaStringLiteral(CharSequence cs)
Converts a
CharSequence into a Java string literal. |
static String |
toString(Object o)
An improved version of
String.valueOf(Object) . |
public static final int ARRAY_ELLIPSIS
{ elem-0, elem-1, elem-2, ... }
public static final int CHAR_ARRAY_ELLIPSIS
'abc'...
public static final int CHAR_SEQUENCE_ELLIPSIS
"abc"...
public static final int TOTAL_LENGTH_ELLIPSIS
"abc"...
@Nullable public static String toString(@Nullable Object o)
String.valueOf(Object)
.
Objects are converted to strings in a Java-like format:
'\n'
3B 3S 3L 3F 3D
"abc\n"
"abcdef"... (123 chars)
CharSequence
:StringBuilder "abc\n"
char[4] 'abc\n'
char[99] 'abcdef'...
int[3] { 1, 2, 3 }
short[199] { 1, 2, 3, 4, 5, 6, ... }
Object[3][] { [self], null, Object[2] { "abc", [parent] } }
Object.toString()
Large objects are abbreviated with an ellipsis as shown above:
As the result string exceeds 1024 characters, all remaining arrays and
CharSequence
s are abbreviated, so the result string will effectively not be much longer than 1024 characters.
public static String toJavaStringLiteral(@Nullable CharSequence cs)
CharSequence
into a Java string literal.
"abc\n"
"abcdef"... (123 chars)
CharSequence
:StringBuilder "abc\n"
CharSequence
s are abbreviated with an ellipsis as shown above when their length exceeds 100 chars.
public static String toJavaCharLiteral(char c)
char
into a Java character literal, like '\n'
.public static String toJavaArrayInitializer(@Nullable Object array)
char[4] 'abc\n'
char[99] 'abcdef'...
int[3] { 1, 2, 3 }
short[199] { 1, 2, 3, 4, 5, 6, ... }
Object[3][] { [self], null, Object[2] { "abc", [parent] } }
Large arrays are abbreviated with an ellipsis as shown above:
@Nullable public static String codePointToJavaLiteral(int codePoint)
'\n'
or 'A'
), or, iff the
codePoint is supplementary (>= 64k), into a JAVA hexadecimal integer literal (e.g. 0x10000
).@Deprecated @Nullable public static String codePointToString(int cp)
codePointToJavaLiteral(int)
insteadCopyright © 2018 Arno Unkrig. All rights reserved.