ca.quine.jcommons.sourcegen
Class FormattingUtils

java.lang.Object
  |
  +--ca.quine.jcommons.sourcegen.FormattingUtils

public class FormattingUtils
extends Object


Method Summary
static void addSpaceToLastEntry(ArrayList retVal)
           
static void addSpaceToLastEntryIfNotThere(ArrayList retVal)
           
static String formatCodeLine(FormattingRules formatRules, String codeLine)
          If the given FormattingRules use spaces for indenting, convert any tabs at the beginning of the line into the appropriate number of spaces.
static ArrayList formatList(FormattingRules rules, ArrayList items, int initialIndent, int subsequentIndent)
          Take the ArrayList of Strings (must contain at least 1 String) and format them onto lines as defined by the given rules.
static ArrayList formatList(FormattingRules rules, ArrayList items, int indentLevel, String prefix)
          Take the ArrayList of Strings (must contain at least 1 String and each String must contain appropriate trailing spacing) and format them onto lines as defined by the given rules with the given prefix on each line.
static ArrayList makeCommaSeparatedList(String prefix, ArrayList items, String suffix, boolean addPrefixSuffixIfNoItems)
          Makes a comma separated list that can then be used with formatList.
static void outputLines(FormattingRules formatRules, ArrayList lines, StringBuffer buffer)
          Outputs the already formatted and indented lines into the given StringBuffer.
static ArrayList tokenize(String text)
           
static String trimRight(String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatList

public static ArrayList formatList(FormattingRules rules,
                                   ArrayList items,
                                   int initialIndent,
                                   int subsequentIndent)
Take the ArrayList of Strings (must contain at least 1 String) and format them onto lines as defined by the given rules.

Parameters:
rules - the desired rules for formatting
items - a list of String objects which are to be formatted on one or more lines with spaces in between them
initialIndent - the number of indents on the first formatted line
subsequentIndent - the number of indents on each subsequent line
Returns:
a list of String objects, each one representing a formatted line of data

formatList

public static ArrayList formatList(FormattingRules rules,
                                   ArrayList items,
                                   int indentLevel,
                                   String prefix)
Take the ArrayList of Strings (must contain at least 1 String and each String must contain appropriate trailing spacing) and format them onto lines as defined by the given rules with the given prefix on each line. Each String in the List must contain spacing after it indicating the amount of spacing that is required. For example, the word that ends a sentence could be a String that contains two trailing spaces. These spaces will be added if another word follows that one on the same line. If one of the Strings in the List is the character "\n", it will be treated as a paragraph break.

Parameters:
rules - the desired rules for formatting
items - a list of String objects which are to be formatted on one or more lines with spaces in between them
indentLevel - the number of indents on the first formatted line
prefix - added to each line after the indent
Returns:
a list of String objects, each one representing a formatted line of data

trimRight

public static String trimRight(String string)

makeCommaSeparatedList

public static ArrayList makeCommaSeparatedList(String prefix,
                                               ArrayList items,
                                               String suffix,
                                               boolean addPrefixSuffixIfNoItems)
Makes a comma separated list that can then be used with formatList.

Parameters:
items - a list of String objects
Returns:
a list of String objects, with a comma added to the end of each of the input items except for the last String.

outputLines

public static void outputLines(FormattingRules formatRules,
                               ArrayList lines,
                               StringBuffer buffer)
Outputs the already formatted and indented lines into the given StringBuffer.

Parameters:
formatRules -
lines -
buffer -

formatCodeLine

public static String formatCodeLine(FormattingRules formatRules,
                                    String codeLine)
If the given FormattingRules use spaces for indenting, convert any tabs at the beginning of the line into the appropriate number of spaces. Otherwise, simply return the given String.

Parameters:
formatRules - the desired rules for formatting
codeLine - the line to reformat
Returns:
the reformatted line

tokenize

public static ArrayList tokenize(String text)

addSpaceToLastEntry

public static void addSpaceToLastEntry(ArrayList retVal)

addSpaceToLastEntryIfNotThere

public static void addSpaceToLastEntryIfNotThere(ArrayList retVal)