public class StandardRepresentation extends java.lang.Object implements Representation
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.util.function.Function<?,java.lang.String>> |
customFormatterByType |
private static java.lang.String |
DEFAULT_END |
private static java.lang.String |
DEFAULT_MAX_ELEMENTS_EXCEEDED |
private static java.lang.String |
DEFAULT_START |
static java.lang.String |
ELEMENT_SEPARATOR |
static java.lang.String |
ELEMENT_SEPARATOR_WITH_NEWLINE |
(package private) static java.lang.String |
INDENTATION_AFTER_NEWLINE |
(package private) static java.lang.String |
INDENTATION_FOR_SINGLE_LINE |
private static int |
maxElementsForPrinting |
private static int |
maxLengthForSingleLineDescription |
private static java.lang.String |
NULL |
static StandardRepresentation |
STANDARD_REPRESENTATION |
private static java.lang.String |
TUPLE_END |
private static java.lang.String |
TUPLE_START |
Constructor and Description |
---|
StandardRepresentation() |
Modifier and Type | Method and Description |
---|---|
protected <T> java.lang.String |
customFormat(T object) |
private static boolean |
doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription) |
java.lang.String |
format(java.lang.Iterable<?> iterable,
java.lang.String start,
java.lang.String end,
java.lang.String elementSeparator,
java.lang.String indentation) |
private java.lang.String |
format(java.util.Map<?,?> map,
java.lang.Object o) |
protected java.lang.String |
format(java.lang.Object[] array,
java.lang.String elementSeparator,
java.lang.String indentation,
java.util.Set<java.lang.Object[]> alreadyFormatted) |
protected java.lang.String |
formatArray(java.lang.Object o)
Returns the
String representation of the given array, or null if the given object is either
null or not an array. |
protected java.lang.String |
formatPrimitiveArray(java.lang.Object o) |
static int |
getMaxLengthForSingleLineDescription() |
protected boolean |
hasCustomFormatterFor(java.lang.Object object) |
protected java.lang.String |
multiLineFormat(java.lang.Iterable<?> iterable) |
protected java.lang.String |
multiLineFormat(Representation representation,
java.lang.Object[] iterable,
java.util.Set<java.lang.Object[]> alreadyFormatted) |
static <T> void |
registerFormatterForType(java.lang.Class<T> type,
java.util.function.Function<T,java.lang.String> formatter)
Registers new formatter for the given type.
|
static void |
removeAllRegisteredFormatters()
Clear all formatters registered per type with
registerFormatterForType(Class, Function) . |
static void |
resetDefaults()
It resets the static defaults for the standard representation.
|
static void |
setMaxElementsForPrinting(int value) |
static void |
setMaxLengthForSingleLineDescription(int value) |
protected java.lang.String |
singleLineFormat(java.lang.Iterable<?> iterable,
java.lang.String start,
java.lang.String end) |
protected java.lang.String |
singleLineFormat(Representation representation,
java.lang.Object[] iterable,
java.lang.String start,
java.lang.String end,
java.util.Set<java.lang.Object[]> alreadyFormatted) |
protected java.lang.String |
smartFormat(java.lang.Iterable<?> iterable)
Returns the
String representation of the given Iterable , or null if the given
Iterable is null . |
protected java.lang.String |
smartFormat(Representation representation,
java.lang.Object[] iterable) |
private static java.util.Map<?,?> |
toSortedMapIfPossible(java.util.Map<?,?> map) |
java.lang.String |
toString() |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicBoolean atomicBoolean) |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicInteger atomicInteger) |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicLong atomicLong) |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicMarkableReference<?> atomicMarkableReference) |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicReference<?> atomicReference) |
protected java.lang.String |
toStringOf(java.util.concurrent.atomic.AtomicStampedReference<?> atomicStampedReference) |
protected java.lang.String |
toStringOf(java.util.Calendar c) |
protected java.lang.String |
toStringOf(java.lang.Character c) |
protected java.lang.String |
toStringOf(java.lang.Class<?> c) |
protected java.lang.String |
toStringOf(java.util.Comparator<?> comparator) |
protected java.lang.String |
toStringOf(java.util.concurrent.CompletableFuture<?> future) |
protected java.lang.String |
toStringOf(java.util.Date d) |
protected java.lang.String |
toStringOf(java.io.File f) |
protected java.lang.String |
toStringOf(java.lang.Float f) |
protected java.lang.String |
toStringOf(java.lang.Long l) |
protected java.lang.String |
toStringOf(java.util.Map<?,?> map) |
protected java.lang.String |
toStringOf(MapEntry<?,?> mapEntry) |
protected java.lang.String |
toStringOf(java.lang.Number number) |
java.lang.String |
toStringOf(java.lang.Object object)
Returns standard the
toString representation of the given object. |
protected java.lang.String |
toStringOf(PredicateDescription p) |
protected java.lang.String |
toStringOf(java.text.SimpleDateFormat dateFormat) |
protected java.lang.String |
toStringOf(java.lang.String s) |
protected java.lang.String |
toStringOf(Tuple tuple) |
java.lang.String |
unambiguousToStringOf(java.lang.Object obj)
Returns the
String representation of the given object with its type and hexadecimal hash code so that
it can be differentied from other objects with the same Representation.toStringOf(Object) representation. |
public static final StandardRepresentation STANDARD_REPRESENTATION
private static final java.lang.String NULL
private static final java.lang.String TUPLE_START
private static final java.lang.String TUPLE_END
private static final java.lang.String DEFAULT_START
private static final java.lang.String DEFAULT_END
private static final java.lang.String DEFAULT_MAX_ELEMENTS_EXCEEDED
static final java.lang.String INDENTATION_AFTER_NEWLINE
static final java.lang.String INDENTATION_FOR_SINGLE_LINE
public static final java.lang.String ELEMENT_SEPARATOR
public static final java.lang.String ELEMENT_SEPARATOR_WITH_NEWLINE
private static int maxLengthForSingleLineDescription
private static final java.util.Map<java.lang.Class<?>,java.util.function.Function<?,java.lang.String>> customFormatterByType
private static int maxElementsForPrinting
public static void resetDefaults()
The following defaults will be reapplied:
maxLengthForSingleLineDescription = 80
maxElementsForPrinting = 1000
public static void setMaxLengthForSingleLineDescription(int value)
public static int getMaxLengthForSingleLineDescription()
public static void setMaxElementsForPrinting(int value)
public static <T> void registerFormatterForType(java.lang.Class<T> type, java.util.function.Function<T,java.lang.String> formatter)
public static void removeAllRegisteredFormatters()
registerFormatterForType(Class, Function)
.public java.lang.String toStringOf(java.lang.Object object)
toString
representation of the given object. It may or not the object's own
implementation of toString
.toStringOf
in interface Representation
object
- the given object.toString
representation of the given object.protected <T> java.lang.String customFormat(T object)
protected boolean hasCustomFormatterFor(java.lang.Object object)
public java.lang.String unambiguousToStringOf(java.lang.Object obj)
Representation
String
representation of the given object with its type and hexadecimal hash code so that
it can be differentied from other objects with the same Representation.toStringOf(Object)
representation.unambiguousToStringOf
in interface Representation
obj
- the object to represent.toString
representation of the given object.protected java.lang.String toStringOf(java.lang.Number number)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicBoolean atomicBoolean)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicInteger atomicInteger)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicLong atomicLong)
protected java.lang.String toStringOf(java.util.Comparator<?> comparator)
protected java.lang.String toStringOf(java.util.Calendar c)
protected java.lang.String toStringOf(java.lang.Class<?> c)
protected java.lang.String toStringOf(java.lang.String s)
protected java.lang.String toStringOf(java.lang.Character c)
protected java.lang.String toStringOf(PredicateDescription p)
protected java.lang.String toStringOf(java.util.Date d)
protected java.lang.String toStringOf(java.lang.Float f)
protected java.lang.String toStringOf(java.lang.Long l)
protected java.lang.String toStringOf(java.io.File f)
protected java.lang.String toStringOf(java.text.SimpleDateFormat dateFormat)
protected java.lang.String toStringOf(java.util.concurrent.CompletableFuture<?> future)
protected java.lang.String toStringOf(Tuple tuple)
protected java.lang.String toStringOf(MapEntry<?,?> mapEntry)
protected java.lang.String toStringOf(java.util.Map<?,?> map)
private static java.util.Map<?,?> toSortedMapIfPossible(java.util.Map<?,?> map)
private java.lang.String format(java.util.Map<?,?> map, java.lang.Object o)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicReference<?> atomicReference)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicMarkableReference<?> atomicMarkableReference)
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicStampedReference<?> atomicStampedReference)
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String formatArray(java.lang.Object o)
String
representation of the given array, or null
if the given object is either
null
or not an array. This method supports arrays having other arrays as elements.o
- the object that is expected to be an array.String
representation of the given array.protected java.lang.String multiLineFormat(Representation representation, java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)
protected java.lang.String singleLineFormat(Representation representation, java.lang.Object[] iterable, java.lang.String start, java.lang.String end, java.util.Set<java.lang.Object[]> alreadyFormatted)
protected java.lang.String smartFormat(Representation representation, java.lang.Object[] iterable)
protected java.lang.String format(java.lang.Object[] array, java.lang.String elementSeparator, java.lang.String indentation, java.util.Set<java.lang.Object[]> alreadyFormatted)
protected java.lang.String formatPrimitiveArray(java.lang.Object o)
public java.lang.String format(java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end, java.lang.String elementSeparator, java.lang.String indentation)
protected java.lang.String multiLineFormat(java.lang.Iterable<?> iterable)
protected java.lang.String singleLineFormat(java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end)
protected java.lang.String smartFormat(java.lang.Iterable<?> iterable)
String
representation of the given Iterable
, or null
if the given
Iterable
is null
.
The Iterable
will be formatted to a single line if it does not exceed 100 char, otherwise each elements
will be formatted on a new line with 4 space indentation.
iterable
- the Iterable
to format.String
representation of the given Iterable
.private static boolean doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription)