logahawk.formatters
Class MultiLineCollectionArgFormatter

java.lang.Object
  extended by logahawk.formatters.AbstractArgumentFormatter
      extended by logahawk.formatters.CollectionArgFormatter
          extended by logahawk.formatters.AbstractCollectionArgFormatter
              extended by logahawk.formatters.MultiLineCollectionArgFormatter
All Implemented Interfaces:
ArgumentFormatter

@Immutable
public class MultiLineCollectionArgFormatter
extends AbstractCollectionArgFormatter

Writes each object in the Collections on a single line. Each line also prints an index to increase readability. For a list containing the strings "Alpha", "Beta", and "Gamma", the output will look like:

 (3 items in collection)
 [0] Alpha
 [1] Beta
 [2] Gama
 
This class sets AbstractCollectionArgFormatter.formatSingleSpecial to true, so a list with a single item will be treated as if it were just that single item.


Field Summary
 
Fields inherited from class logahawk.formatters.AbstractCollectionArgFormatter
concat, formatSingleSpecial, maxItems
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
MultiLineCollectionArgFormatter()
           
MultiLineCollectionArgFormatter(int maxItems)
           
 
Method Summary
 String format(Object obj, Collection<ArgumentFormatter> formatters, int indentLevel)
          Formats the provided object into a list of objects, displaying the index before each item.
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, formatHeader, formatList, formatSingleObj
 
Methods inherited from class logahawk.formatters.CollectionArgFormatter
canFormat
 
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
 

Constructor Detail

MultiLineCollectionArgFormatter

public MultiLineCollectionArgFormatter()

MultiLineCollectionArgFormatter

public MultiLineCollectionArgFormatter(int maxItems)
Method Detail

format

public String format(Object obj,
                     Collection<ArgumentFormatter> formatters,
                     int indentLevel)
Formats the provided object into a list of objects, displaying the index before each item. The provided formatters will be used to format each item, using AbstractArgumentFormatter.getChildObjectFormat(java.lang.Object, java.util.Collection, int). If there is only one item, this will simply format that one item and return it, without all the index and other formatting. (This is allows this formatter to quietly disappear in the single item case.) If no items are in the collection, an empty string will be returned.


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.