src/java.base/share/classes/java/util/Formatter.java

Print this page
rev 13339 : Move sun.misc math support classes to jdk.internal.math


  43 import java.nio.charset.Charset;
  44 import java.nio.charset.IllegalCharsetNameException;
  45 import java.nio.charset.UnsupportedCharsetException;
  46 import java.text.DateFormatSymbols;
  47 import java.text.DecimalFormat;
  48 import java.text.DecimalFormatSymbols;
  49 import java.text.NumberFormat;
  50 import java.util.regex.Matcher;
  51 import java.util.regex.Pattern;
  52 import java.util.Objects;
  53 
  54 import java.time.DateTimeException;
  55 import java.time.Instant;
  56 import java.time.ZoneId;
  57 import java.time.ZoneOffset;
  58 import java.time.temporal.ChronoField;
  59 import java.time.temporal.TemporalAccessor;
  60 import java.time.temporal.TemporalQueries;
  61 import java.time.temporal.UnsupportedTemporalTypeException;
  62 
  63 import sun.misc.DoubleConsts;
  64 import sun.misc.FormattedFloatingDecimal;
  65 
  66 /**
  67  * An interpreter for printf-style format strings.  This class provides support
  68  * for layout justification and alignment, common formats for numeric, string,
  69  * and date/time data, and locale-specific output.  Common Java types such as
  70  * {@code byte}, {@link java.math.BigDecimal BigDecimal}, and {@link Calendar}
  71  * are supported.  Limited formatting customization for arbitrary user types is
  72  * provided through the {@link Formattable} interface.
  73  *
  74  * <p> Formatters are not necessarily safe for multithreaded access.  Thread
  75  * safety is optional and is the responsibility of users of methods in this
  76  * class.
  77  *
  78  * <p> Formatted printing for the Java language is heavily inspired by C's
  79  * {@code printf}.  Although the format strings are similar to C, some
  80  * customizations have been made to accommodate the Java language and exploit
  81  * some of its features.  Also, Java formatting is more strict than C's; for
  82  * example, if a conversion is incompatible with a flag, an exception will be
  83  * thrown.  In C inapplicable flags are silently ignored.  The format strings
  84  * are thus intended to be recognizable to C programmers but not necessarily




  43 import java.nio.charset.Charset;
  44 import java.nio.charset.IllegalCharsetNameException;
  45 import java.nio.charset.UnsupportedCharsetException;
  46 import java.text.DateFormatSymbols;
  47 import java.text.DecimalFormat;
  48 import java.text.DecimalFormatSymbols;
  49 import java.text.NumberFormat;
  50 import java.util.regex.Matcher;
  51 import java.util.regex.Pattern;
  52 import java.util.Objects;
  53 
  54 import java.time.DateTimeException;
  55 import java.time.Instant;
  56 import java.time.ZoneId;
  57 import java.time.ZoneOffset;
  58 import java.time.temporal.ChronoField;
  59 import java.time.temporal.TemporalAccessor;
  60 import java.time.temporal.TemporalQueries;
  61 import java.time.temporal.UnsupportedTemporalTypeException;
  62 
  63 import jdk.internal.math.DoubleConsts;
  64 import jdk.internal.math.FormattedFloatingDecimal;
  65 
  66 /**
  67  * An interpreter for printf-style format strings.  This class provides support
  68  * for layout justification and alignment, common formats for numeric, string,
  69  * and date/time data, and locale-specific output.  Common Java types such as
  70  * {@code byte}, {@link java.math.BigDecimal BigDecimal}, and {@link Calendar}
  71  * are supported.  Limited formatting customization for arbitrary user types is
  72  * provided through the {@link Formattable} interface.
  73  *
  74  * <p> Formatters are not necessarily safe for multithreaded access.  Thread
  75  * safety is optional and is the responsibility of users of methods in this
  76  * class.
  77  *
  78  * <p> Formatted printing for the Java language is heavily inspired by C's
  79  * {@code printf}.  Although the format strings are similar to C, some
  80  * customizations have been made to accommodate the Java language and exploit
  81  * some of its features.  Also, Java formatting is more strict than C's; for
  82  * example, if a conversion is incompatible with a flag, an exception will be
  83  * thrown.  In C inapplicable flags are silently ignored.  The format strings
  84  * are thus intended to be recognizable to C programmers but not necessarily