org.cert.cc.util
Class Formatter

java.lang.Object
  extended by org.cert.cc.util.Formatter

public class Formatter
extends Object

Support for a macro for use in velocity to set fixed widths. Call setFieldLengths to initialize before using padField. Note: Not thread safe.

Author:
brubbo

Constructor Summary
Formatter()
           
 
Method Summary
 String pad(String string, int width)
          Pads the input string with spaces to the width specified.
 String padField(String fieldName, String fieldValue)
          Pads a field to a previously stored size set by setFieldLengths.
 String rightJustifyNumber(int number, int width)
          Right justifies the integer to the width specified.
 void setFieldLengths(Collection<String> fieldNames, Collection<Issue> issues, CustomFieldManager customFieldManager)
          This method goes through all the field values for each field and finds the largest string to set the field width for formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Formatter

public Formatter()
Method Detail

pad

public String pad(String string,
                  int width)
Pads the input string with spaces to the width specified.

Parameters:
string - - input string
width - - width of output
Returns:
- padded string

rightJustifyNumber

public String rightJustifyNumber(int number,
                                 int width)
Right justifies the integer to the width specified.

Parameters:
number - - number to format
width - - width to format the number to.
Returns:
- the padded number.

padField

public String padField(String fieldName,
                       String fieldValue)
Pads a field to a previously stored size set by setFieldLengths.

Parameters:
fieldName - - FieldName to look up for size.
fieldValue - - The value of the field to pad.
Returns:
- the padded field value.

setFieldLengths

public void setFieldLengths(Collection<String> fieldNames,
                            Collection<Issue> issues,
                            CustomFieldManager customFieldManager)
This method goes through all the field values for each field and finds the largest string to set the field width for formatting.

Parameters:
fieldNames - - Fields to record largest size for.
issues - - The issues to scan for the above fields
customFieldManager - - CustomFieldManager to allow handling of custom fields.


Copyright © 2012 Carnegie Mellon University