logahawk.formatters
Class AbstractCollectionArgFormatter

java.lang.Object
  extended by logahawk.formatters.AbstractArgumentFormatter
      extended by logahawk.formatters.CollectionArgFormatter
          extended by logahawk.formatters.AbstractCollectionArgFormatter
All Implemented Interfaces:
ArgumentFormatter
Direct Known Subclasses:
MapArgFormatter, MultiLineCollectionArgFormatter

@Immutable
public abstract class AbstractCollectionArgFormatter
extends CollectionArgFormatter

Abstract base class for ArgumentFormatters that writes each object in the Collections on a single line. This is a sibling class to ConcatCollectionArgFormatter, which is best suited for formatting objects into a single-line. The output is of the form:

   Header
   Item
   Item
   Item
   ...
   Footer
 
The header and footer are output only if there is at least one item. If there is only one item, the flag formatSingleSpecial will be used to determine behavior.


Field Summary
protected  ConcatCollectionArgFormatter concat
          Used to merge the formatted lines into one big String with the appropriate new lines.
protected  boolean formatSingleSpecial
          If true this will format a list with a single object using formatSingleObj(Object, Collection, int) without any call to formatHeader(Collection) or formatFooter(Collection, int).
protected  int maxItems
          Signals the maximum number of items to display.
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
protected AbstractCollectionArgFormatter(boolean formatSingleSpecial, int maxItems)
           
 
Method Summary
protected  String formatFooter(Collection<?> coll, int numUsed)
          Returns a footer string, which will be the last item displayed.
protected  String formatHeader(Collection<?> coll)
          Returns a header string, which will be the first item displayed.
protected  String formatList(Collection<?> coll, Collection<ArgumentFormatter> formatters, int indentLevel)
           
protected  String formatObj(Object obj, int index, Collection<ArgumentFormatter> formatters, int indentLevel)
          Formats a single object at the provided index.
protected  String formatSingleObj(Object obj, Collection<ArgumentFormatter> formatters, int indentLevel)
          Special formatting request when the collection contains only one item.
 
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
 
Methods inherited from interface logahawk.formatters.ArgumentFormatter
format
 

Field Detail

concat

protected final ConcatCollectionArgFormatter concat
Used to merge the formatted lines into one big String with the appropriate new lines.


formatSingleSpecial

protected final boolean formatSingleSpecial
If true this will format a list with a single object using formatSingleObj(Object, Collection, int) without any call to formatHeader(Collection) or formatFooter(Collection, int). A true value essentially "unpacks" the one item and reacts as if there were no containing list.


maxItems

protected final int maxItems
Signals the maximum number of items to display. This is used to prevent very long collections from flooding the log with more data than is useful. The default is 16 items. The formatFooter(Collection, int) can be used to display how many items were not logged.

Constructor Detail

AbstractCollectionArgFormatter

protected AbstractCollectionArgFormatter(boolean formatSingleSpecial,
                                         int maxItems)
Method Detail

formatList

protected String formatList(Collection<?> coll,
                            Collection<ArgumentFormatter> formatters,
                            int indentLevel)

formatHeader

protected String formatHeader(Collection<?> coll)
Returns a header string, which will be the first item displayed. The default implementation displays "(### items in collection)".

Returns:
Null if no header desired.

formatFooter

protected String formatFooter(Collection<?> coll,
                              int numUsed)
Returns a footer string, which will be the last item displayed. The default implementation displays "(### items hidden)" only if items are hidden.

Parameters:
numUsed - Number of items actually formatted and displayed.
Returns:
Null if no footer desired.

formatSingleObj

protected String formatSingleObj(Object obj,
                                 Collection<ArgumentFormatter> formatters,
                                 int indentLevel)
Special formatting request when the collection contains only one item. The default implementation simply calls AbstractArgumentFormatter.getChildObjectFormat(Object, Collection, int).

Parameters:
indentLevel - The indent will be one larger than the caller, there is no need to increment by one.

formatObj

protected String formatObj(Object obj,
                           int index,
                           Collection<ArgumentFormatter> formatters,
                           int indentLevel)
Formats a single object at the provided index. The default implementation simply calls AbstractArgumentFormatter.getChildObjectFormat(Object, Collection, int).

Parameters:
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.