logahawk
Class SimpleIndentor

java.lang.Object
  extended by logahawk.SimpleIndentor
All Implemented Interfaces:
Indentor

@Immutable
public class SimpleIndentor
extends Object
implements Indentor

Simple implementation of Indentor that repeats a provided string for the indent. Instances of this class should be shared between ArgumentFormatters where possible, as this class uses an internal cache to speed up calls to buildIndent(int) for the common cases.


Field Summary
static SimpleIndentor SPACE_1
          A single space (ie: " ") reusable SimpleIndentor instance.
static SimpleIndentor SPACE_2
          A double space (ie: " ") reusable SimpleIndentor instance.
static SimpleIndentor SPACE_4
          Four spaces (ie: " ") reusable SimpleIndentor instance.
static SimpleIndentor SPACE_8
          Eight spaces (ie: " ") reusable SimpleIndentor instance.
static SimpleIndentor TAB
          Tab character (ie: "\t") reusable SimpleIndentor instance.
 
Constructor Summary
SimpleIndentor(String singleIndent)
           
 
Method Summary
protected  String buildIndent(int indentLevel)
          Creates indents strings; does not use cache.
 String createIndent(int indentLevel)
          Returns the string that should be used for indenting.
 String getSingleIndent()
          The string used for a single indent (ie: indent level 1).
 void indent(List<String> values, int indentLevel, boolean indentFirstLine)
          Indents a collection of Strings, replacing the un-indented strings with indented Strings.
 void indent(List<String> values, List<Integer> indentLevels)
          Indents a collection of strings, replacing the un-indented strings with indented Strings of varying indent levels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPACE_1

public static final SimpleIndentor SPACE_1
A single space (ie: " ") reusable SimpleIndentor instance.


SPACE_2

public static final SimpleIndentor SPACE_2
A double space (ie: " ") reusable SimpleIndentor instance.


SPACE_4

public static final SimpleIndentor SPACE_4
Four spaces (ie: " ") reusable SimpleIndentor instance.


SPACE_8

public static final SimpleIndentor SPACE_8
Eight spaces (ie: " ") reusable SimpleIndentor instance.


TAB

public static final SimpleIndentor TAB
Tab character (ie: "\t") reusable SimpleIndentor instance.

Constructor Detail

SimpleIndentor

public SimpleIndentor(String singleIndent)
Method Detail

getSingleIndent

public String getSingleIndent()
The string used for a single indent (ie: indent level 1).


createIndent

public String createIndent(int indentLevel)
Description copied from interface: Indentor
Returns the string that should be used for indenting.

Specified by:
createIndent in interface Indentor

indent

public void indent(List<String> values,
                   int indentLevel,
                   boolean indentFirstLine)
Description copied from interface: Indentor
Indents a collection of Strings, replacing the un-indented strings with indented Strings. This method is designed to simplify creating a correctly indented multi-line value. You can build the list of Strings without worrying about indenting, pass them to this method to have those Strings correctly indented.

Specified by:
indent in interface Indentor
Parameters:
values - It is HIGHLY RECOMMENDED that this collection have O(1) get and set operations.
indentFirstLine - Whether to indent the first line or not. For most uses this will be false, in accordance with the behavior expected by ArgumentFormatter.format(Object, Collection, int)

indent

public void indent(List<String> values,
                   List<Integer> indentLevels)
Description copied from interface: Indentor
Indents a collection of strings, replacing the un-indented strings with indented Strings of varying indent levels. This is similar to Indentor.indent(List, int, boolean) except that each String is indented a variable number of times AND the first line will be indented (if desired). The index used by the "values" parameter is used to find the indent level in parameter "indentLevels".

Specified by:
indent in interface Indentor
Parameters:
values - It is HIGHLY RECOMMENDED that this collection have O(1) get and set operations.

buildIndent

protected String buildIndent(int indentLevel)
Creates indents strings; does not use cache.