ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.util
Class LaTeXFormatter

java.lang.Object
  extended by umontreal.iro.lecuyer.util.LaTeXFormatter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class LaTeXFormatter
extends Object
implements Closeable, Flushable, Appendable

Provides methods for formatting times and number for typesetting with LATEX.


Field Summary
static String DEFAULTMATHENSURINGCMD
          Default math-ensuring command, ensuremath.
static String DEFAULTNAN
          Default string for representing NaN, --.
 
Constructor Summary
LaTeXFormatter()
           
LaTeXFormatter(Appendable out)
           
LaTeXFormatter(Appendable out, Locale locale)
           
LaTeXFormatter(File file)
           
LaTeXFormatter(File file, Locale locale)
           
LaTeXFormatter(File file, String csn)
           
LaTeXFormatter(File file, String csn, Locale locale)
           
LaTeXFormatter(Locale locale)
           
LaTeXFormatter(OutputStream os)
           
LaTeXFormatter(OutputStream os, Locale locale)
           
LaTeXFormatter(OutputStream os, String csn)
           
LaTeXFormatter(OutputStream os, String csn, Locale locale)
           
LaTeXFormatter(PrintStream ps)
           
LaTeXFormatter(PrintStream ps, Locale locale)
           
LaTeXFormatter(String fileName)
           
LaTeXFormatter(String fileName, Locale locale)
           
LaTeXFormatter(String fileName, String csn)
           
LaTeXFormatter(String fileName, String csn, Locale locale)
           
 
Method Summary
 LaTeXFormatter append(char c)
           
 LaTeXFormatter append(CharSequence csq)
           
 LaTeXFormatter append(CharSequence csq, int start, int end)
           
 void close()
           
static String fixGroupingAndDecimal(NumberFormat nf, String str)
          Fixes groupings of the string str formatted by the number formatter nf, for LATEX compatibility.
static String fixScientific(String str, String mathEnsuringCmd)
          Converts the string str using Java scientific notation to LATEX notation.
 void flush()
           
 LaTeXFormatter formatFixed(double x)
           
 LaTeXFormatter formatFixed(int precision, double x)
          Formats the given double-precision number x to a string with a fixed number precision of decimal digits, for the locale locale.
 LaTeXFormatter formatInteger(int precision, long x)
          Formats the integer x for the locale locale with at least precision digits.
 LaTeXFormatter formatInteger(long x)
           
 LaTeXFormatter formatNumber(double x)
           
 LaTeXFormatter formatNumber(int precision, double x)
          Formats the given number x for the locale locale, with precision significant digits.
 LaTeXFormatter formatNumber(int digitsSmall, int digitsLarge, double x)
          Formats x with digitsSmall significant digits if it is smaller than 1, and digitsLarge significant digits if it is larger than 1.
 LaTeXFormatter formatScientific(double x)
           
 LaTeXFormatter formatScientific(int precision, double x)
          Formats the double-precision value x into a string with the scientific notation for the locale locale, with precision decimal digits of precision.
 LaTeXFormatter formatTime(double time)
          Formats a string representing the time duration time, given in seconds.
static NumberFormat getFixedFormatter(Locale locale, int precision, boolean grouping)
           
static NumberFormat getIntegerFormatter(Locale locale, int precision, boolean grouping)
           
 String getMathEnsuringCmd()
           
 String getNanString()
           
static DecimalFormat getScientificFormatter(Locale locale, int precision, boolean showAllDecimals)
           
 IOException ioException()
           
 boolean isGroupingUsed()
           
 Locale locale()
           
 Appendable out()
           
static String processInfiniteAndNaN(double x, String mathEnsuringCmd, String nanString)
          Returns a string representing infinite or NaN for x, or null if x is finite.
 void setGroupingUsed(boolean grouping)
           
 void setLocale(Locale locale)
           
 void setMathEnsuringCmd(String mathEnsuringCmd)
           
 void setNanString(String nanString)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULTMATHENSURINGCMD

public static final String DEFAULTMATHENSURINGCMD
Default math-ensuring command, ensuremath.

See Also:
Constant Field Values

DEFAULTNAN

public static final String DEFAULTNAN
Default string for representing NaN, --.

See Also:
Constant Field Values
Constructor Detail

LaTeXFormatter

public LaTeXFormatter()

LaTeXFormatter

public LaTeXFormatter(Locale locale)

LaTeXFormatter

public LaTeXFormatter(Appendable out)

LaTeXFormatter

public LaTeXFormatter(Appendable out,
                      Locale locale)

LaTeXFormatter

