logahawk.formatters
Class MapArgFormatter
java.lang.Object
logahawk.formatters.AbstractArgumentFormatter
logahawk.formatters.CollectionArgFormatter
logahawk.formatters.AbstractCollectionArgFormatter
logahawk.formatters.MapArgFormatter
- All Implemented Interfaces:
- ArgumentFormatter
@Immutable
public class MapArgFormatter
- extends AbstractCollectionArgFormatter
Formats a map object to be output as "[index] key -> value". The index is automatically generated by this class, and
is output to improve read-ability.
This sets AbstractCollectionArgFormatter.formatSingleSpecial
to false; this does not handle a single item in any special way.
Field Summary |
protected String |
separator
The separator between the key and value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
separator
protected final String separator
- The separator between the key and value. By default this is " -> ". Leading and trailing spaces are not added
automatically.
MapArgFormatter
public MapArgFormatter()
MapArgFormatter
public MapArgFormatter(String separator)
MapArgFormatter
public MapArgFormatter(int maxItems,
String separator)
canFormat
public boolean canFormat(Object obj)
- Description copied from class:
CollectionArgFormatter
- Formats anything that implements
Iterable
.
- Specified by:
canFormat
in interface ArgumentFormatter
- Overrides:
canFormat
in class CollectionArgFormatter
formatHeader
protected String formatHeader(Collection<?> coll)
- Description copied from class:
AbstractCollectionArgFormatter
- Returns a header string, which will be the first item displayed. The default implementation displays "(### items in
collection)".
- Overrides:
formatHeader
in class AbstractCollectionArgFormatter
- Returns:
- Null if no header desired.
formatObj
protected String formatObj(Object obj,
int index,
Collection<ArgumentFormatter> formatters,
int indentLevel)
- Description copied from class:
AbstractCollectionArgFormatter
- Formats a single object at the provided index. The default implementation simply calls
AbstractArgumentFormatter.getChildObjectFormat(Object, Collection, int)
.
- Overrides:
formatObj
in class AbstractCollectionArgFormatter
index
- The 0-based index of this item in the original collection.indentLevel
- The indent will be one larger than the caller, there is no need to increment by one.
format
public String format(Object obj,
Collection<ArgumentFormatter> formatters,
int indentLevel)
- Formats the provided object into a map of objects, displaying the index before each key value pair. The provided
formatters will be used to format both key and value, using
AbstractArgumentFormatter.getChildObjectFormat(java.lang.Object, java.util.Collection, int)
.
If no items are in the map, an empty string will be returned.