Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.xmud.util
Class PrintfFormat.ConversionSpecification  view PrintfFormat.ConversionSpecification download PrintfFormat.ConversionSpecification.java

java.lang.Object
  extended byorg.xmud.util.PrintfFormat.ConversionSpecification
Enclosing class:
PrintfFormat

private class PrintfFormat.ConversionSpecification
extends java.lang.Object

ConversionSpecification allows the formatting of a single primitive or object embedded within a string. The formatting is controlled by a format string. Only one Java primitive or object can be formatted at a time.

A format string is a Java string that contains a control string. The control string starts at the first percent sign (%) in the string, provided that this percent sign

  1. is not escaped protected by a matching % or is not an escape % character,
  2. is not at the end of the format string, and
  3. precedes a sequence of characters that parses as a valid control string.

A control string takes the form:

 % ['-+ #0]* [0..9]* { . [0..9]* }+
                { [hlL] }+ [idfgGoxXeEcs]

The behavior is like printf. One (hopefully the only) exception is that the minimum number of exponent digits is 3 instead of 2 for e and E formats when the optional L is used before the e, E, g, or G conversion character. The optional L does not imply conversion to a long long double.


Field Summary
private  boolean alternateForm
          For an o conversion, increase the precision to force the first digit of the result to be a zero.
private  int argumentPosition
           
private  int argumentPositionForFieldWidth
           
private  int argumentPositionForPrecision
           
private  char conversionCharacter
          Control string type.
private static int defaultDigits
          Default precision.
private  int fieldWidth
          If the converted value has fewer bytes than the field width, it will be padded with spaces or zeroes.
private  boolean fieldWidthSet
          Flag indicating whether or not the field width has been set.
private  java.lang.String fmt
          Literal or control format string.
private  boolean leadingSign
          The result of a signed conversion will always begin with a sign (+ or -).
private  boolean leadingSpace
          Flag indicating that left padding with spaces is specified.
private  boolean leadingZeros
          Flag indicating that left padding with zeroes is specified.
private  boolean leftJustify
          The result of the conversion will be left-justified within the field.
private  boolean optionalh
          Flag specifying that a following d, i, o, u, x, or X conversion character applies to a type short int.
private  boolean optionall
          Flag specifying that a following d, i, o, u, x, or X conversion character applies to a type lont int argument.
private  boolean optionalL
          Flag specifying that a following e, E, f, g, or G conversion character applies to a type double argument.
private  int pos
          Position within the control string.
private  boolean positionalFieldWidth
           
private  boolean positionalPrecision
           
private  boolean positionalSpecification
           
private  int precision
          The minimum number of digits to appear for the d, i, o, u, x, or X conversions.
private  boolean precisionSet
          Flag indicating whether or not the precision has been set.
private  boolean thousands
          The integer portion of the result of a decimal conversion (i, d, u, f, g, or G) will be formatted with thousands' grouping characters.
private  boolean variableFieldWidth
          Flag indicating that the field width is *.
private  boolean variablePrecision
          Flag indicating that the precision is *.
 
Constructor Summary
(package private) PrintfFormat.ConversionSpecification()
          Constructor.
(package private) PrintfFormat.ConversionSpecification(java.lang.String fmtArg)
          Constructor for a conversion specification.
 
Method Summary
private  char[] applyFloatPadding(char[] ca4, boolean noDigits)
          Apply zero or blank, left or right padding.
private  boolean checkForCarry(char[] ca1, int icarry)
          Check to see if the digits that are going to be truncated because of the precision should force a round in the preceding digits.
private  char[] eFormatDigits(double x, char eChar)
          For e format, the flag character '-', means that the output should be left justified within the field.
private  java.lang.String eFormatString(double x, char eChar)
          An intermediate routine on the way to creating an e format String.
private  char[] fFormatDigits(double x)
          For f format, the flag character '-', means that the output should be left justified within the field.
private  java.lang.String fFormatString(double x)
          An intermediate routine on the way to creating an f format String.
(package private)  int getArgumentPosition()
           
(package private)  int getArgumentPositionForFieldWidth()
           
(package private)  int getArgumentPositionForPrecision()
           
(package private)  char getConversionCharacter()
          Get the conversion character that tells what type of control character this instance has.
(package private)  java.lang.String getLiteral()
          Get the String for this instance.
(package private)  java.lang.String internalsprintf(double s)
          Format a double argument using this conversion specification.
(package private)  java.lang.String internalsprintf(int s)
          Format an int argument using this conversion specification.
(package private)  java.lang.String internalsprintf(long s)
          Format a long argument using this conversion specification.
(package private)  java.lang.String internalsprintf(java.lang.Object s)
          Format an Object argument using this conversion specification.
(package private)  java.lang.String internalsprintf(java.lang.String s)
          Format a String argument using this conversion specification.
(package private)  boolean isPositionalFieldWidth()
           
(package private)  boolean isPositionalPrecision()
           
(package private)  boolean isPositionalSpecification()
           
(package private)  boolean isVariableFieldWidth()
          Check whether the specifier has a variable field width that is going to be set by an argument.
(package private)  boolean isVariablePrecision()
          Check whether the specifier has a variable precision that is going to be set by an argument.
private  java.lang.String printCFormat(char x)
          Format method for the c conversion character and char argument.
private  java.lang.String printDFormat(int x)
          Format method for the d conversion character and int argument.
private  java.lang.String printDFormat(long x)
          Format method for the d conversion character and long argument.
private  java.lang.String printDFormat(short x)
          Format method for the d conversion specifer and short argument.
private  java.lang.String printDFormat(java.lang.String sx)
          Utility method for formatting using the d conversion character.
private  java.lang.String printEFormat(double x)
          Format method for the e or E conversion character.
private  java.lang.String printFFormat(double x)
          Format method for the f conversion character.
private  java.lang.String printGFormat(double x)
          Format method for the g conversion character.
private  java.lang.String printOFormat(int x)
          Format method for the o conversion character and int argument.
private  java.lang.String printOFormat(long x)
          Format method for the o conversion character and long argument.
private  java.lang.String printOFormat(short x)
          Format method for the o conversion character and short argument.
private  java.lang.String printOFormat(java.lang.String sx)
          Utility method for formatting using the o conversion character.
private  java.lang.String printSFormat(java.lang.String x)
          Format method for the s conversion character and String argument.
private  java.lang.String printXFormat(int x)
          Format method for the x conversion character and int argument.
private  java.lang.String printXFormat(long x)
          Format method for the x conversion character and long argument.
private  java.lang.String printXFormat(short x)
          Format method for the x conversion character and short argument.
private  java.lang.String printXFormat(java.lang.String sx)
          Utility method for formatting using the x conversion character.
private  void setArgPosition()
          Store the digits n in %n$ forms.
private  boolean setConversionCharacter()
          Check for a conversion character.
private  void setFieldWidth()
          Set the field width.
private  boolean setFieldWidthArgPosition()
          Store the digits n in *n$ forms.
(package private)  void setFieldWidthWithArg(int fw)
          Set the field width with an argument.
private  void setFlagCharacters()
          Set flag characters, one of '-+#0 or a space.
(package private)  void setLiteral(java.lang.String s)
          Set the String for this instance.
private  void setOptionalHL()
          Check for an h, l, or L in a format.
private  void setPrecision()
          Set the precision.
private  boolean setPrecisionArgPosition()
          Store the digits n in *n$ forms.
(package private)  void setPrecisionWithArg(int pr)
          Set the precision with an argument.
private  boolean startSymbolicCarry(char[] ca, int cLast, int cFirst)
          Start the symbolic carry process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thousands

private boolean thousands
The integer portion of the result of a decimal conversion (i, d, u, f, g, or G) will be formatted with thousands' grouping characters. For other conversions the flag is ignored.


leftJustify

private boolean leftJustify
The result of the conversion will be left-justified within the field.


leadingSign

private boolean leadingSign
The result of a signed conversion will always begin with a sign (+ or -).


leadingSpace

private boolean leadingSpace
Flag indicating that left padding with spaces is specified.


alternateForm

private boolean alternateForm
For an o conversion, increase the precision to force the first digit of the result to be a zero. For x (or X) conversions, a non-zero result will have 0x (or 0X) prepended to it. For e, E, f, g, or G conversions, the result will always contain a radix character, even if no digits follow the point. For g and G conversions, trailing zeros will not be removed from the result.


leadingZeros

private boolean leadingZeros
Flag indicating that left padding with zeroes is specified.


variableFieldWidth

private boolean variableFieldWidth
Flag indicating that the field width is *.


fieldWidth

private int fieldWidth
If the converted value has fewer bytes than the field width, it will be padded with spaces or zeroes.


fieldWidthSet

private boolean fieldWidthSet
Flag indicating whether or not the field width has been set.


precision

private int precision
The minimum number of digits to appear for the d, i, o, u, x, or X conversions. The number of digits to appear after the radix character for the e, E, and f conversions. The maximum number of significant digits for the g and G conversions. The maximum number of bytes to be printed from a string in s and S conversions.


defaultDigits

private static final int defaultDigits
Default precision.

See Also:
Constant Field Values

variablePrecision

private boolean variablePrecision
Flag indicating that the precision is *.


precisionSet

private boolean precisionSet
Flag indicating whether or not the precision has been set.


positionalSpecification

private boolean positionalSpecification

argumentPosition

private int argumentPosition

positionalFieldWidth

private boolean positionalFieldWidth

argumentPositionForFieldWidth

private int argumentPositionForFieldWidth

positionalPrecision

private boolean positionalPrecision

argumentPositionForPrecision

private int argumentPositionForPrecision

optionalh

private boolean optionalh
Flag specifying that a following d, i, o, u, x, or X conversion character applies to a type short int.


optionall

private boolean optionall
Flag specifying that a following d, i, o, u, x, or X conversion character applies to a type lont int argument.


optionalL

private boolean optionalL
Flag specifying that a following e, E, f, g, or G conversion character applies to a type double argument. This is a noop in Java.


conversionCharacter

private char conversionCharacter
Control string type.


pos

private int pos
Position within the control string. Used by the constructor.


fmt

private java.lang.String fmt
Literal or control format string.

Constructor Detail

PrintfFormat.ConversionSpecification

PrintfFormat.ConversionSpecification()
Constructor. Used to prepare an instance to hold a literal, not a control string.


PrintfFormat.ConversionSpecification

PrintfFormat.ConversionSpecification(java.lang.String fmtArg)
                               throws java.lang.IllegalArgumentException
Constructor for a conversion specification. The argument must begin with a % and end with the conversion character for the conversion specification.

Method Detail

setLiteral

void setLiteral(java.lang.String s)
Set the String for this instance.


getLiteral

java.lang.String getLiteral()
Get the String for this instance. Translate any escape sequences.


getConversionCharacter

char getConversionCharacter()
Get the conversion character that tells what type of control character this instance has.


isVariableFieldWidth

boolean isVariableFieldWidth()
Check whether the specifier has a variable field width that is going to be set by an argument.


setFieldWidthWithArg

void setFieldWidthWithArg(int fw)
Set the field width with an argument. A negative field width is taken as a - flag followed by a positive field width.


isVariablePrecision

boolean isVariablePrecision()
Check whether the specifier has a variable precision that is going to be set by an argument.


setPrecisionWithArg

void setPrecisionWithArg(int pr)
Set the precision with an argument. A negative precision will be changed to zero.


internalsprintf

java.lang.String internalsprintf(int s)
                           throws java.lang.IllegalArgumentException
Format an int argument using this conversion specification.


internalsprintf

java.lang.String internalsprintf(long s)
                           throws java.lang.IllegalArgumentException
Format a long argument using this conversion specification.


internalsprintf

java.lang.String internalsprintf(double s)
                           throws java.lang.IllegalArgumentException
Format a double argument using this conversion specification.


internalsprintf

java.lang.String internalsprintf(java.lang.String s)
                           throws java.lang.IllegalArgumentException
Format a String argument using this conversion specification.


internalsprintf

java.lang.String internalsprintf(java.lang.Object s)
Format an Object argument using this conversion specification.


fFormatDigits

private char[] fFormatDigits(double x)
For f format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the number of digits to appear after the radix character. Padding is with trailing 0s.


fFormatString

private java.lang.String fFormatString(double x)
An intermediate routine on the way to creating an f format String. The method decides whether the input double value is an infinity, not-a-number, or a finite double and formats each type of input appropriately.


eFormatDigits

private char[] eFormatDigits(double x,
                             char eChar)
For e format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear after the radix character. Padding is with trailing 0s. The behavior is like printf. One (hopefully the only) exception is that the minimum number of exponent digits is 3 instead of 2 for e and E formats when the optional L is used before the e, E, g, or G conversion character. The optional L does not imply conversion to a long long double.


checkForCarry

private boolean checkForCarry(char[] ca1,
                              int icarry)
Check to see if the digits that are going to be truncated because of the precision should force a round in the preceding digits.


startSymbolicCarry

private boolean startSymbolicCarry(char[] ca,
                                   int cLast,
                                   int cFirst)
Start the symbolic carry process. The process is not quite finished because the symbolic carry may change the length of the string and change the exponent (in e format).


eFormatString

private java.lang.String eFormatString(double x,
                                       char eChar)
An intermediate routine on the way to creating an e format String. The method decides whether the input double value is an infinity, not-a-number, or a finite double and formats each type of input appropriately.


applyFloatPadding

private char[] applyFloatPadding(char[] ca4,
                                 boolean noDigits)
Apply zero or blank, left or right padding.


printFFormat

private java.lang.String printFFormat(double x)
Format method for the f conversion character.


printEFormat

private java.lang.String printEFormat(double x)
Format method for the e or E conversion character.


printGFormat

private java.lang.String printGFormat(double x)
Format method for the g conversion character. For g format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear after the radix character. Padding is with trailing 0s.


printDFormat

private java.lang.String printDFormat(short x)
Format method for the d conversion specifer and short argument. For d format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. A '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printDFormat

private java.lang.String printDFormat(long x)
Format method for the d conversion character and long argument. For d format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. A '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printDFormat

private java.lang.String printDFormat(int x)
Format method for the d conversion character and int argument. For d format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. A '+' character means that the conversion will always begin with a sign (+ or -). The blank flag character means that a non-negative input will be preceded with a blank. If both a '+' and a ' ' are specified, the blank flag is ignored. The '0' flag character implies that padding to the field width will be done with zeros instead of blanks. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printDFormat

private java.lang.String printDFormat(java.lang.String sx)
Utility method for formatting using the d conversion character.


printXFormat

private java.lang.String printXFormat(short x)
Format method for the x conversion character and short argument. For x format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means to lead with '0x'. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printXFormat

private java.lang.String printXFormat(long x)
Format method for the x conversion character and long argument. For x format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means to lead with '0x'. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printXFormat

private java.lang.String printXFormat(int x)
Format method for the x conversion character and int argument. For x format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means to lead with '0x'. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printXFormat

private java.lang.String printXFormat(java.lang.String sx)
Utility method for formatting using the x conversion character.


printOFormat

private java.lang.String printOFormat(short x)
Format method for the o conversion character and short argument. For o format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means that the output begins with a leading 0 and the precision is increased by 1. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printOFormat

private java.lang.String printOFormat(long x)
Format method for the o conversion character and long argument. For o format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means that the output begins with a leading 0 and the precision is increased by 1. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printOFormat

private java.lang.String printOFormat(int x)
Format method for the o conversion character and int argument. For o format, the flag character '-', means that the output should be left justified within the field. The default is to pad with blanks on the left. The '#' flag character means that the output begins with a leading 0 and the precision is increased by 1. The field width is treated as the minimum number of characters to be printed. The default is to add no padding. Padding is with blanks by default. The precision, if set, is the minimum number of digits to appear. Padding is with leading 0s.


printOFormat

private java.lang.String printOFormat(java.lang.String sx)
Utility method for formatting using the o conversion character.


printCFormat

private java.lang.String printCFormat(char x)
Format method for the c conversion character and char argument. The only flag character that affects c format is the '-', meaning that the output should be left justified within the field. The default is to pad with blanks on the left. The field width is treated as the minimum number of characters to be printed. Padding is with blanks by default. The default width is 1. The precision, if set, is ignored.


printSFormat

private java.lang.String printSFormat(java.lang.String x)
Format method for the s conversion character and String argument. The only flag character that affects s format is the '-', meaning that the output should be left justified within the field. The default is to pad with blanks on the left. The field width is treated as the minimum number of characters to be printed. The default is the smaller of the number of characters in the the input and the precision. Padding is with blanks by default. The precision, if set, specifies the maximum number of characters to be printed from the string. A null digit string is treated as a 0. The default is not to set a maximum number of characters to be printed.


setConversionCharacter

private boolean setConversionCharacter()
Check for a conversion character. If it is there, store it.


setOptionalHL

private void setOptionalHL()
Check for an h, l, or L in a format. An L is used to control the minimum number of digits in an exponent when using floating point formats. An l or h is used to control conversion of the input to a long or short, respectively, before formatting. If any of these is present, store them.


setPrecision

private void setPrecision()
Set the precision.


setFieldWidth

private void setFieldWidth()
Set the field width.


setArgPosition

private void setArgPosition()
Store the digits n in %n$ forms.


setFieldWidthArgPosition

private boolean setFieldWidthArgPosition()
Store the digits n in *n$ forms.


setPrecisionArgPosition

private boolean setPrecisionArgPosition()
Store the digits n in *n$ forms.


isPositionalSpecification

boolean isPositionalSpecification()

getArgumentPosition

int getArgumentPosition()

isPositionalFieldWidth

boolean isPositionalFieldWidth()

getArgumentPositionForFieldWidth

int getArgumentPositionForFieldWidth()

isPositionalPrecision

boolean isPositionalPrecision()

getArgumentPositionForPrecision

int getArgumentPositionForPrecision()

setFlagCharacters

private void setFlagCharacters()
Set flag characters, one of '-+#0 or a space.