logahawk.formatters
Class MapArgFormatter

java.lang.Object
  extended by logahawk.formatters.AbstractArgumentFormatter
      extended by logahawk.formatters.CollectionArgFormatter
          extended by logahawk.formatters.AbstractCollectionArgFormatter
              extended by 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.
 
Fields inherited from class logahawk.formatters.AbstractCollectionArgFormatter
concat, formatSingleSpecial, maxItems
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
MapArgFormatter()
           
MapArgFormatter(int maxItems, String separator)
           
MapArgFormatter(String separator)
           
 
Method Summary
 boolean canFormat(Object obj)
          Formats anything that implements Iterable.
 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.
protected  String formatHeader(Collection<?> coll)
          Returns a header string, which will be the first item displayed.
protected  String formatObj(Object obj, int index, Collection<ArgumentFormatter> formatters, int indentLevel)
          Formats a single object at the provided index.
 
Methods inherited from class logahawk.formatters.AbstractCollectionArgFormatter
formatFooter, formatList, formatSingleObj
 
Methods inherited from class logahawk.formatters.AbstractArgumentFormatter
findFormatter, getChildObjectFormat, getIndentor, setIndentor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

separator

protected final String separator
The separator between the key and value. By default this is " -> ". Leading and trailing spaces are not added automatically.

Constructor Detail

MapArgFormatter

public MapArgFormatter()

MapArgFormatter

public MapArgFormatter(String separator)

MapArgFormatter

public MapArgFormatter(int maxItems,
                       String separator)
Method Detail

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.