logahawk.formatters
Class ConcatCollectionArgFormatter

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

@Immutable
public class ConcatCollectionArgFormatter
extends CollectionArgFormatter

Concatonates all objects in the Collections together into a single String. This is a good formatter when you are trying to build a sentence as opposed to a list. The flexibility of this formatter allows it to create results with or without line breaks. For a list containing the strings "Alpha", "Beta", and "Gamma", and no separator, the output will look like:

AlphaBetaGamma
For a list containing the strings "Alpha", "Beta", and "Gamma", and a single space separator, the output will look like:
Alpha Beta Gamma


Field Summary
protected  String prefix
          Prefix to be prepended to each item in the output.
protected  String separator
          Separator between items in the output.
protected  String suffix
          Prefix to be appended to each item in the output.
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
ConcatCollectionArgFormatter()
           
ConcatCollectionArgFormatter(String separator)
           
ConcatCollectionArgFormatter(String separator, String prefix, String suffix)
           
 
Method Summary
 StringBuilder createStringBuilder(List<String> values)
          Creates a StringBuilder of the appropriate size to avoid re-allocation.
 String format(List<String> values)
          Formats the provided object into a list of objects, displaying the index before each item.
 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

separator

protected final String separator
Separator between items in the output. Default is a single space.


prefix

protected final String prefix
Prefix to be prepended to each item in the output. Default is empty string.


suffix

protected final String suffix
Prefix to be appended to each item in the output. Default is empty string.

Constructor Detail

ConcatCollectionArgFormatter

public ConcatCollectionArgFormatter()

ConcatCollectionArgFormatter

public ConcatCollectionArgFormatter(String separator)

ConcatCollectionArgFormatter

public ConcatCollectionArgFormatter(String separator,
                                    String prefix,
                                    String suffix)
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. If there is only one item, this will simply format that one item and return it, without all the index and other formatting. The provided formatters will be used to format each item, using AbstractArgumentFormatter.getChildObjectFormat(java.lang.Object, java.util.Collection, int).


format

public String format(List<String> values)
Formats the provided object into a list of objects, displaying the index before each item. If there is only one item, this will simply format that one item and return it, without all the index and other formatting. The provided formatters will be used to format each item, using AbstractArgumentFormatter.getChildObjectFormat(java.lang.Object, java.util.Collection, int).


createStringBuilder

public StringBuilder createStringBuilder(List<String> values)
Creates a StringBuilder of the appropriate size to avoid re-allocation. While this method requires a full scan of the list, the savings are generally worth it because of the number of times re-allocation could occur and the linear cost of re-allocation. We are trading one guaranteed O(N) operations (scanning the list) with an unknown number of O(N) operations (re-allocations).