gshute.ioutil
Class Formatting

java.lang.Object
  |
  +--gshute.ioutil.Formatting

public class Formatting
extends java.lang.Object

The Formatting class provides utility methods for formatting text for String and numerical data.


Method Summary
static java.lang.String binary(long n, int w)
          Formatting.binary(n, w) returns the unsigned binary representation of n, right justified in a string field of width at least w.
static java.lang.String binary(long n, int w, char fc)
          Formatting.binary(n, w, fc) returns the unsigned binary representation of n, right justified in a string field of width at least w.
static java.lang.String decimal(long n, int w)
          Formatting.decimal(n, w) returns the decimal representation of n, right justified in a string field of width at least w.
static java.lang.String decimal(long n, int w, char fc)
          Formatting.decimal(n, w, fc) returns the decimal representation of n, right justified in a string field of width at least w.
static java.lang.String filledLeft(java.lang.String str, int w)
          Formatting.filledLeft(str, w) returns a copy of the string str, right justified in a string field of width at least w.
static java.lang.String filledLeft(java.lang.String str, int w, char fc)
          Formatting.filledLeft(str, w, fc) returns a copy of the string str, right justified in a string field of width at least w.
static java.lang.String filledRight(java.lang.String str, int w)
          Formatting.filledRight(str, w) returns a copy of the string str, right justified in a string field of width at least w.
static java.lang.String filledRight(java.lang.String str, int w, char fc)
          Formatting.filledRight(str, w, fc) returns a copy of the string str, left justified in a string field of width at least w.
static java.lang.String fillString(int w)
          Formatting.fillString(w) returns a string of length w whose characters are all spaces.
static java.lang.String fillString(int w, char fc)
          Formatting.fillString(w, fc) returns a string of length w whose characters are all copies of fc.
static java.lang.String fixedPoint(double x, int w, int p)
          Formatting.fixedPoint(x, w, p) returns the fixed point representation of x, right justified in a string field of width at least w, with p digits after the decimal point.
static java.lang.String floatingPoint(double x, int w, int i, int p)
          Formatting.floatingPoint(x, w, i, p) returns the floating point representation of x, right justified in a string field of width at least w, with i digits before the decimal point and p digits after the decimal point.
static java.lang.String hexadecimal(long n, int w)
          Formatting.hexadecimal(n, w) returns the unsigned hexadecimal representation of n, right justified in a string field of width at least w.
static java.lang.String hexadecimal(long n, int w, char fc)
          Formatting.hexadecimal(n, w, fc) returns the unsigned hexadecimal representation of n, right justified in a string field of width at least w.
static java.lang.String octal(long n, int w)
          Formatting.octal(n, w) returns the unsigned octal representation of n, right justified in a string field of width at least w.
static java.lang.String octal(long n, int w, char fc)
          Formatting.octal(n, w, fc) returns the unsigned octal representation of n, right justified in a string field of width at least w.
static java.lang.String trimmedLeft(java.lang.String str, int w)
          Formatting.trimmedLeft(str, w) returns a copy of the string str, trimmed on the left if necessary to fit in a string field of width w.
static java.lang.String trimmedRight(java.lang.String str, int w)
          Formatting.trimmedRight(str, w) returns a copy of the string str, trimmed on the right if necessary to fit in a string field of width w.
static java.lang.String whiteEquivalent(java.lang.String str)
          Formatting.whiteEquivalent(str) returns a string that displays in the same space as str, but contains space characters replacing the non-white characters of str.
static java.lang.String whiteEquivalent(java.lang.String str, char ch)
          Formatting.whiteEquivalent(str, ch) returns a string that displays in the same space as str, but contains copies of ch replacing the non-white characters of str.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fillString

public static java.lang.String fillString(int w,
                                          char fc)
Formatting.fillString(w, fc) returns a string of length w whose characters are all copies of fc. If w is less than or equal to zero then an empty string is returned.

fillString

public static java.lang.String fillString(int w)
Formatting.fillString(w) returns a string of length w whose characters are all spaces. If w is less than or equal to zero then an empty string is returned.

filledLeft

public static java.lang.String filledLeft(java.lang.String str,
                                          int w)
Formatting.filledLeft(str, w) returns a copy of the string str, right justified in a string field of width at least w. If necessary, space characters are used as a fill characters on the left. The full content of str always appears in the returned string, even if it requires more than w characters.

filledLeft

public static java.lang.String filledLeft(java.lang.String str,
                                          int w,
                                          char fc)
Formatting.filledLeft(str, w, fc) returns a copy of the string str, right justified in a string field of width at least w. If necessary, the character fc is used as a fill character on the left. The full content of str always appears in the returned string, even if it requires more than w characters.

filledRight

public static java.lang.String filledRight(java.lang.String str,
                                           int w)
