Package org.assertj.core.presentation
Class StandardRepresentation
- java.lang.Object
-
- org.assertj.core.presentation.StandardRepresentation
-
- All Implemented Interfaces:
Representation
- Direct Known Subclasses:
BinaryRepresentation
,HexadecimalRepresentation
,UnicodeRepresentation
public class StandardRepresentation extends java.lang.Object implements Representation
Standard java object representation.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description StandardRepresentation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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)
protected java.lang.String
format(java.lang.Object[] array, java.lang.String elementSeparator, java.lang.String indentation, java.util.Set<java.lang.Object[]> alreadyFormatted)
private java.lang.String
format(java.util.Map<?,?> map, java.lang.Object o)
protected java.lang.String
formatArray(java.lang.Object o)
Returns theString
representation of the given array, ornull
if the given object is eithernull
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 withregisterFormatterForType(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 theString
representation of the givenIterable
, ornull
if the givenIterable
isnull
.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.io.File f)
protected java.lang.String
toStringOf(java.lang.Character c)
protected java.lang.String
toStringOf(java.lang.Class<?> c)
protected java.lang.String
toStringOf(java.lang.Float f)
protected java.lang.String
toStringOf(java.lang.Long l)
protected java.lang.String
toStringOf(java.lang.Number number)
java.lang.String
toStringOf(java.lang.Object object)
Returns standard thetoString
representation of the given object.protected java.lang.String
toStringOf(java.lang.String s)
protected java.lang.String
toStringOf(java.text.SimpleDateFormat dateFormat)
protected java.lang.String
toStringOf(java.util.Calendar c)
protected java.lang.String
toStringOf(java.util.Comparator<?> comparator)
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.concurrent.CompletableFuture<?> future)
protected java.lang.String
toStringOf(java.util.Date d)
protected java.lang.String
toStringOf(java.util.Map<?,?> map)
protected java.lang.String
toStringOf(MapEntry<?,?> mapEntry)
protected java.lang.String
toStringOf(Tuple tuple)
protected java.lang.String
toStringOf(PredicateDescription p)
java.lang.String
unambiguousToStringOf(java.lang.Object obj)
Returns theString
representation of the given object with its type and hexadecimal hash code so that it can be differentied from other objects with the sameRepresentation.toStringOf(Object)
representation.
-
-
-
Field Detail
-
STANDARD_REPRESENTATION
public static final StandardRepresentation STANDARD_REPRESENTATION
-
NULL
private static final java.lang.String NULL
- See Also:
- Constant Field Values
-
TUPLE_START
private static final java.lang.String TUPLE_START
- See Also:
- Constant Field Values
-
TUPLE_END
private static final java.lang.String TUPLE_END
- See Also:
- Constant Field Values
-
DEFAULT_START
private static final java.lang.String DEFAULT_START
- See Also:
- Constant Field Values
-
DEFAULT_END
private static final java.lang.String DEFAULT_END
- See Also:
- Constant Field Values
-
DEFAULT_MAX_ELEMENTS_EXCEEDED
private static final java.lang.String DEFAULT_MAX_ELEMENTS_EXCEEDED
- See Also:
- Constant Field Values
-
INDENTATION_AFTER_NEWLINE
static final java.lang.String INDENTATION_AFTER_NEWLINE
- See Also:
- Constant Field Values
-
INDENTATION_FOR_SINGLE_LINE
static final java.lang.String INDENTATION_FOR_SINGLE_LINE
- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR
public static final java.lang.String ELEMENT_SEPARATOR
- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR_WITH_NEWLINE
public static final java.lang.String ELEMENT_SEPARATOR_WITH_NEWLINE
-
maxLengthForSingleLineDescription
private static int maxLengthForSingleLineDescription
-
customFormatterByType
private static final java.util.Map<java.lang.Class<?>,java.util.function.Function<?,java.lang.String>> customFormatterByType
-
maxElementsForPrinting
private static int maxElementsForPrinting
-
-
Method Detail
-
resetDefaults
public static void resetDefaults()
It resets the static defaults for the standard representation.The following defaults will be reapplied:
maxLengthForSingleLineDescription = 80
maxElementsForPrinting = 1000
-
setMaxLengthForSingleLineDescription
public static void setMaxLengthForSingleLineDescription(int value)
-
getMaxLengthForSingleLineDescription
public static int getMaxLengthForSingleLineDescription()
-
setMaxElementsForPrinting
public static void setMaxElementsForPrinting(int value)
-
registerFormatterForType
public 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. All instances of the given type will be formatted with the provided formatter.
-
removeAllRegisteredFormatters
public static void removeAllRegisteredFormatters()
Clear all formatters registered per type withregisterFormatterForType(Class, Function)
.
-
toStringOf
public java.lang.String toStringOf(java.lang.Object object)
Returns standard thetoString
representation of the given object. It may or not the object's own implementation oftoString
.- Specified by:
toStringOf
in interfaceRepresentation
- Parameters:
object
- the given object.- Returns:
- the
toString
representation of the given object.
-
customFormat
protected <T> java.lang.String customFormat(T object)
-
hasCustomFormatterFor
protected boolean hasCustomFormatterFor(java.lang.Object object)
-
unambiguousToStringOf
public java.lang.String unambiguousToStringOf(java.lang.Object obj)
Description copied from interface:Representation
Returns theString
representation of the given object with its type and hexadecimal hash code so that it can be differentied from other objects with the sameRepresentation.toStringOf(Object)
representation.- Specified by:
unambiguousToStringOf
in interfaceRepresentation
- Parameters:
obj
- the object to represent.- Returns:
- the
toString
representation of the given object.
-
toStringOf
protected java.lang.String toStringOf(java.lang.Number number)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicBoolean atomicBoolean)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicInteger atomicInteger)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicLong atomicLong)
-
toStringOf
protected java.lang.String toStringOf(java.util.Comparator<?> comparator)
-
toStringOf
protected java.lang.String toStringOf(java.util.Calendar c)
-
toStringOf
protected java.lang.String toStringOf(java.lang.Class<?> c)
-
toStringOf
protected java.lang.String toStringOf(java.lang.String s)
-
toStringOf
protected java.lang.String toStringOf(java.lang.Character c)
-
toStringOf
protected java.lang.String toStringOf(PredicateDescription p)
-
toStringOf
protected java.lang.String toStringOf(java.util.Date d)
-
toStringOf
protected java.lang.String toStringOf(java.lang.Float f)
-
toStringOf
protected java.lang.String toStringOf(java.lang.Long l)
-
toStringOf
protected java.lang.String toStringOf(java.io.File f)
-
toStringOf
protected java.lang.String toStringOf(java.text.SimpleDateFormat dateFormat)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.CompletableFuture<?> future)
-
toStringOf
protected java.lang.String toStringOf(Tuple tuple)
-
toStringOf
protected java.lang.String toStringOf(MapEntry<?,?> mapEntry)
-
toStringOf
protected java.lang.String toStringOf(java.util.Map<?,?> map)
-
toSortedMapIfPossible
private static java.util.Map<?,?> toSortedMapIfPossible(java.util.Map<?,?> map)
-
format
private java.lang.String format(java.util.Map<?,?> map, java.lang.Object o)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicReference<?> atomicReference)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicMarkableReference<?> atomicMarkableReference)
-
toStringOf
protected java.lang.String toStringOf(java.util.concurrent.atomic.AtomicStampedReference<?> atomicStampedReference)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
formatArray
protected java.lang.String formatArray(java.lang.Object o)
Returns theString
representation of the given array, ornull
if the given object is eithernull
or not an array. This method supports arrays having other arrays as elements.- Parameters:
o
- the object that is expected to be an array.- Returns:
- the
String
representation of the given array.
-
multiLineFormat
protected java.lang.String multiLineFormat(Representation representation, java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)
-
singleLineFormat
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)
-
smartFormat
protected java.lang.String smartFormat(Representation representation, java.lang.Object[] iterable)
-
format
protected java.lang.String format(java.lang.Object[] array, java.lang.String elementSeparator, java.lang.String indentation, java.util.Set<java.lang.Object[]> alreadyFormatted)
-
formatPrimitiveArray
protected java.lang.String formatPrimitiveArray(java.lang.Object o)
-
format
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)
-
multiLineFormat
protected java.lang.String multiLineFormat(java.lang.Iterable<?> iterable)
-
singleLineFormat
protected java.lang.String singleLineFormat(java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end)
-
smartFormat
protected java.lang.String smartFormat(java.lang.Iterable<?> iterable)
Returns theString
representation of the givenIterable
, ornull
if the givenIterable
isnull
.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.- Parameters:
iterable
- theIterable
to format.- Returns:
- the
String
representation of the givenIterable
.
-
doesDescriptionFitOnSingleLine
private static boolean doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription)
-
-