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>>customFormatterByTypeprivate static java.lang.StringDEFAULT_ENDprivate static java.lang.StringDEFAULT_MAX_ELEMENTS_EXCEEDEDprivate static java.lang.StringDEFAULT_STARTstatic java.lang.StringELEMENT_SEPARATORstatic java.lang.StringELEMENT_SEPARATOR_WITH_NEWLINE(package private) static java.lang.StringINDENTATION_AFTER_NEWLINE(package private) static java.lang.StringINDENTATION_FOR_SINGLE_LINEprivate static intmaxElementsForPrintingprivate static intmaxLengthForSingleLineDescriptionprivate static java.lang.StringNULLstatic StandardRepresentationSTANDARD_REPRESENTATIONprivate static java.lang.StringTUPLE_ENDprivate static java.lang.StringTUPLE_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.StringcustomFormat(T object)private static booleandoesDescriptionFitOnSingleLine(java.lang.String singleLineDescription)protected java.lang.StringfallbackToStringOf(java.lang.Object object)Returns theStringrepresentation of the given object.java.lang.Stringformat(java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end, java.lang.String elementSeparator, java.lang.String indentation)protected java.lang.Stringformat(java.lang.Object[] array, java.lang.String elementSeparator, java.lang.String indentation, java.util.Set<java.lang.Object[]> alreadyFormatted)private java.lang.Stringformat(java.util.Map<?,?> map, java.lang.Object o)protected java.lang.StringformatArray(java.lang.Object o)Returns theStringrepresentation of the given array, ornullif the given object is eithernullor not an array.private java.lang.StringformatLines(java.util.List<?> lines)protected java.lang.StringformatPrimitiveArray(java.lang.Object o)static intgetMaxElementsForPrinting()static intgetMaxLengthForSingleLineDescription()protected booleanhasCustomFormatterFor(java.lang.Object object)protected java.lang.StringmultiLineFormat(java.lang.Iterable<?> iterable)protected java.lang.StringmultiLineFormat(java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)static <T> voidregisterFormatterForType(java.lang.Class<T> type, java.util.function.Function<T,java.lang.String> formatter)Registers new formatter for the given type.static voidremoveAllRegisteredFormatters()Clear all formatters registered per type withregisterFormatterForType(Class, Function).static voidresetDefaults()It resets the static defaults for the standard representation.static voidsetMaxElementsForPrinting(int value)static voidsetMaxLengthForSingleLineDescription(int value)protected java.lang.StringsingleLineFormat(java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end)protected java.lang.StringsingleLineFormat(java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)protected java.lang.StringsmartFormat(java.lang.Iterable<?> iterable)Returns theStringrepresentation of the givenIterable, ornullif the givenIterableisnull.protected java.lang.StringsmartFormat(java.lang.Object[] iterable)private static java.util.Map<?,?>toSortedMapIfPossible(java.util.Map<?,?> map)java.lang.StringtoString()protected java.lang.StringtoStringOf(java.io.File file)protected java.lang.StringtoStringOf(java.lang.Character c)protected java.lang.StringtoStringOf(java.lang.Class<?> c)protected java.lang.StringtoStringOf(java.lang.Float f)protected java.lang.StringtoStringOf(java.lang.Long l)protected java.lang.StringtoStringOf(java.lang.Number number)java.lang.StringtoStringOf(java.lang.Object object)Returns standard thetoStringrepresentation of the given object.protected java.lang.StringtoStringOf(java.lang.String s)protected java.lang.StringtoStringOf(java.text.SimpleDateFormat dateFormat)protected java.lang.StringtoStringOf(java.util.Calendar c)protected java.lang.StringtoStringOf(java.util.Comparator<?> comparator)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicBoolean atomicBoolean)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicInteger atomicInteger)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicLong atomicLong)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicMarkableReference<?> atomicMarkableReference)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicReference<?> atomicReference)protected java.lang.StringtoStringOf(java.util.concurrent.atomic.AtomicStampedReference<?> atomicStampedReference)protected java.lang.StringtoStringOf(java.util.concurrent.CompletableFuture<?> future)protected java.lang.StringtoStringOf(java.util.Date d)protected java.lang.StringtoStringOf(java.util.Map<?,?> map)protected java.lang.StringtoStringOf(MapEntry<?,?> mapEntry)protected java.lang.StringtoStringOf(Tuple tuple)protected java.lang.StringtoStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)protected java.lang.StringtoStringOf(PredicateDescription p)private java.lang.StringtoStringOf(ChangeDelta<?> changeDelta)private java.lang.StringtoStringOf(DeleteDelta<?> deleteDelta)private java.lang.StringtoStringOf(InsertDelta<?> insertDelta)java.lang.StringunambiguousToStringOf(java.lang.Object obj)Returns theStringrepresentation of the given object with its type and hexadecimal identity hash code so that it can be differentiated 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
-
maxElementsForPrinting
private static int maxElementsForPrinting
-
customFormatterByType
private static final java.util.Map<java.lang.Class<?>,java.util.function.Function<?,java.lang.String>> customFormatterByType
-
-
Method Detail
-
resetDefaults
public static void resetDefaults()
-
setMaxLengthForSingleLineDescription
public static void setMaxLengthForSingleLineDescription(int value)
-
getMaxLengthForSingleLineDescription
public static int getMaxLengthForSingleLineDescription()
-
setMaxElementsForPrinting
public static void setMaxElementsForPrinting(int value)
-
getMaxElementsForPrinting
public static int getMaxElementsForPrinting()
-
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.- Type Parameters:
T- the type to register a formatter for- Parameters:
type- the class of the type to register a formatter forformatter- the 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 thetoStringrepresentation of the given object. It may or not the object's own implementation oftoString.- Specified by:
toStringOfin interfaceRepresentation- Parameters:
object- the given object.- Returns:
- the
toStringrepresentation 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:RepresentationReturns theStringrepresentation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the sameRepresentation.toStringOf(Object)representation.- Specified by:
unambiguousToStringOfin interfaceRepresentation- Parameters:
obj- the object to represent.- Returns:
- the unambiguous
toStringrepresentation of the given object.
-
fallbackToStringOf
protected java.lang.String fallbackToStringOf(java.lang.Object object)
Returns theStringrepresentation of the given object. This method is used as a last resort if none of theStandardRepresentationpredefined string representations were not called.- Parameters:
object- the object to represent (nevernull- Returns:
- to
toStringrepresentation for 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(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
-
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 file)
-
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)
-
toStringOf
private java.lang.String toStringOf(ChangeDelta<?> changeDelta)
-
toStringOf
private java.lang.String toStringOf(DeleteDelta<?> deleteDelta)
-
toStringOf
private java.lang.String toStringOf(InsertDelta<?> insertDelta)
-
formatLines
private java.lang.String formatLines(java.util.List<?> lines)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
formatArray
protected java.lang.String formatArray(java.lang.Object o)
Returns theStringrepresentation of the given array, ornullif the given object is eithernullor 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
Stringrepresentation of the given array.
-
multiLineFormat
protected java.lang.String multiLineFormat(java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)
-
singleLineFormat
protected java.lang.String singleLineFormat(java.lang.Object[] iterable, java.util.Set<java.lang.Object[]> alreadyFormatted)
-
smartFormat
protected java.lang.String smartFormat(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 theStringrepresentation of the givenIterable, ornullif the givenIterableisnull.The
Iterablewill 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- theIterableto format.- Returns:
- the
Stringrepresentation of the givenIterable.
-
doesDescriptionFitOnSingleLine
private static boolean doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription)
-
-