logahawk.formatters
Class HierarchicalCollectionArgFormatter

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

@Immutable
public class HierarchicalCollectionArgFormatter
extends CollectionArgFormatter

Writes each object in the Collections in a way that shows a hierarchy between the objects. This formatter will create a single line result if no objects in the collection are multi-line (contain Logger.LINE_SEPARATOR, otherwise this formatter will create a multi-line result. The first object in the list is considered the root, the last object is considered the child. For single-line results, a ConcatCollectionArgFormatter will be used. This allows the separator to be different depending on single-line and multi-line results. This class assumes that the arguments are a hierarchy, but does not do any validation of that assumption. Therefore this class is not intended to be used in a generic ArgumentFormatterContainer, it is designed to be used in situations similar to the needs of ParentObjectArgFormatter. For a list containing the single-line strings "Alpha", "Beta", and "Gamma" (where "Gamma" is the child), and the inner ConcatCollectionArgFormatter's separator is " -> " the output will look like:

Alpha -> Beta -> Gama
For a list containing the three multi-line strings:
 Alpha
   First Line
   Second Line

 Beta
   First Line
   Second Line

 Gama
   First Line
   Second Line
 
(where "Gamma" is the child), with the multiLineSeparator is "|-- ", the output will look like:
  |-- Alpha
      First Line
      Second Line
     |-- Beta
         First Line
         Second Line
         |-- Gamma
             First Line
             Second Line
 


Field Summary
protected  ConcatCollectionArgFormatter concat
          Used to merge the formatted lines into one big String with the appropriate new lines.
protected  String multiLineSeparator
          Separator between items in the hierarchy.
protected  ConcatCollectionArgFormatter singleLineFormatter
          Used to format the message when none of the items in the hierarchy are multi-line.
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
HierarchicalCollectionArgFormatter()
           
HierarchicalCollectionArgFormatter(ConcatCollectionArgFormatter singleLineFormatter, String multiLineSeparator)
           
 
Method Summary
protected  String format(List<Object> list, Collection<ArgumentFormatter> formatters, int indentLevel)
           
 String format(Object obj, Collection<ArgumentFormatter> formatters, int indentLevel)
          Formats the provided object into a list of objects, displaying the index before each 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
 

Field Detail

concat

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


singleLineFormatter

protected final ConcatCollectionArgFormatter singleLineFormatter
Used to format the message when none of the items in the hierarchy are multi-line.


multiLineSeparator

protected final String multiLineSeparator
Separator between items in the hierarchy.

Constructor Detail

HierarchicalCollectionArgFormatter

public HierarchicalCollectionArgFormatter()

HierarchicalCollectionArgFormatter

public HierarchicalCollectionArgFormatter(ConcatCollectionArgFormatter singleLineFormatter,
                                          String multiLineSeparator)
Parameters:
multiLineSeparator -
singleLineFormatter -
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.


format

protected String format(List<Object> list,
                        Collection<ArgumentFormatter> formatters,
                        int indentLevel)