Formatting.filledRight(str, w) returns a copy of the string str, right justified in a string field of width at least w. If necessary, space characters are used as a fill characters on the right. The full content of str always appears in the returned string, even if it requires more than w characters.

filledRight

public static java.lang.String filledRight(java.lang.String str,
                                           int w,
                                           char fc)
Formatting.filledRight(str, w, fc) returns a copy of the string str, left justified in a string field of width at least w. If necessary, the character fc is used as a fill character on the right. The full content of str always appears in the returned string, even if it requires more than w characters.

trimmedLeft

public static java.lang.String trimmedLeft(java.lang.String str,
                                           int w)
Formatting.trimmedLeft(str, w) returns a copy of the string str, trimmed on the left if necessary to fit in a string field of width w. If w is less than or equal to zero then an empty string is returned. If the length of str is less than or equal to w then str is returned.

trimmedRight

public static java.lang.String trimmedRight(java.lang.String str,
                                            int w)
Formatting.trimmedRight(str, w) returns a copy of the string str, trimmed on the right if necessary to fit in a string field of width w. If w is less than or equal to zero then an empty string is returned. If the length of str is less than or equal to w then str is returned.

whiteEquivalent

public static java.lang.String whiteEquivalent(java.lang.String str)
Formatting.whiteEquivalent(str) returns a string that displays in the same space as str, but contains space characters replacing the non-white characters of str.

whiteEquivalent

public static java.lang.String whiteEquivalent(java.lang.String str,
                                               char ch)
Formatting.whiteEquivalent(str, ch) returns a string that displays in the same space as str, but contains copies of ch replacing the non-white characters of str.

decimal

public static java.lang.String decimal(long n,
                                       int w,
                                       char fc)
Formatting.decimal(n, w, fc) returns the decimal representation of n, right justified in a string field of width at least w. If necessary, the character fc is used as a fill character. The full decimal representation of n always appears in the returned string, even if it requires more than w characters.

decimal

public static java.lang.String decimal(long n,
                                       int w)
Formatting.decimal(n, w) returns the decimal representation of n, right justified in a string field of width at least w. If necessary, blanks are used as fill characters. The full decimal representation of n always appears in the returned string, even if it requires more than w characters.

hexadecimal

public static java.lang.String hexadecimal(long n,
                                           int w,
                                           char fc)
Formatting.hexadecimal(n, w, fc) returns the unsigned hexadecimal representation of n, right justified in a string field of width at least w. If necessary, the character fc is used as a fill character. The full hexadecimal representation of n always appears in the returned string, even if it requires more than w characters.

hexadecimal

public static java.lang.String hexadecimal(long n,
                                           int w)
Formatting.hexadecimal(n, w) returns the unsigned hexadecimal representation of n, right justified in a string field of width at least w. If necessary, blanks are used as fill characters. The full hexadecimal representation of n always appears in the returned string, even if it requires more than w characters.

octal

public static java.lang.String octal(long n,
                                     int w,
                                     char fc)
Formatting.octal(n, w, fc) returns the unsigned octal representation of n, right justified in a string field of width at least w. If necessary, the character fc is used as a fill character. The full octal representation of n always appears in the returned string, even if it requires more than w characters.

octal

public static java.lang.String octal(long n,
                                     int w)
Formatting.octal(n, w) returns the unsigned octal representation of n, right justified in a string field of width at least w. If necessary, blanks are used as fill characters. The full octal representation of n always appears in the returned string, even if it requires more than w characters.

binary

public static java.lang.String binary(long n,
                                      int w,
                                      char fc)
Formatting.binary(n, w, fc) returns the unsigned binary representation of n, right justified in a string field of width at least w. If necessary, the character fc is used as a fill character. The full binary representation of n always appears in the returned string, even if it requires more than w characters.

binary

public static java.lang.String binary(long n,
                                      int w)
Formatting.binary(n, w) returns the unsigned binary representation of n, right justified in a string field of width at least w. If necessary, blanks are used as fill characters. The full binary representation of n always appears in the returned string, even if it requires more than w characters.

fixedPoint

public static java.lang.String fixedPoint(double x,
                                          int w,
                                          int p)
Formatting.fixedPoint(x, w, p) returns the fixed point representation of x, right justified in a string field of width at least w, with p digits after the decimal point. If necessary, blanks are used as fill characters. The full integer part of x always appears in the returned string, even if it requires more than w characters.

floatingPoint

public static java.lang.String floatingPoint(double x,
                                             int w,
                                             int i,
                                             int p)
Formatting.floatingPoint(x, w, i, p) returns the floating point representation of x, right justified in a string field of width at least w, with i digits before the decimal point and p digits after the decimal point. If necessary, blanks are used as fill characters. The actual width of the returned string is at least i + p + 3, even if w is smaller.