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 Object implements Representation
Standard java object representation.- Author:
- Mariusz Smykula
-
-
Field Summary
Fields Modifier and Type Field Description static StringELEMENT_SEPARATORstatic StringELEMENT_SEPARATOR_WITH_NEWLINEstatic StandardRepresentationSTANDARD_REPRESENTATION
-
Constructor Summary
Constructors Constructor Description StandardRepresentation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> StringcustomFormat(T object)Stringformat(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation)protected Stringformat(Object[] array, String elementSeparator, String indentation, Set<Object[]> alreadyFormatted)protected StringformatArray(Object o)Returns theStringrepresentation of the given array, ornullif the given object is eithernullor not an array.protected StringformatPrimitiveArray(Object o)static intgetMaxLengthForSingleLineDescription()protected booleanhasCustomFormatterFor(Object object)protected StringmultiLineFormat(Iterable<?> iterable)protected StringmultiLineFormat(Representation representation, Object[] iterable, Set<Object[]> alreadyFormatted)static <T> voidregisterFormatterForType(Class<T> type, Function<T,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 StringsingleLineFormat(Iterable<?> iterable, String start, String end)protected StringsingleLineFormat(Representation representation, Object[] iterable, String start, String end, Set<Object[]> alreadyFormatted)protected StringsmartFormat(Iterable<?> iterable)Returns theStringrepresentation of the givenIterable, ornullif the givenIterableisnull.protected StringsmartFormat(Representation representation, Object[] iterable)StringtoString()protected StringtoStringOf(File f)protected StringtoStringOf(Character c)protected StringtoStringOf(Class<?> c)protected StringtoStringOf(Float f)protected StringtoStringOf(Long l)protected StringtoStringOf(Number number)StringtoStringOf(Object object)Returns standard thetoStringrepresentation of the given object.protected StringtoStringOf(String s)protected StringtoStringOf(SimpleDateFormat dateFormat)protected StringtoStringOf(Calendar c)protected StringtoStringOf(Comparator<?> comparator)protected StringtoStringOf(AtomicBoolean atomicBoolean)protected StringtoStringOf(AtomicInteger atomicInteger)protected StringtoStringOf(AtomicLong atomicLong)protected StringtoStringOf(AtomicMarkableReference<?> atomicMarkableReference)protected StringtoStringOf(AtomicReference<?> atomicReference)protected StringtoStringOf(AtomicStampedReference<?> atomicStampedReference)protected StringtoStringOf(CompletableFuture<?> future)protected StringtoStringOf(Date d)protected StringtoStringOf(Map<?,?> map)protected StringtoStringOf(MapEntry<?,?> mapEntry)protected StringtoStringOf(Tuple tuple)protected StringtoStringOf(PredicateDescription p)StringunambiguousToStringOf(Object obj)Returns theStringrepresentation 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
-
ELEMENT_SEPARATOR
public static final String ELEMENT_SEPARATOR
- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR_WITH_NEWLINE
public static final String ELEMENT_SEPARATOR_WITH_NEWLINE
-
-
Method Detail
-
resetDefaults
public static void resetDefaults()
It resets the static defaults for the standard representation.The following defaults will be reapplied:
maxLengthForSingleLineDescription = 80maxElementsForPrinting = 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(Class<T> type, Function<T,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 String toStringOf(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> String customFormat(T object)
-
hasCustomFormatterFor
protected boolean hasCustomFormatterFor(Object object)
-
unambiguousToStringOf
public String unambiguousToStringOf(Object obj)
Description copied from interface:RepresentationReturns theStringrepresentation 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:
unambiguousToStringOfin interfaceRepresentation- Parameters:
obj- the object to represent.- Returns:
- the
toStringrepresentation of the given object.
-
toStringOf
protected String toStringOf(AtomicBoolean atomicBoolean)
-
toStringOf
protected String toStringOf(AtomicInteger atomicInteger)
-
toStringOf
protected String toStringOf(AtomicLong atomicLong)
-
toStringOf
protected String toStringOf(Comparator<?> comparator)
-
toStringOf
protected String toStringOf(PredicateDescription p)
-
toStringOf
protected String toStringOf(SimpleDateFormat dateFormat)
-
toStringOf
protected String toStringOf(CompletableFuture<?> future)
-
toStringOf
protected String toStringOf(AtomicReference<?> atomicReference)
-
toStringOf
protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
-
toStringOf
protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
-
formatArray
protected String formatArray(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 String multiLineFormat(Representation representation, Object[] iterable, Set<Object[]> alreadyFormatted)
-
singleLineFormat
protected String singleLineFormat(Representation representation, Object[] iterable, String start, String end, Set<Object[]> alreadyFormatted)
-
smartFormat
protected String smartFormat(Representation representation, Object[] iterable)
-
format
protected String format(Object[] array, String elementSeparator, String indentation, Set<Object[]> alreadyFormatted)
-
format
public String format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation)
-
smartFormat
protected String smartFormat(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.
-
-