public class StandardRepresentation extends Object implements Representation
Modifier and Type | Field and Description |
---|---|
static String |
ELEMENT_SEPARATOR |
static String |
ELEMENT_SEPARATOR_WITH_NEWLINE |
static StandardRepresentation |
STANDARD_REPRESENTATION |
Constructor and Description |
---|
StandardRepresentation() |
Modifier and Type | Method and Description |
---|---|
protected <T> String |
customFormat(T object) |
protected String |
fallbackToStringOf(Object object)
Returns the
String representation of the given object. |
String |
format(Iterable<?> iterable,
String start,
String end,
String elementSeparator,
String indentation) |
protected String |
format(Object[] array,
String elementSeparator,
String indentation,
Set<Object[]> alreadyFormatted) |
protected String |
formatArray(Object o)
Returns the
String representation of the given array, or null if the given object is either
null or not an array. |
protected String |
formatPrimitiveArray(Object o) |
static int |
getMaxLengthForSingleLineDescription() |
protected boolean |
hasCustomFormatterFor(Object object) |
protected String |
multiLineFormat(Iterable<?> iterable) |
protected String |
multiLineFormat(Object[] iterable,
Set<Object[]> alreadyFormatted) |
static <T> void |
registerFormatterForType(Class<T> type,
Function<T,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 String |
singleLineFormat(Iterable<?> iterable,
String start,
String end) |
protected String |
singleLineFormat(Object[] iterable,
Set<Object[]> alreadyFormatted) |
protected String |
smartFormat(Iterable<?> iterable)
Returns the
String representation of the given Iterable , or null if the given
Iterable is null . |
protected String |
smartFormat(Object[] iterable) |
String |
toString() |
protected String |
toStringOf(AtomicBoolean atomicBoolean) |
protected String |
toStringOf(AtomicInteger atomicInteger) |
protected String |
toStringOf(AtomicLong atomicLong) |
protected String |
toStringOf(AtomicMarkableReference<?> atomicMarkableReference) |
protected String |
toStringOf(AtomicReference<?> atomicReference) |
protected String |
toStringOf(AtomicStampedReference<?> atomicStampedReference) |
protected String |
toStringOf(Calendar c) |
protected String |
toStringOf(Character c) |
protected String |
toStringOf(Class<?> c) |
protected String |
toStringOf(Comparator<?> comparator) |
protected String |
toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy) |
protected String |
toStringOf(CompletableFuture<?> future) |
protected String |
toStringOf(Date d) |
protected String |
toStringOf(File f) |
protected String |
toStringOf(Float f) |
protected String |
toStringOf(Long l) |
protected String |
toStringOf(Map<?,?> map) |
protected String |
toStringOf(MapEntry<?,?> mapEntry) |
protected String |
toStringOf(Number number) |
String |
toStringOf(Object object)
Returns standard the
toString representation of the given object. |
protected String |
toStringOf(PredicateDescription p) |
protected String |
toStringOf(SimpleDateFormat dateFormat) |
protected String |
toStringOf(String s) |
protected String |
toStringOf(Tuple tuple) |
String |
unambiguousToStringOf(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
public static final String ELEMENT_SEPARATOR
public static final String ELEMENT_SEPARATOR_WITH_NEWLINE
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(Class<T> type, Function<T,String> formatter)
T
- the type to register a formatter fortype
- the class of the type to register a formatter forformatter
- the formatterpublic static void removeAllRegisteredFormatters()
registerFormatterForType(Class, Function)
.public String toStringOf(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> String customFormat(T object)
protected boolean hasCustomFormatterFor(Object object)
public String unambiguousToStringOf(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 String fallbackToStringOf(Object object)
String
representation of the given object. This method is used as a last resort if none of
the StandardRepresentation
predefined string representations were not called.object
- the object to represent (never null
toString
representation for the given objectprotected String toStringOf(AtomicBoolean atomicBoolean)
protected String toStringOf(AtomicInteger atomicInteger)
protected String toStringOf(AtomicLong atomicLong)
protected String toStringOf(Comparator<?> comparator)
protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
protected String toStringOf(PredicateDescription p)
protected String toStringOf(SimpleDateFormat dateFormat)
protected String toStringOf(CompletableFuture<?> future)
protected String toStringOf(AtomicReference<?> atomicReference)
protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
protected String formatArray(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 String singleLineFormat(Object[] iterable, Set<Object[]> alreadyFormatted)
protected String format(Object[] array, String elementSeparator, String indentation, Set<Object[]> alreadyFormatted)
public String format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation)
protected String smartFormat(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
.Copyright © 2014–2018 AssertJ. All rights reserved.