jodd.format
Class PrintfFormat

java.lang.Object
  extended by jodd.format.PrintfFormat

public class PrintfFormat
extends java.lang.Object

Fast simple and yet useful formattings.


Field Summary
protected  boolean alternate
           
protected  boolean countSignInLen
           
protected  char fmt
           
protected  boolean groupDigits
           
protected  boolean leadingZeroes
           
protected  boolean leftAlign
           
protected  java.lang.StringBuffer post
           
protected  java.lang.StringBuffer pre
           
protected  int precision
           
protected  boolean showPlus
           
protected  boolean showSpace
           
protected  int width
           
 
Constructor Summary
protected PrintfFormat()
          For internal use with init(String, int) and reinit(String).
  PrintfFormat(java.lang.String s)
          Formats a number in a printf format, like C.
 
Method Summary
protected  java.lang.String expFormat(double d)
          Formats a double with exp format.
protected  java.lang.String fixedFormat(double d)
          Formats a double with fixed format.
 java.lang.String form(boolean value)
          Formats a boolean into a string (like sprintf in C).
 java.lang.String form(char value)
          Formats a character into a string (like sprintf in C).
 java.lang.String form(double x)
          Formats a double into a string (like sprintf in C).
 java.lang.String form(int x)
          Formats an integer into a string (like sprintf in C).
 java.lang.String form(long x)
          Formats a long integer into a string (like sprintf in C).
 java.lang.String form(java.lang.String s)
          Formats a string into a larger string (like sprintf in C).
protected  java.lang.String groupDigits(java.lang.String value, int size, char separator)
          Groups numbers by inserting 'separator' after every group of 'size' digits, starting from the right.
protected  void init(java.lang.String s, int i)
           
protected  java.lang.String pad(java.lang.String value)
          Pads the value with spaces and adds prefix and suffix.
protected  PrintfFormat reinit(java.lang.String s)
           
protected static java.lang.String repeat(char c, int n)
          Returns new string created by repeating a single character.
protected  java.lang.String sign(int s, java.lang.String r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected int width

precision

protected int precision

pre

protected java.lang.StringBuffer pre

post

protected java.lang.StringBuffer post

leadingZeroes

protected boolean leadingZeroes

showPlus

protected boolean showPlus

alternate

protected boolean alternate

showSpace

protected boolean showSpace

leftAlign

protected boolean leftAlign

groupDigits

protected boolean groupDigits

fmt

protected char fmt

countSignInLen

protected boolean countSignInLen
Constructor Detail

PrintfFormat

public PrintfFormat(java.lang.String s)
Formats a number in a printf format, like C.

Parameters:
s - the format string following printf format string The string has a prefix, a format code and a suffix. The prefix and suffix become part of the formatted output. The format code directs the formatting of the (single) parameter to be formatted. The code has the following structure
  • a % (required)
  • a modifier (optional)
    +
    forces display of + for positive numbers
    ~
    do not count leading + or - in length
    0
    show leading zeroes
    -
    align left in the field
    space
    prepend a space in front of positive numbers
    #
    use "alternate" format. Add 0 or 0x for octal or hexadecimal numbers. Don't suppress trailing zeroes in general floating point format.
    ,
    groups decimal values by thousands (for 'diuxXb' formats)
  • an integer denoting field width (optional)
  • a period (.) followed by an integer denoting precision (optional)
  • a format descriptor (required)
    f
    floating point number in fixed format,
    e, E
    floating point number in exponential notation (scientific format). The E format results in an uppercase E for the exponent (1.14130E+003), the e format in a lowercase e,
    g, G
    floating point number in general format (fixed format for small numbers, exponential format for large numbers). Trailing zeroes are suppressed. The G format results in an uppercase E for the exponent (if any), the g format in a lowercase e,.
    d, i
    signed long and integer in decimal,
    u
    unsigned long or integer in decimal,
    x
    unsigned long or integer in hexadecimal,
    o
    unsigned long or integer in octal,
    b
    unsigned long or integer in binary,
    s
    string,
    c
    character,
    l, L
    boolean in lower or upper case (for booleans and int/longs).

PrintfFormat

protected PrintfFormat()
For internal use with init(String, int) and reinit(String).

Method Detail

reinit

protected PrintfFormat reinit(java.lang.String s)

init

protected void init(java.lang.String s,
                    int i)

expFormat

protected java.lang.String expFormat(double d)
Formats a double with exp format.


fixedFormat

protected java.lang.String fixedFormat(double d)
Formats a double with fixed format.


pad

protected java.lang.String pad(java.lang.String value)
Pads the value with spaces and adds prefix and suffix.


repeat

protected static java.lang.String repeat(char c,
                                         int n)
Returns new string created by repeating a single character.


sign

protected java.lang.String sign(int s,
                                java.lang.String r)

groupDigits

protected java.lang.String groupDigits(java.lang.String value,
                                       int size,
                                       char separator)
Groups numbers by inserting 'separator' after every group of 'size' digits, starting from the right.


form

public java.lang.String form(char value)
Formats a character into a string (like sprintf in C).


form

public java.lang.String form(boolean value)
Formats a boolean into a string (like sprintf in C).


form

public java.lang.String form(double x)
Formats a double into a string (like sprintf in C).


form

public java.lang.String form(long x)
Formats a long integer into a string (like sprintf in C).


form

public java.lang.String form(int x)
Formats an integer into a string (like sprintf in C).


form

public java.lang.String form(java.lang.String s)
Formats a string into a larger string (like sprintf in C).



Copyright © 2003-2012 Jodd Team