Class Align

java.lang.Object
  extended by Align

public final class Align
extends java.lang.Object

A class to right-align, center-align, or left-align an expression in a field of a specified width. The expression may be a String, int or double, The expression is converted to a String (if not already a String) and padded with the correct number of spaces to make its length equal to the specified width. Note: If the width specified is too small to accomodate the entire expression, then the width is ignored and the expression is neither padded nor truncated.


Constructor Summary
Align()
           
 
Method Summary
static java.lang.String center(double number, int width)
          Center-align a double expression in a field of a specified width
static java.lang.String center(double number, int width, int places)
          Round a double to a specified number of decimal places and center it in a field of a specified width.
static java.lang.String center(int number, int width)
          Center-align an int in a field of a specified width
static java.lang.String center(java.lang.String aString, int width)
          Center-align a string in a field of a specified width
static java.lang.String currency(double number, int width)
          Formats a double expression as US currency and right-aligns it in a field of a specified width.
static java.lang.String left(double number, int width)
          Left-align a double expression in a field of a specified width
static java.lang.String left(double number, int width, int places)
          Round a double to a specified number of decimal places and left-align it in a field of a specified width.
static java.lang.String left(int number, int width)
          Left-align an int in a field of a specified width
static java.lang.String left(java.lang.String aString, int width)
          Left-align a string in a field of a specified width
static java.lang.String right(double number, int width)
          Right-align a double expression in a field of a specified width
static java.lang.String right(double number, int width, int places)
          Round a double to a specified number of decimal places and right-align it in a field of a specified width.
static java.lang.String right(int number, int width)
          Right-align an int in a field of a specified width
static java.lang.String right(java.lang.String aString, int width)
          Right-align a string in a field of a specified width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Align

public Align()
Method Detail

right

public static java.lang.String right(java.lang.String aString,
                                     int width)
Right-align a string in a field of a specified width

Parameters:
aString - the string to be aligned
width - the width (number of spaces) of the field
Returns:
the string "padded" with the correct number of leading spaces, if necessary, to right-align it in the field

left

public static java.lang.String left(java.lang.String aString,
                                    int width)
Left-align a string in a field of a specified width

Parameters:
aString - the string to be aligned
width - the width (number of spaces) of the field
Returns:
the string "padded" with the correct number of trailing spaces, if necessary, to left-align it in the field

center

public static java.lang.String center(java.lang.String aString,
                                      int width)
Center-align a string in a field of a specified width

Parameters:
aString - the string to be aligned
width - the width (number of spaces) of the field
Returns:
the string "padded" with the correct number of leading and trailing spaces, if necessary, to center it in the field

right

public static java.lang.String right(int number,
                                     int width)
Right-align an int in a field of a specified width

Parameters:
number - the int to be aligned
width - the width (number of spaces) of the field
Returns:
the int converted to a string and padded with the correct number of leading spaces, if necessary, to right-align it in the field

left

public static java.lang.String left(int number,
                                    int width)
Left-align an int in a field of a specified width

Parameters:
number - the int to be aligned
width - the width (number of spaces) of the field
Returns:
the int converted to a string and padded with the correct number of trailing spaces, if necessary, to left-align it in the field

center

public static java.lang.String center(int number,
                                      int width)
Center-align an int in a field of a specified width

Parameters:
number - the int to be aligned
width - the width (number of spaces) of the field
Returns:
the int converted to a string and padded with the correct number of leading and trailing spaces, if necessary, to center it in the field

right

public static java.lang.String right(double number,
                                     int width)
Right-align a double expression in a field of a specified width

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
Returns:
the double value converted to a string and padded with the correct number of leading spaces, if necessary, to right-align it in the field

currency

public static java.lang.String currency(double number,
                                        int width)
Formats a double expression as US currency and right-aligns it in a field of a specified width. Note: width must be one greater than for the same value formatted as "non-currency," to accomodate the "$"

Parameters:
number - the value to be expressed as currency
width - the width (number of spaces) of the field
Returns:
a String consisting of the correct number of leading spaces, if necessary, for right-alignment, the dollar sign ($), and the number rounded to 2 decimal places

left

public static java.lang.String left(double number,
                                    int width)
Left-align a double expression in a field of a specified width

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
Returns:
the double value converted to a string and padded with the correct number of trailing spaces, if necessary, to left-align it in the field

center

public static java.lang.String center(double number,
                                      int width)
Center-align a double expression in a field of a specified width

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
Returns:
the double value converted to a string and padded with the correct number of leading and trailing spaces, if necessary, to center it in the field

right

public static java.lang.String right(double number,
                                     int width,
                                     int places)
Round a double to a specified number of decimal places and right-align it in a field of a specified width.

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
places - the number of decimal places to which number is rounded
Returns:
the double, rounded to the correct number of decimal places, converted to a string, and padded with the correct number of leading spaces (if necessary) to right-align it in the field

left

public static java.lang.String left(double number,
                                    int width,
                                    int places)
Round a double to a specified number of decimal places and left-align it in a field of a specified width.

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
places - the number of decimal places to which number is rounded
Returns:
the double, rounded to the correct number of decimal places, converted to a string, and padded with the correct number of trailing spaces (if necessary) to left-align it in the field

center

public static java.lang.String center(double number,
                                      int width,
                                      int places)
Round a double to a specified number of decimal places and center it in a field of a specified width.

Parameters:
number - the double to be rounded and aligned
width - the width (number of spaces) of the field
places - the number of decimal places to which number is rounded
Returns:
the double, rounded to the correct number of decimal places, converted to a string, and padded with the correct number of leading and trailing spaces (if necessary) to center it in the field