com.ibm.are.common
Class AlignableString

java.lang.Object
  extended by com.ibm.are.common.AlignableString

public class AlignableString
extends java.lang.Object

The AlignableString class is a simple way to create a Java String that can be left, center, or right aligned. Alignment is achieved by specifying a fixed size for the string, and a character to use to pad the string if its length is less than the specified fixed size.. The default pad character is a space. This class is very useful for creating tables of strings where each column has a fixed width, but the length of the strings within the columns may vary.

Version:
1.0
Author:
IBM

Field Summary
protected  java.lang.String alignedString
          The aligned string
static int CENTER_ALIGN
          Center align the string
static java.lang.String COPYRIGHT
          Copyright for class bytecode
static int LEFT_ALIGN
          Left align the string
static int RIGHT_ALIGN
          Right align the string
 
Constructor Summary
AlignableString(java.lang.String str, int totalSize, int alignment)
          Constructs an AlignableString object with the specified string text, total size, and alignment.
AlignableString(java.lang.String str, int totalSize, int alignment, char padChar)
          Constructs an AlignableString object with the specified string text, total size, alignment, and pad character.
 
Method Summary
 java.lang.String getString()
          Retrieves the aligned string
 int length()
          Retrieves the length, in characters, of the aligned string.
 java.lang.String toString()
          Retrieves the aligned string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Copyright for class bytecode

See Also:
Constant Field Values

LEFT_ALIGN

public static final int LEFT_ALIGN
Left align the string

See Also:
Constant Field Values

RIGHT_ALIGN

public static final int RIGHT_ALIGN
Right align the string

See Also:
Constant Field Values

CENTER_ALIGN

public static final int CENTER_ALIGN
Center align the string

See Also:
Constant Field Values

alignedString

protected java.lang.String alignedString
The aligned string

Constructor Detail

AlignableString

public AlignableString(java.lang.String str,
                       int totalSize,
                       int alignment)
Constructs an AlignableString object with the specified string text, total size, and alignment. The pad character will default to the space character.

Parameters:
str - The text string to align
totalSize - The total number of characters, i.e. length, of the alignable string
alignment - How to align the string. Must be LEFT_ALIGN, CENTER_ALIGN, or RIGHT_ALIGN

AlignableString

public AlignableString(java.lang.String str,
                       int totalSize,
                       int alignment,
                       char padChar)
Constructs an AlignableString object with the specified string text, total size, alignment, and pad character.

Parameters:
str - The text string to align
totalSize - The total number of characters, i.e. length, of the alignable string
alignment - How to align the string. Must be LEFT_ALIGN, CENTER_ALIGN, or RIGHT_ALIGN
padChar - The character used to pad the string so that its length equals totalSize
Method Detail

getString

public java.lang.String getString()
Retrieves the aligned string

Returns:
The aligned string

length

public int length()
Retrieves the length, in characters, of the aligned string.

Returns:
The length, in characters, of the aligned string.

toString

public java.lang.String toString()
Retrieves the aligned string. This method is the same as invoking the getString() method.

Overrides:
toString in class java.lang.Object
Returns:
The aligned string