javabook
Class Format

java.lang.Object
  |
  +--javabook.Format

public class Format
extends java.lang.Object

This class is used to format the numerical and textual values for a properly aligned output display.

This class is provided as freeware. You are free to use as provided or modify to your heart's content. But you use it at your own risk. No implied or explicit warranty is given.


Constructor Summary
Format()
           
 
Method Summary
static java.lang.String centerAlign(int width, int decimalPlaces, double number)
          Formats a real number using the center alignment.
static java.lang.String centerAlign(int width, long number)
          Formats an integer using the center alignment.
static java.lang.String centerAlign(int width, java.lang.String str)
          Formats a String using the center alignment.
static java.lang.String leftAlign(int width, int decimalPlaces, double number)
          Formats a real number using the left alignment.
static java.lang.String leftAlign(int width, long number)
          Formats an integer using the left alignment.
static java.lang.String leftAlign(int width, java.lang.String str)
          Formats a String using the left alignment.
static java.lang.String rightAlign(int width, int decimalPlaces, double number)
          Formats a real number using the right alignment.
static java.lang.String rightAlign(int width, long number)
          Formats an integer using the right alignment.
static java.lang.String rightAlign(int width, java.lang.String str)
          Formats a String using the right alignment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format()
Method Detail

centerAlign

public static java.lang.String centerAlign(int width,
                                           int decimalPlaces,
                                           double number)
Formats a real number using the center alignment. The passed number is converted to a String with width characters. The number is placed at the center, and the second parameter decimalPlaces determines the number of decimal places to be shown. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - number of characters the resulting string will contain
decimalPlaces - the number of decimal places within the designated field width
number - the value to be formatted
Returns:
a formatted string

centerAlign

public static java.lang.String centerAlign(int width,
                                           long number)
Formats an integer using the center alignment. The passed number is converted to a String with width characters. The number is placed at the center. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
number - the integer value to be formatted
Returns:
a formatted string

centerAlign

public static java.lang.String centerAlign(int width,
                                           java.lang.String str)
Formats a String using the center alignment. The passed str is converted to a new String with width characters. The string str is placed at the center of the new string. If the original str has more characters than the designated width, then the original str is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
str - the String value to be formatted
Returns:
a formatted string

leftAlign

public static java.lang.String leftAlign(int width,
                                         int decimalPlaces,
                                         double number)
Formats a real number using the left alignment. The passed number is converted to a String with width characters. The number is placed at the left, and the second parameter decimalPlaces determines the number of decimal places to be shown. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - number of characters the resulting string will contain
decimalPlaces - the number of decimal places within the designated field width
number - the value to be formatted
Returns:
a formatted string

leftAlign

public static java.lang.String leftAlign(int width,
                                         long number)
Formats an integer using the left alignment. The passed number is converted to a String with width characters. The number is placed at the left. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
number - the integer value to be formatted
Returns:
a formatted string

leftAlign

public static java.lang.String leftAlign(int width,
                                         java.lang.String str)
Formats a String using the left alignment. The passed str is converted to a new String with width characters. The string str is placed at the left of the new string. If the original str has more characters than the designated width, then the original str is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
str - the String value to be formatted
Returns:
a formatted string

rightAlign

public static java.lang.String rightAlign(int width,
                                          int decimalPlaces,
                                          double number)
Formats a real number using the right alignment. The passed number is converted to a String with width characters. The number is placed at the right, and the second parameter decimalPlaces determines the number of decimal places to be shown. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - number of characters the resulting string will contain
decimalPlaces - the number of decimal places within the designated field width
number - the value to be formatted
Returns:
a formatted string

rightAlign

public static java.lang.String rightAlign(int width,
                                          long number)
Formats an integer using the right alignment. The passed number is converted to a String with width characters. The number is placed at the right. If the converted number has more characters than the designated width, then the converted number is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
number - the integer value to be formatted
Returns:
a formatted string

rightAlign

public static java.lang.String rightAlign(int width,
                                          java.lang.String str)
Formats a String using the right alignment. The passed str is converted to a new String with width characters. The string str is placed at the right of the new string. If the original str has more characters than the designated width, then the original str is returned without any formatting.
Parameters:
width - the number of characters the resulting string will contain
str - the String value to be formatted
Returns:
a formatted string