public LaTeXFormatter(File file)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(File file,
                      String csn)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(File file,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(File file,
                      String csn,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(OutputStream os)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(OutputStream os,
                      String csn)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(OutputStream os,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(OutputStream os,
                      String csn,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(String fileName)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(String fileName,
                      String csn)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(String fileName,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(String fileName,
                      String csn,
                      Locale locale)
               throws IOException
Throws:
IOException

LaTeXFormatter

public LaTeXFormatter(PrintStream ps)

LaTeXFormatter

public LaTeXFormatter(PrintStream ps,
                      Locale locale)
Method Detail

ioException

public IOException ioException()

out

public Appendable out()

locale

public Locale locale()

setLocale

public void setLocale(Locale locale)

getMathEnsuringCmd

public String getMathEnsuringCmd()

setMathEnsuringCmd

public void setMathEnsuringCmd(String mathEnsuringCmd)

getNanString

public String getNanString()

setNanString

public void setNanString(String nanString)

isGroupingUsed

public boolean isGroupingUsed()

setGroupingUsed

public void setGroupingUsed(boolean grouping)

flush

public void flush()
Specified by:
flush in interface Flushable

close

public void close()
Specified by:
close in interface Closeable

toString

public String toString()
Overrides:
toString in class Object

formatTime

public LaTeXFormatter formatTime(double time)
Formats a string representing the time duration time, given in seconds. The returned string is of the form 1h2min3s.

Parameters:
time - the time to be formatted.
Returns:
the latex formatter.

formatInteger

public LaTeXFormatter formatInteger(long x)

formatInteger

public LaTeXFormatter formatInteger(int precision,
                                    long x)
Formats the integer x for the locale locale with at least precision digits. If grouping is true, a locale-specific delimiter is used to separate groups, usually thousands. If the grouping corresponds to a whitespace, it is converted to ˜, the LATEX unbreakable space.

Parameters:
precision - the minimal number of digits.
x - the integer being formatted.
Returns:
the formatter object.
Throws:
IllegalArgumentException - if precision is negative.

getIntegerFormatter

public static NumberFormat getIntegerFormatter(Locale locale,
                                               int precision,
                                               boolean grouping)

formatFixed

public LaTeXFormatter formatFixed(double x)

formatFixed

public LaTeXFormatter formatFixed(int precision,
                                  double x)
Formats the given double-precision number x to a string with a fixed number precision of decimal digits, for the locale locale. If grouping is true, a locale-specific delimiter is used to separate groups, usually thousands. If the grouping corresponds to a whitespace, it is converted to ˜, the LATEX unbreakable space. If the formatted string has to be typeset in math mode, it is surrounded with the given math-ensuring command mathEnsuringCmd.

Parameters:
precision - the number of decimal digits.
x - the number being formatted.
Returns:
this formatter object.
Throws:
IllegalArgumentException - if precision is negative.

getFixedFormatter

public static NumberFormat getFixedFormatter(Locale locale,
                                             int precision,
                                             boolean grouping)

formatScientific

public LaTeXFormatter formatScientific(double x)

formatScientific

public LaTeXFormatter formatScientific(int precision,
                                       double x)
Formats the double-precision value x into a string with the scientific notation for the locale locale, with precision decimal digits of precision. If the formatted string has to be typeset in math mode, it is surrounded with the given math-ensuring command mathEnsuringCmd.

Parameters:
precision - the number of decimal digits.
x - the value being formatted.
Returns:
this formatter object.
Throws:
IllegalArgumentException - if precision is negative.

getScientificFormatter

public static DecimalFormat getScientificFormatter(Locale locale,
                                                   int precision,
                                                   boolean showAllDecimals)

formatNumber

public LaTeXFormatter formatNumber(double x)

formatNumber

public LaTeXFormatter formatNumber(int precision,
                                   double x)
Formats the given number x for the locale locale, with precision significant digits. This method uses scientific notation when the exponent is smaller than -4, or greater than or equal to precision. Otherwise, it uses standard notation. If grouping is true, a locale-specific delimiter is used to separate groups, usually thousands. If the grouping corresponds to a whitespace, it is converted to ˜, the LATEX unbreakable space. If the formatted string has to be typeset in math mode, it is surrounded with the given math-ensuring command mathEnsuringCmd.

Parameters:
precision - the number of significant digits.
x - the value being formatted.
Returns:
this formatter object.
Throws:
IllegalArgumentException - if precision is negative or 0.

formatNumber

public LaTeXFormatter formatNumber(int digitsSmall,
                                   int digitsLarge,
                                   double x)
Formats x with digitsSmall significant digits if it is smaller than 1, and digitsLarge significant digits if it is larger than 1. Let x be a value to be formatted. Let d1 be the number of needed significant digits for | x|≤1, and d2 be the number of digits for | x| > 1. If x≥10d1, the formatter uses formatFixed(int,double) with 0 decimal digit of precision. If x < 10-d2, the formatter uses formatScientific(double) with d2 digits of precision. Otherwise, the formatter uses formatNumber(int,int,double) with d1 or d2 significant digits, depending if | x| is smaller than or equal to 1, or greater than 1.

Parameters:
digitsSmall - the number of significant digits for small numbers.
digitsLarge - the number of significant digits for large numbers.
x - the value to be formatted.
Returns:
this formatter object.

processInfiniteAndNaN

public static String processInfiniteAndNaN(double x,
                                           String mathEnsuringCmd,
                                           String nanString)
Returns a string representing infinite or NaN for x, or null if x is finite. This method is used by double), double), and int, double).

Parameters:
x - the number being processed.
mathEnsuringCmd - the math-ensuring command.
nanString - the string representing NaN.
Returns:
a string representing infinity or NaN, or null.

fixGroupingAndDecimal

public static String fixGroupingAndDecimal(NumberFormat nf,
                                           String str)
Fixes groupings of the string str formatted by the number formatter nf, for LATEX compatibility. If the grouping used by the given number formatter is a whitespace, this method replaces it with a LATEX unbreakable space. Otherwise, the string is unchanged.

Parameters:
str - the string to fix.
nf - the number formatter having formatted the string.
Returns:
the fixed string.

fixScientific

public static String fixScientific(String str,
                                   String mathEnsuringCmd)
Converts the string str using Java scientific notation to LATEX notation. For example, this converts 2e4 to 2*10ˆ{4}.

Parameters:
str - the string being fixed.
mathEnsuringCmd - the math-ensuring LATEX command.
Returns:
the fixed string.

append

public LaTeXFormatter append(char c)
Specified by:
append in interface Appendable

append

public LaTeXFormatter append(CharSequence csq,
                             int start,
                             int end)
Specified by:
append in interface Appendable

append

public LaTeXFormatter append(CharSequence csq)
Specified by:
append in interface Appendable

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.