jdk/src/java.base/share/classes/java/util/Formatter.java
author sherman
Fri, 16 Jan 2015 13:46:39 -0800
changeset 28518 9a6247bbed98
parent 28302 5de69b0d3a84
child 28768 30b987a20989
permissions -rw-r--r--
8042262: Javadoc typo in java.util.Formatter Summary: to fix the simple typo in java doc Reviewed-by: rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.BufferedWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Closeable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Flushable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.OutputStreamWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.math.BigDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.math.MathContext;
1823
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
    42
import java.math.RoundingMode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.nio.charset.Charset;
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
    44
import java.nio.charset.IllegalCharsetNameException;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
    45
import java.nio.charset.UnsupportedCharsetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.text.DateFormatSymbols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.text.DecimalFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.text.DecimalFormatSymbols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.text.NumberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.regex.Matcher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    53
import java.time.DateTimeException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    54
import java.time.Instant;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    55
import java.time.ZoneId;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    56
import java.time.ZoneOffset;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    57
import java.time.temporal.ChronoField;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    58
import java.time.temporal.TemporalAccessor;
20795
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 19426
diff changeset
    59
import java.time.temporal.TemporalQueries;
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
    60
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.misc.DoubleConsts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.misc.FormattedFloatingDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * An interpreter for printf-style format strings.  This class provides support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * for layout justification and alignment, common formats for numeric, string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * and date/time data, and locale-specific output.  Common Java types such as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
    68
 * {@code byte}, {@link java.math.BigDecimal BigDecimal}, and {@link Calendar}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * are supported.  Limited formatting customization for arbitrary user types is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * provided through the {@link Formattable} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p> Formatters are not necessarily safe for multithreaded access.  Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * safety is optional and is the responsibility of users of methods in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p> Formatted printing for the Java language is heavily inspired by C's
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
    77
 * {@code printf}.  Although the format strings are similar to C, some
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * customizations have been made to accommodate the Java language and exploit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * some of its features.  Also, Java formatting is more strict than C's; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * example, if a conversion is incompatible with a flag, an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * thrown.  In C inapplicable flags are silently ignored.  The format strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * are thus intended to be recognizable to C programmers but not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * completely compatible with those in C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p> Examples of expected usage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *   StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   // Send all output to the Appendable object sb
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *   Formatter formatter = new Formatter(sb, Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *   // Explicit argument indices may be used to re-order output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *   formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   // -&gt; " d  c  b  a"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   // Optional locale as the first argument can be used to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *   // locale-specific formatting of numbers.  The precision and width can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *   // given to round and align the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   formatter.format(Locale.FRANCE, "e = %+10.4f", Math.E);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   // -&gt; "e =    +2,7183"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *   // The '(' numeric flag may be used to format negative numbers with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *   // parentheses rather than a minus sign.  Group separators are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *   // automatically inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *   formatter.format("Amount gained or lost since last statement: $ %(,.2f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *                    balanceDelta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *   // -&gt; "Amount gained or lost since last statement: $ (6,217.58)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p> Convenience methods for common formatting requests exist as illustrated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * by the following invocations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *   // Writes a formatted string to System.out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   System.out.format("Local time: %tT", Calendar.getInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *   // -&gt; "Local time: 13:34:18"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *   // Writes formatted output to System.err.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *   System.err.printf("Unable to open file '%1$s': %2$s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *                     fileName, exception.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *   // -&gt; "Unable to open file 'food': No such file or directory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   124
 * <p> Like C's {@code sprintf(3)}, Strings may be formatted using the static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * method {@link String#format(String,Object...) String.format}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *   // Format a string containing a date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *   import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *   import java.util.GregorianCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *   import static java.util.Calendar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *   Calendar c = new GregorianCalendar(1995, MAY, 23);
21368
7b48f137e525 5063500: Formatter spec says "char" is not an integral type
smarks
parents: 20795
diff changeset
   134
 *   String s = String.format("Duke's Birthday: %1$tb %1$te, %1$tY", c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *   // -&gt; s == "Duke's Birthday: May 23, 1995"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <h3><a name="org">Organization</a></h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p> This specification is divided into two sections.  The first section, <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * href="#summary">Summary</a>, covers the basic formatting concepts.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * section is intended for users who want to get started quickly and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * familiar with formatted printing in other programming languages.  The second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * section, <a href="#detail">Details</a>, covers the specific implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * details.  It is intended for users who want more precise specification of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * formatting behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <h3><a name="summary">Summary</a></h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <p> This section is intended to provide a brief overview of formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * concepts.  For precise behavioral details, refer to the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * href="#detail">Details</a> section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <h4><a name="syntax">Format String Syntax</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <p> Every method which produces formatted output requires a <i>format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * string</i> and an <i>argument list</i>.  The format string is a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * String} which may contain fixed text and one or more embedded <i>format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * specifiers</i>.  Consider the following example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *   Calendar c = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *   String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   166
 * This format string is the first argument to the {@code format} method.  It
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   167
 * contains three format specifiers "{@code %1$tm}", "{@code %1$te}", and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   168
 * "{@code %1$tY}" which indicate how the arguments should be processed and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * where they should be inserted in the text.  The remaining portions of the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   170
 * format string are fixed text including {@code "Dukes Birthday: "} and any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * other spaces or punctuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * The argument list consists of all arguments passed to the method after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * format string.  In the above example, the argument list is of size one and
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   175
 * consists of the {@link java.util.Calendar Calendar} object {@code c}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <li> The format specifiers for general, character, and numeric types have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * the following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *   %[argument_index$][flags][width][.precision]conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * <p> The optional <i>argument_index</i> is a decimal integer indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * position of the argument in the argument list.  The first argument is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   188
 * referenced by "{@code 1$}", the second by "{@code 2$}", etc.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <p> The optional <i>flags</i> is a set of characters that modify the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * format.  The set of valid flags depends on the conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *
18797
ced9bcc861d9 6178739: (fmt) Formatter.format("%0.4f\n", 56789.456789) generates MissingFormatWidthException
bpb
parents: 18774
diff changeset
   193
 * <p> The optional <i>width</i> is a positive decimal integer indicating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * the minimum number of characters to be written to the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * <p> The optional <i>precision</i> is a non-negative decimal integer usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * used to restrict the number of characters.  The specific behavior depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * the conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <p> The required <i>conversion</i> is a character indicating how the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * argument should be formatted.  The set of valid conversions for a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * argument depends on the argument's data type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * <li> The format specifiers for types which are used to represents dates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * times have the following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *   %[argument_index$][flags][width]conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * <p> The optional <i>argument_index</i>, <i>flags</i> and <i>width</i> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * defined as above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * <p> The required <i>conversion</i> is a two character sequence.  The first
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   215
 * character is {@code 't'} or {@code 'T'}.  The second character indicates
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * the format to be used.  These characters are similar to but not completely
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   217
 * identical to those defined by GNU {@code date} and POSIX
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   218
 * {@code strftime(3c)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * <li> The format specifiers which do not correspond to arguments have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *   %[flags][width]conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * <p> The optional <i>flags</i> and <i>width</i> is defined as above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * <p> The required <i>conversion</i> is a character indicating content to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * inserted in the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * <h4> Conversions </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * <p> Conversions are divided into the following categories:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * <li> <b>General</b> - may be applied to any argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * <li> <b>Character</b> - may be applied to basic types which represent
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   244
 * Unicode characters: {@code char}, {@link Character}, {@code byte}, {@link
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   245
 * Byte}, {@code short}, and {@link Short}. This conversion may also be
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   246
 * applied to the types {@code int} and {@link Integer} when {@link
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   247
 * Character#isValidCodePoint} returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * <li> <b>Numeric</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   253
 * <li> <b>Integral</b> - may be applied to Java integral types: {@code byte},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   254
 * {@link Byte}, {@code short}, {@link Short}, {@code int} and {@link
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   255
 * Integer}, {@code long}, {@link Long}, and {@link java.math.BigInteger
21368
7b48f137e525 5063500: Formatter spec says "char" is not an integral type
smarks
parents: 20795
diff changeset
   256
 * BigInteger} (but not {@code char} or {@link Character})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * <li><b>Floating Point</b> - may be applied to Java floating-point types:
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   259
 * {@code float}, {@link Float}, {@code double}, {@link Double}, and {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * java.math.BigDecimal BigDecimal}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * <li> <b>Date/Time</b> - may be applied to Java types which are capable of
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
   265
 * encoding a date or time: {@code long}, {@link Long}, {@link Calendar},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
   266
 * {@link Date} and {@link TemporalAccessor TemporalAccessor}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   268
 * <li> <b>Percent</b> - produces a literal {@code '%'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * (<tt>'&#92;u0025'</tt>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * <li> <b>Line Separator</b> - produces the platform-specific line separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * <p> The following table summarizes the supported conversions.  Conversions
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   276
 * denoted by an upper-case character (i.e. {@code 'B'}, {@code 'H'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   277
 * {@code 'S'}, {@code 'C'}, {@code 'X'}, {@code 'E'}, {@code 'G'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   278
 * {@code 'A'}, and {@code 'T'}) are the same as those for the corresponding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * lower-case conversion characters except that the result is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * upper case according to the rules of the prevailing {@link java.util.Locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * Locale}.  The result is equivalent to the following invocation of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * String#toUpperCase()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *    out.toUpperCase() </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * <table cellpadding=5 summary="genConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * <tr><th valign="bottom"> Conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 *     <th valign="bottom"> Argument Category
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *     <th valign="bottom"> Description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   293
 * <tr><td valign="top"> {@code 'b'}, {@code 'B'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 *     <td valign="top"> general
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   295
 *     <td> If the argument <i>arg</i> is {@code null}, then the result is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   296
 *     "{@code false}".  If <i>arg</i> is a {@code boolean} or {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 *     Boolean}, then the result is the string returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 *     String#valueOf(boolean) String.valueOf(arg)}.  Otherwise, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *     "true".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   301
 * <tr><td valign="top"> {@code 'h'}, {@code 'H'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *     <td valign="top"> general
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   303
 *     <td> If the argument <i>arg</i> is {@code null}, then the result is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   304
 *     "{@code null}".  Otherwise, the result is obtained by invoking
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   305
 *     {@code Integer.toHexString(arg.hashCode())}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   306
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   307
 * <tr><td valign="top"> {@code 's'}, {@code 'S'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *     <td valign="top"> general
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   309
 *     <td> If the argument <i>arg</i> is {@code null}, then the result is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   310
 *     "{@code null}".  If <i>arg</i> implements {@link Formattable}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 *     {@link Formattable#formatTo arg.formatTo} is invoked. Otherwise, the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   312
 *     result is obtained by invoking {@code arg.toString()}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   313
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   314
 * <tr><td valign="top">{@code 'c'}, {@code 'C'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 *     <td valign="top"> character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 *     <td> The result is a Unicode character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   318
 * <tr><td valign="top">{@code 'd'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 *     <td valign="top"> integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 *     <td> The result is formatted as a decimal integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   322
 * <tr><td valign="top">{@code 'o'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 *     <td valign="top"> integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 *     <td> The result is formatted as an octal integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   326
 * <tr><td valign="top">{@code 'x'}, {@code 'X'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 *     <td valign="top"> integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 *     <td> The result is formatted as a hexadecimal integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   330
 * <tr><td valign="top">{@code 'e'}, {@code 'E'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 *     <td valign="top"> floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 *     <td> The result is formatted as a decimal number in computerized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 *     scientific notation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   335
 * <tr><td valign="top">{@code 'f'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 *     <td valign="top"> floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 *     <td> The result is formatted as a decimal number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   339
 * <tr><td valign="top">{@code 'g'}, {@code 'G'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 *     <td valign="top"> floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 *     <td> The result is formatted using computerized scientific notation or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 *     decimal format, depending on the precision and the value after rounding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   344
 * <tr><td valign="top">{@code 'a'}, {@code 'A'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 *     <td valign="top"> floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 *     <td> The result is formatted as a hexadecimal floating-point number with
15524
b77777dcac17 5035569: Formatter should document that %a conversion unsupported for BigDecimal args
alanb
parents: 15289
diff changeset
   347
 *     a significand and an exponent. This conversion is <b>not</b> supported
b77777dcac17 5035569: Formatter should document that %a conversion unsupported for BigDecimal args
alanb
parents: 15289
diff changeset
   348
 *     for the {@code BigDecimal} type despite the latter's being in the
b77777dcac17 5035569: Formatter should document that %a conversion unsupported for BigDecimal args
alanb
parents: 15289
diff changeset
   349
 *     <i>floating point</i> argument category.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   351
 * <tr><td valign="top">{@code 't'}, {@code 'T'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 *     <td valign="top"> date/time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 *     <td> Prefix for date and time conversion characters.  See <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 *     href="#dt">Date/Time Conversions</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   356
 * <tr><td valign="top">{@code '%'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 *     <td valign="top"> percent
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   358
 *     <td> The result is a literal {@code '%'} (<tt>'&#92;u0025'</tt>)
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   359
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   360
 * <tr><td valign="top">{@code 'n'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 *     <td valign="top"> line separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 *     <td> The result is the platform-specific line separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * <p> Any characters not explicitly defined as conversions are illegal and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * reserved for future extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * <h4><a name="dt">Date/Time Conversions</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * <p> The following date and time conversion suffix characters are defined for
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   372
 * the {@code 't'} and {@code 'T'} conversions.  The types are similar to but
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   373
 * not completely identical to those defined by GNU {@code date} and POSIX
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   374
 * {@code strftime(3c)}.  Additional conversion types are provided to access
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   375
 * Java-specific functionality (e.g. {@code 'L'} for milliseconds within the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * second).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 * <p> The following conversion characters are used for formatting times:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * <table cellpadding=5 summary="time">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   382
 * <tr><td valign="top"> {@code 'H'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 *     <td> Hour of the day for the 24-hour clock, formatted as two digits with
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   384
 *     a leading zero as necessary i.e. {@code 00 - 23}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   385
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   386
 * <tr><td valign="top">{@code 'I'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 *     <td> Hour for the 12-hour clock, formatted as two digits with a leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   388
 *     zero as necessary, i.e.  {@code 01 - 12}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   389
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   390
 * <tr><td valign="top">{@code 'k'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   391
 *     <td> Hour of the day for the 24-hour clock, i.e. {@code 0 - 23}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   392
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   393
 * <tr><td valign="top">{@code 'l'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   394
 *     <td> Hour for the 12-hour clock, i.e. {@code 1 - 12}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   395
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   396
 * <tr><td valign="top">{@code 'M'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 *     <td> Minute within the hour formatted as two digits with a leading zero
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   398
 *     as necessary, i.e.  {@code 00 - 59}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   399
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   400
 * <tr><td valign="top">{@code 'S'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
 *     <td> Seconds within the minute, formatted as two digits with a leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   402
 *     zero as necessary, i.e. {@code 00 - 60} ("{@code 60}" is a special
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
 *     value required to support leap seconds).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   405
 * <tr><td valign="top">{@code 'L'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 *     <td> Millisecond within the second formatted as three digits with
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   407
 *     leading zeros as necessary, i.e. {@code 000 - 999}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   408
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   409
 * <tr><td valign="top">{@code 'N'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 *     <td> Nanosecond within the second, formatted as nine digits with leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   411
 *     zeros as necessary, i.e. {@code 000000000 - 999999999}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   412
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   413
 * <tr><td valign="top">{@code 'p'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
 *     <td> Locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 *     java.text.DateFormatSymbols#getAmPmStrings morning or afternoon} marker
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   416
 *     in lower case, e.g."{@code am}" or "{@code pm}". Use of the conversion
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   417
 *     prefix {@code 'T'} forces this output to upper case.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   418
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   419
 * <tr><td valign="top">{@code 'z'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 *     <td> <a href="http://www.ietf.org/rfc/rfc0822.txt">RFC&nbsp;822</a>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   421
 *     style numeric time zone offset from GMT, e.g. {@code -0800}.  This
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 *     value will be adjusted as necessary for Daylight Saving Time.  For
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   423
 *     {@code long}, {@link Long}, and {@link Date} the time zone used is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   424
 *     the {@linkplain TimeZone#getDefault() default time zone} for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 *     instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   427
 * <tr><td valign="top">{@code 'Z'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 *     <td> A string representing the abbreviation for the time zone.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 *     value will be adjusted as necessary for Daylight Saving Time.  For
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   430
 *     {@code long}, {@link Long}, and {@link Date} the  time zone used is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   431
 *     the {@linkplain TimeZone#getDefault() default time zone} for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 *     instance of the Java virtual machine.  The Formatter's locale will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 *     supersede the locale of the argument (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   435
 * <tr><td valign="top">{@code 's'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 *     <td> Seconds since the beginning of the epoch starting at 1 January 1970
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   437
 *     {@code 00:00:00} UTC, i.e. {@code Long.MIN_VALUE/1000} to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   438
 *     {@code Long.MAX_VALUE/1000}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   439
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   440
 * <tr><td valign="top">{@code 'Q'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 *     <td> Milliseconds since the beginning of the epoch starting at 1 January
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   442
 *     1970 {@code 00:00:00} UTC, i.e. {@code Long.MIN_VALUE} to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   443
 *     {@code Long.MAX_VALUE}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
 * <p> The following conversion characters are used for formatting dates:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
 * <table cellpadding=5 summary="date">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   451
 * <tr><td valign="top">{@code 'B'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 *     <td> Locale-specific {@linkplain java.text.DateFormatSymbols#getMonths
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   453
 *     full month name}, e.g. {@code "January"}, {@code "February"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   454
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   455
 * <tr><td valign="top">{@code 'b'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
 *     <td> Locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
 *     java.text.DateFormatSymbols#getShortMonths abbreviated month name},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   458
 *     e.g. {@code "Jan"}, {@code "Feb"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   459
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   460
 * <tr><td valign="top">{@code 'h'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   461
 *     <td> Same as {@code 'b'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   462
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   463
 * <tr><td valign="top">{@code 'A'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 *     <td> Locale-specific full name of the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 *     java.text.DateFormatSymbols#getWeekdays day of the week},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   466
 *     e.g. {@code "Sunday"}, {@code "Monday"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   467
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   468
 * <tr><td valign="top">{@code 'a'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
 *     <td> Locale-specific short name of the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
 *     java.text.DateFormatSymbols#getShortWeekdays day of the week},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   471
 *     e.g. {@code "Sun"}, {@code "Mon"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   472
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   473
 * <tr><td valign="top">{@code 'C'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   474
 *     <td> Four-digit year divided by {@code 100}, formatted as two digits
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   475
 *     with leading zero as necessary, i.e. {@code 00 - 99}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   476
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   477
 * <tr><td valign="top">{@code 'Y'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
 *     <td> Year, formatted as at least four digits with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   479
 *     necessary, e.g. {@code 0092} equals {@code 92} CE for the Gregorian
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 *     calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   482
 * <tr><td valign="top">{@code 'y'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
 *     <td> Last two digits of the year, formatted with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   484
 *     necessary, i.e. {@code 00 - 99}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   485
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   486
 * <tr><td valign="top">{@code 'j'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 *     <td> Day of year, formatted as three digits with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   488
 *     necessary, e.g. {@code 001 - 366} for the Gregorian calendar.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   489
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   490
 * <tr><td valign="top">{@code 'm'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 *     <td> Month, formatted as two digits with leading zeros as necessary,
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   492
 *     i.e. {@code 01 - 13}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   493
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   494
 * <tr><td valign="top">{@code 'd'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 *     <td> Day of month, formatted as two digits with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   496
 *     necessary, i.e. {@code 01 - 31}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   497
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   498
 * <tr><td valign="top">{@code 'e'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   499
 *     <td> Day of month, formatted as two digits, i.e. {@code 1 - 31}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
 * <p> The following conversion characters are used for formatting common
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
 * date/time compositions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
 * <table cellpadding=5 summary="composites">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   508
 * <tr><td valign="top">{@code 'R'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   509
 *     <td> Time formatted for the 24-hour clock as {@code "%tH:%tM"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   510
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   511
 * <tr><td valign="top">{@code 'T'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   512
 *     <td> Time formatted for the 24-hour clock as {@code "%tH:%tM:%tS"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   513
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   514
 * <tr><td valign="top">{@code 'r'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   515
 *     <td> Time formatted for the 12-hour clock as {@code "%tI:%tM:%tS %Tp"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   516
 *     The location of the morning or afternoon marker ({@code '%Tp'}) may be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
 *     locale-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   519
 * <tr><td valign="top">{@code 'D'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   520
 *     <td> Date formatted as {@code "%tm/%td/%ty"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   521
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   522
 * <tr><td valign="top">{@code 'F'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 *     <td> <a href="http://www.w3.org/TR/NOTE-datetime">ISO&nbsp;8601</a>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   524
 *     complete date formatted as {@code "%tY-%tm-%td"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   525
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   526
 * <tr><td valign="top">{@code 'c'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   527
 *     <td> Date and time formatted as {@code "%ta %tb %td %tT %tZ %tY"},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   528
 *     e.g. {@code "Sun Jul 20 16:17:00 EDT 1969"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
 * <p> Any characters not explicitly defined as date/time conversion suffixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
 * are illegal and are reserved for future extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
 * <h4> Flags </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
 * <p> The following table summarizes the supported flags.  <i>y</i> means the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
 * flag is supported for the indicated argument types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
 * <table cellpadding=5 summary="genConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
 * <tr><th valign="bottom"> Flag <th valign="bottom"> General
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
 *     <th valign="bottom"> Character <th valign="bottom"> Integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
 *     <th valign="bottom"> Floating Point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
 *     <th valign="bottom"> Date/Time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
 *     <th valign="bottom"> Description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
 * <tr><td> '-' <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 *     <td> The result will be left-justified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 * <tr><td> '#' <td align="center" valign="top"> y<sup>1</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
 *     <td align="center" valign="top"> y<sup>3</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
 *     <td> The result should use a conversion-dependent alternate form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
 * <tr><td> '+' <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
 *     <td align="center" valign="top"> y<sup>4</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
 *     <td> The result will always include a sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
 * <tr><td> '&nbsp;&nbsp;' <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
 *     <td align="center" valign="top"> y<sup>4</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
 *     <td> The result will include a leading space for positive values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
 * <tr><td> '0' <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 *     <td align="center" valign="top"> y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 *     <td> The result will be zero-padded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
 * <tr><td> ',' <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
 *     <td align="center" valign="top"> y<sup>2</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
 *     <td align="center" valign="top"> y<sup>5</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
 *     <td> The result will include locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
 *     java.text.DecimalFormatSymbols#getGroupingSeparator grouping separators}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
 * <tr><td> '(' <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
 *     <td align="center" valign="top"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
 *     <td align="center" valign="top"> y<sup>4</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
 *     <td align="center" valign="top"> y<sup>5</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
 *     <td align="center"> -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
 *     <td> The result will enclose negative numbers in parentheses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
 * <p> <sup>1</sup> Depends on the definition of {@link Formattable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   602
 * <p> <sup>2</sup> For {@code 'd'} conversion only.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   603
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   604
 * <p> <sup>3</sup> For {@code 'o'}, {@code 'x'}, and {@code 'X'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
 * conversions only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   607
 * <p> <sup>4</sup> For {@code 'd'}, {@code 'o'}, {@code 'x'}, and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   608
 * {@code 'X'} conversions applied to {@link java.math.BigInteger BigInteger}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   609
 * or {@code 'd'} applied to {@code byte}, {@link Byte}, {@code short}, {@link
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   610
 * Short}, {@code int} and {@link Integer}, {@code long}, and {@link Long}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   611
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   612
 * <p> <sup>5</sup> For {@code 'e'}, {@code 'E'}, {@code 'f'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   613
 * {@code 'g'}, and {@code 'G'} conversions only.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
 * <p> Any characters not explicitly defined as flags are illegal and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
 * reserved for future extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
 * <h4> Width </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 * <p> The width is the minimum number of characters to be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 * output.  For the line separator conversion, width is not applicable; if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
 * is provided, an exception will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 * <h4> Precision </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 * <p> For general argument types, the precision is the maximum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 * characters to be written to the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 *
19196
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
   629
 * <p> For the floating-point conversions {@code 'a'}, {@code 'A'}, {@code 'e'},
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
   630
 * {@code 'E'}, and {@code 'f'} the precision is the number of digits after the
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
   631
 * radix point.  If the conversion is {@code 'g'} or {@code 'G'}, then the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
 * precision is the total number of digits in the resulting magnitude after
19196
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
   633
 * rounding.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
 * <p> For character, integral, and date/time argument types and the percent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 * and line separator conversions, the precision is not applicable; if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * precision is provided, an exception will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * <h4> Argument Index </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 * <p> The argument index is a decimal integer indicating the position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
 * argument in the argument list.  The first argument is referenced by
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   643
 * "{@code 1$}", the second by "{@code 2$}", etc.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
 * <p> Another way to reference arguments by position is to use the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   646
 * {@code '<'} (<tt>'&#92;u003c'</tt>) flag, which causes the argument for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 * the previous format specifier to be re-used.  For example, the following two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 * statements would produce identical strings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
 *   Calendar c = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
 *   String s1 = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
 *   String s2 = String.format("Duke's Birthday: %1$tm %&lt;te,%&lt;tY", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
 * <hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
 * <h3><a name="detail">Details</a></h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
 * <p> This section is intended to provide behavioral details for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
 * including conditions and exceptions, supported data types, localization, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
 * interactions between flags, conversions, and data types.  For an overview of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
 * formatting concepts, refer to the <a href="#summary">Summary</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
 * <p> Any characters not explicitly defined as conversions, date/time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
 * conversion suffixes, or flags are illegal and are reserved for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
 * future extensions.  Use of such a character in a format string will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
 * cause an {@link UnknownFormatConversionException} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
 * UnknownFormatFlagsException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
 * <p> If the format specifier contains a width or precision with an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
 * value or which is otherwise unsupported, then a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
 * IllegalFormatWidthException} or {@link IllegalFormatPrecisionException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
 * respectively will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
 * <p> If a format specifier contains a conversion character that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
 * applicable to the corresponding argument, then an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
 * IllegalFormatConversionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   680
 * <p> All specified exceptions may be thrown by any of the {@code format}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   681
 * methods of {@code Formatter} as well as by any {@code format} convenience
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
 * methods such as {@link String#format(String,Object...) String.format} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
 * {@link java.io.PrintStream#printf(String,Object...) PrintStream.printf}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   685
 * <p> Conversions denoted by an upper-case character (i.e. {@code 'B'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   686
 * {@code 'H'}, {@code 'S'}, {@code 'C'}, {@code 'X'}, {@code 'E'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   687
 * {@code 'G'}, {@code 'A'}, and {@code 'T'}) are the same as those for the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
 * corresponding lower-case conversion characters except that the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
 * converted to upper case according to the rules of the prevailing {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
 * java.util.Locale Locale}.  The result is equivalent to the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
 * invocation of {@link String#toUpperCase()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
 *    out.toUpperCase() </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
 * <h4><a name="dgen">General</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 * <p> The following general conversions may be applied to any argument type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
 * <table cellpadding=5 summary="dgConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   702
 * <tr><td valign="top"> {@code 'b'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
 *     <td valign="top"> <tt>'&#92;u0062'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   704
 *     <td> Produces either "{@code true}" or "{@code false}" as returned by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
 *     {@link Boolean#toString(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   707
 *     <p> If the argument is {@code null}, then the result is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   708
 *     "{@code false}".  If the argument is a {@code boolean} or {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
 *     Boolean}, then the result is the string returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
 *     String#valueOf(boolean) String.valueOf()}.  Otherwise, the result is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   711
 *     "{@code true}".
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   712
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   713
 *     <p> If the {@code '#'} flag is given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   716
 * <tr><td valign="top"> {@code 'B'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
 *     <td valign="top"> <tt>'&#92;u0042'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   718
 *     <td> The upper-case variant of {@code 'b'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   719
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   720
 * <tr><td valign="top"> {@code 'h'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
 *     <td valign="top"> <tt>'&#92;u0068'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
 *     <td> Produces a string representing the hash code value of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   724
 *     <p> If the argument, <i>arg</i> is {@code null}, then the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   725
 *     result is "{@code null}".  Otherwise, the result is obtained
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   726
 *     by invoking {@code Integer.toHexString(arg.hashCode())}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   727
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   728
 *     <p> If the {@code '#'} flag is given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   731
 * <tr><td valign="top"> {@code 'H'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
 *     <td valign="top"> <tt>'&#92;u0048'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   733
 *     <td> The upper-case variant of {@code 'h'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   734
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   735
 * <tr><td valign="top"> {@code 's'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 *     <td valign="top"> <tt>'&#92;u0073'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
 *     <td> Produces a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   739
 *     <p> If the argument is {@code null}, then the result is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   740
 *     "{@code null}".  If the argument implements {@link Formattable}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 *     its {@link Formattable#formatTo formatTo} method is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 *     Otherwise, the result is obtained by invoking the argument's
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   743
 *     {@code toString()} method.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   744
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   745
 *     <p> If the {@code '#'} flag is given and the argument is not a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 *     Formattable} , then a {@link FormatFlagsConversionMismatchException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 *     will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   749
 * <tr><td valign="top"> {@code 'S'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
 *     <td valign="top"> <tt>'&#92;u0053'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   751
 *     <td> The upper-case variant of {@code 's'}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
 * <p> The following <a name="dFlags">flags</a> apply to general conversions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
 * <table cellpadding=5 summary="dFlags">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   759
 * <tr><td valign="top"> {@code '-'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
 *     <td valign="top"> <tt>'&#92;u002d'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
 *     <td> Left justifies the output.  Spaces (<tt>'&#92;u0020'</tt>) will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
 *     added at the end of the converted value as required to fill the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
 *     width of the field.  If the width is not provided, then a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
 *     MissingFormatWidthException} will be thrown.  If this flag is not given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
 *     then the output will be right-justified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   767
 * <tr><td valign="top"> {@code '#'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
 *     <td valign="top"> <tt>'&#92;u0023'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 *     <td> Requires the output use an alternate form.  The definition of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 *     form is specified by the conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * <p> The <a name="genWidth">width</a> is the minimum number of characters to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 * be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 * output.  If the length of the converted value is less than the width then
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   777
 * the output will be padded by <tt>'&nbsp;&nbsp;'</tt> (<tt>'&#92;u0020'</tt>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
 * until the total number of characters equals the width.  The padding is on
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   779
 * the left by default.  If the {@code '-'} flag is given, then the padding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
 * will be on the right.  If the width is not specified then there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
 * minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
 * <p> The precision is the maximum number of characters to be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
 * output.  The precision is applied before the width, thus the output will be
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   785
 * truncated to {@code precision} characters even if the width is greater than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 * the precision.  If the precision is not specified then there is no explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
 * limit on the number of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
 * <h4><a name="dchar">Character</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   791
 * This conversion may be applied to {@code char} and {@link Character}.  It
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   792
 * may also be applied to the types {@code byte}, {@link Byte},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   793
 * {@code short}, and {@link Short}, {@code int} and {@link Integer} when
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   794
 * {@link Character#isValidCodePoint} returns {@code true}.  If it returns
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   795
 * {@code false} then an {@link IllegalFormatCodePointException} will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 * <table cellpadding=5 summary="charConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   800
 * <tr><td valign="top"> {@code 'c'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 *     <td valign="top"> <tt>'&#92;u0063'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 *     <td> Formats the argument as a Unicode character as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
 *     href="../lang/Character.html#unicode">Unicode Character
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   804
 *     Representation</a>.  This may be more than one 16-bit {@code char} in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
 *     the case where the argument represents a supplementary character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   807
 *     <p> If the {@code '#'} flag is given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   810
 * <tr><td valign="top"> {@code 'C'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
 *     <td valign="top"> <tt>'&#92;u0043'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   812
 *     <td> The upper-case variant of {@code 'c'}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   816
 * <p> The {@code '-'} flag defined for <a href="#dFlags">General
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   817
 * conversions</a> applies.  If the {@code '#'} flag is given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
 * FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
 * <p> The width is defined as for <a href="#genWidth">General conversions</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
 * <p> The precision is not applicable.  If the precision is specified then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
 * {@link IllegalFormatPrecisionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
 * <h4><a name="dnum">Numeric</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
 * <p> Numeric conversions are divided into the following categories:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
 * <li> <a href="#dnint"><b>Byte, Short, Integer, and Long</b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
 * <li> <a href="#dnbint"><b>BigInteger</b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
 * <li> <a href="#dndec"><b>Float and Double</b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
 *
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
   837
 * <li> <a href="#dnbdec"><b>BigDecimal</b></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
 * <p> Numeric types will be formatted according to the following algorithm:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
 *
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
   843
 * <p><b><a name="L10nAlgorithm"> Number Localization Algorithm</a></b>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
 * <p> After digits are obtained for the integer part, fractional part, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
 * exponent (as appropriate for the data type), the following transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
 * is applied:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
 * <li> Each digit character <i>d</i> in the string is replaced by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
 * locale-specific digit computed relative to the current locale's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
 * {@linkplain java.text.DecimalFormatSymbols#getZeroDigit() zero digit}
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   854
 * <i>z</i>; that is <i>d&nbsp;-&nbsp;</i> {@code '0'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
 * <i>&nbsp;+&nbsp;z</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
 * <li> If a decimal separator is present, a locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
 * java.text.DecimalFormatSymbols#getDecimalSeparator decimal separator} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 * substituted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   861
 * <li> If the {@code ','} (<tt>'&#92;u002c'</tt>)
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
   862
 * <a name="L10nGroup">flag</a> is given, then the locale-specific {@linkplain
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
 * java.text.DecimalFormatSymbols#getGroupingSeparator grouping separator} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
 * inserted by scanning the integer part of the string from least significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
 * to most significant digits and inserting a separator at intervals defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
 * the locale's {@linkplain java.text.DecimalFormat#getGroupingSize() grouping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
 * size}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   869
 * <li> If the {@code '0'} flag is given, then the locale-specific {@linkplain
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
 * java.text.DecimalFormatSymbols#getZeroDigit() zero digits} are inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
 * after the sign character, if any, and before the first non-zero digit, until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
 * the length of the string is equal to the requested field width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   874
 * <li> If the value is negative and the {@code '('} flag is given, then a
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   875
 * {@code '('} (<tt>'&#92;u0028'</tt>) is prepended and a {@code ')'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
 * (<tt>'&#92;u0029'</tt>) is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
 * <li> If the value is negative (or floating-point negative zero) and
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   879
 * {@code '('} flag is not given, then a {@code '-'} (<tt>'&#92;u002d'</tt>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 * is prepended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   882
 * <li> If the {@code '+'} flag is given and the value is positive or zero (or
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   883
 * floating-point positive zero), then a {@code '+'} (<tt>'&#92;u002b'</tt>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 * will be prepended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
 * <p> If the value is NaN or positive infinity the literal strings "NaN" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
 * "Infinity" respectively, will be output.  If the value is negative infinity,
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   890
 * then the output will be "(Infinity)" if the {@code '('} flag is given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
 * otherwise the output will be "-Infinity".  These values are not localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
 * <p><a name="dnint"><b> Byte, Short, Integer, and Long </b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   895
 * <p> The following conversions may be applied to {@code byte}, {@link Byte},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   896
 * {@code short}, {@link Short}, {@code int} and {@link Integer},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   897
 * {@code long}, and {@link Long}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
 * <table cellpadding=5 summary="IntConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   901
 * <tr><td valign="top"> {@code 'd'}
21368
7b48f137e525 5063500: Formatter spec says "char" is not an integral type
smarks
parents: 20795
diff changeset
   902
 *     <td valign="top"> <tt>'&#92;u0064'</tt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
 *     <td> Formats the argument as a decimal integer. The <a
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
   904
 *     href="#L10nAlgorithm">localization algorithm</a> is applied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   906
 *     <p> If the {@code '0'} flag is given and the value is negative, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
 *     the zero padding will occur after the sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   909
 *     <p> If the {@code '#'} flag is given then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   912
 * <tr><td valign="top"> {@code 'o'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 *     <td valign="top"> <tt>'&#92;u006f'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 *     <td> Formats the argument as an integer in base eight.  No localization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 *     is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 *     <p> If <i>x</i> is negative then the result will be an unsigned value
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   918
 *     generated by adding 2<sup>n</sup> to the value where {@code n} is the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   919
 *     number of bits in the type as returned by the static {@code SIZE} field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
 *     in the {@linkplain Byte#SIZE Byte}, {@linkplain Short#SIZE Short},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
 *     {@linkplain Integer#SIZE Integer}, or {@linkplain Long#SIZE Long}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
 *     classes as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   924
 *     <p> If the {@code '#'} flag is given then the output will always begin
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   925
 *     with the radix indicator {@code '0'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   926
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   927
 *     <p> If the {@code '0'} flag is given then the output will be padded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
 *     with leading zeros to the field width following any indication of sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
 *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11135
diff changeset
   930
 *     <p> If {@code '('}, {@code '+'}, '&nbsp;&nbsp;', or {@code ','} flags
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
 *     are given then a {@link FormatFlagsConversionMismatchException} will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 *     thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   934
 * <tr><td valign="top"> {@code 'x'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
 *     <td valign="top"> <tt>'&#92;u0078'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
 *     <td> Formats the argument as an integer in base sixteen. No
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 *     localization is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
 *     <p> If <i>x</i> is negative then the result will be an unsigned value
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   940
 *     generated by adding 2<sup>n</sup> to the value where {@code n} is the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   941
 *     number of bits in the type as returned by the static {@code SIZE} field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
 *     in the {@linkplain Byte#SIZE Byte}, {@linkplain Short#SIZE Short},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
 *     {@linkplain Integer#SIZE Integer}, or {@linkplain Long#SIZE Long}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
 *     classes as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   946
 *     <p> If the {@code '#'} flag is given then the output will always begin
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   947
 *     with the radix indicator {@code "0x"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   948
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   949
 *     <p> If the {@code '0'} flag is given then the output will be padded to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
 *     the field width with leading zeros after the radix indicator or sign (if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
 *     present).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   953
 *     <p> If {@code '('}, <tt>'&nbsp;&nbsp;'</tt>, {@code '+'}, or
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   954
 *     {@code ','} flags are given then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   957
 * <tr><td valign="top"> {@code 'X'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 *     <td valign="top"> <tt>'&#92;u0058'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   959
 *     <td> The upper-case variant of {@code 'x'}.  The entire string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
 *     representing the number will be converted to {@linkplain
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   961
 *     String#toUpperCase upper case} including the {@code 'x'} (if any) and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   962
 *     all hexadecimal digits {@code 'a'} - {@code 'f'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
 *     (<tt>'&#92;u0061'</tt> -  <tt>'&#92;u0066'</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   967
 * <p> If the conversion is {@code 'o'}, {@code 'x'}, or {@code 'X'} and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   968
 * both the {@code '#'} and the {@code '0'} flags are given, then result will
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   969
 * contain the radix indicator ({@code '0'} for octal and {@code "0x"} or
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   970
 * {@code "0X"} for hexadecimal), some number of zeros (based on the width),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
 * and the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   973
 * <p> If the {@code '-'} flag is not given, then the space padding will occur
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
 * before the sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
 * <p> The following <a name="intFlags">flags</a> apply to numeric integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
 * conversions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
 * <table cellpadding=5 summary="intFlags">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   981
 * <tr><td valign="top"> {@code '+'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
 *     <td valign="top"> <tt>'&#92;u002b'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
 *     <td> Requires the output to include a positive sign for all positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
 *     numbers.  If this flag is not given then only negative values will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
 *     include a sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   987
 *     <p> If both the {@code '+'} and <tt>'&nbsp;&nbsp;'</tt> flags are given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
 *     then an {@link IllegalFormatFlagsException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
 * <tr><td valign="top"> <tt>'&nbsp;&nbsp;'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
 *     <td valign="top"> <tt>'&#92;u0020'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
 *     <td> Requires the output to include a single extra space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
 *     (<tt>'&#92;u0020'</tt>) for non-negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   995
 *     <p> If both the {@code '+'} and <tt>'&nbsp;&nbsp;'</tt> flags are given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
 *     then an {@link IllegalFormatFlagsException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
   998
 * <tr><td valign="top"> {@code '0'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
 *     <td valign="top"> <tt>'&#92;u0030'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
 *     <td> Requires the output to be padded with leading {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
 *     java.text.DecimalFormatSymbols#getZeroDigit zeros} to the minimum field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
 *     width following any sign or radix indicator except when converting NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
 *     or infinity.  If the width is not provided, then a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
 *     MissingFormatWidthException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1006
 *     <p> If both the {@code '-'} and {@code '0'} flags are given then an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
 *     {@link IllegalFormatFlagsException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1009
 * <tr><td valign="top"> {@code ','}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
 *     <td valign="top"> <tt>'&#92;u002c'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
 *     <td> Requires the output to include the locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
 *     java.text.DecimalFormatSymbols#getGroupingSeparator group separators} as
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1013
 *     described in the <a href="#L10nGroup">"group" section</a> of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
 *     localization algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1016
 * <tr><td valign="top"> {@code '('}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
 *     <td valign="top"> <tt>'&#92;u0028'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1018
 *     <td> Requires the output to prepend a {@code '('}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1019
 *     (<tt>'&#92;u0028'</tt>) and append a {@code ')'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
 *     (<tt>'&#92;u0029'</tt>) to negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
 * <p> If no <a name="intdFlags">flags</a> are given the default formatting is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
 * as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1029
 * <li> The output is right-justified within the {@code width}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1030
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1031
 * <li> Negative numbers begin with a {@code '-'} (<tt>'&#92;u002d'</tt>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
 * <li> Positive numbers and zero do not include a sign or extra leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
 * space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
 * <li> No grouping separators are included
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
 * <p> The <a name="intWidth">width</a> is the minimum number of characters to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
 * be written to the output.  This includes any signs, digits, grouping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
 * separators, radix indicator, and parentheses.  If the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
 * converted value is less than the width then the output will be padded by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
 * spaces (<tt>'&#92;u0020'</tt>) until the total number of characters equals
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1045
 * width.  The padding is on the left by default.  If {@code '-'} flag is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
 * given then the padding will be on the right.  If width is not specified then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
 * there is no minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
 * <p> The precision is not applicable.  If precision is specified then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
 * {@link IllegalFormatPrecisionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
 * <p><a name="dnbint"><b> BigInteger </b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
 * <p> The following conversions may be applied to {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
 * java.math.BigInteger}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
 * <table cellpadding=5 summary="BIntConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1059
 * <tr><td valign="top"> {@code 'd'}
21368
7b48f137e525 5063500: Formatter spec says "char" is not an integral type
smarks
parents: 20795
diff changeset
  1060
 *     <td valign="top"> <tt>'&#92;u0064'</tt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
 *     <td> Requires the output to be formatted as a decimal integer. The <a
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1062
 *     href="#L10nAlgorithm">localization algorithm</a> is applied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1064
 *     <p> If the {@code '#'} flag is given {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1067
 * <tr><td valign="top"> {@code 'o'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
 *     <td valign="top"> <tt>'&#92;u006f'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
 *     <td> Requires the output to be formatted as an integer in base eight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
 *     No localization is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
 *     <p> If <i>x</i> is negative then the result will be a signed value
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1073
 *     beginning with {@code '-'} (<tt>'&#92;u002d'</tt>).  Signed output is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
 *     allowed for this type because unlike the primitive types it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
 *     possible to create an unsigned equivalent without assuming an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
 *     data-type size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1078
 *     <p> If <i>x</i> is positive or zero and the {@code '+'} flag is given
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1079
 *     then the result will begin with {@code '+'} (<tt>'&#92;u002b'</tt>).
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1080
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1081
 *     <p> If the {@code '#'} flag is given then the output will always begin
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1082
 *     with {@code '0'} prefix.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1083
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1084
 *     <p> If the {@code '0'} flag is given then the output will be padded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
 *     with leading zeros to the field width following any indication of sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1087
 *     <p> If the {@code ','} flag is given then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1090
 * <tr><td valign="top"> {@code 'x'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
 *     <td valign="top"> <tt>'&#92;u0078'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
 *     <td> Requires the output to be formatted as an integer in base
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
 *     sixteen.  No localization is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
 *     <p> If <i>x</i> is negative then the result will be a signed value
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1096
 *     beginning with {@code '-'} (<tt>'&#92;u002d'</tt>).  Signed output is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
 *     allowed for this type because unlike the primitive types it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
 *     possible to create an unsigned equivalent without assuming an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
 *     data-type size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1101
 *     <p> If <i>x</i> is positive or zero and the {@code '+'} flag is given
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1102
 *     then the result will begin with {@code '+'} (<tt>'&#92;u002b'</tt>).
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1103
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1104
 *     <p> If the {@code '#'} flag is given then the output will always begin
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1105
 *     with the radix indicator {@code "0x"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1106
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1107
 *     <p> If the {@code '0'} flag is given then the output will be padded to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
 *     the field width with leading zeros after the radix indicator or sign (if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
 *     present).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1111
 *     <p> If the {@code ','} flag is given then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1114
 * <tr><td valign="top"> {@code 'X'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
 *     <td valign="top"> <tt>'&#92;u0058'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1116
 *     <td> The upper-case variant of {@code 'x'}.  The entire string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
 *     representing the number will be converted to {@linkplain
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1118
 *     String#toUpperCase upper case} including the {@code 'x'} (if any) and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1119
 *     all hexadecimal digits {@code 'a'} - {@code 'f'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
 *     (<tt>'&#92;u0061'</tt> - <tt>'&#92;u0066'</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1124
 * <p> If the conversion is {@code 'o'}, {@code 'x'}, or {@code 'X'} and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1125
 * both the {@code '#'} and the {@code '0'} flags are given, then result will
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1126
 * contain the base indicator ({@code '0'} for octal and {@code "0x"} or
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1127
 * {@code "0X"} for hexadecimal), some number of zeros (based on the width),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
 * and the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1130
 * <p> If the {@code '0'} flag is given and the value is negative, then the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
 * zero padding will occur after the sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1133
 * <p> If the {@code '-'} flag is not given, then the space padding will occur
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
 * before the sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
 * Long apply.  The <a href="#intdFlags">default behavior</a> when no flags are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
 * given is the same as for Byte, Short, Integer, and Long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
 * <p> The specification of <a href="#intWidth">width</a> is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
 * defined for Byte, Short, Integer, and Long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
 * <p> The precision is not applicable.  If precision is specified then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
 * {@link IllegalFormatPrecisionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
 * <p><a name="dndec"><b> Float and Double</b></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1148
 * <p> The following conversions may be applied to {@code float}, {@link
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1149
 * Float}, {@code double} and {@link Double}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
 * <table cellpadding=5 summary="floatConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1153
 * <tr><td valign="top"> {@code 'e'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
 *     <td> Requires the output to be formatted using <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
 *     name="scientific">computerized scientific notation</a>.  The <a
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1157
 *     href="#L10nAlgorithm">localization algorithm</a> is applied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
 *     <p> If <i>m</i> is NaN or infinite, the literal strings "NaN" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
 *     "Infinity", respectively, will be output.  These values are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
 *     localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
 *     <p> If <i>m</i> is positive-zero or negative-zero, then the exponent
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1166
 *     will be {@code "+00"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
 *     <p> Otherwise, the result is a string that represents the sign and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
 *     magnitude (absolute value) of the argument.  The formatting of the sign
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1170
 *     is described in the <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
 *     value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
 *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
 *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
 *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
 *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
 *     integer part of <i>a</i>, as a single decimal digit, followed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
 *     decimal separator followed by decimal digits representing the fractional
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1180
 *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
 *     (<tt>'&#92;u0065'</tt>), followed by the sign of the exponent, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
 *     by a representation of <i>n</i> as a decimal integer, as produced by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
 *     method {@link Long#toString(long, int)}, and zero-padded to include at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
 *     least two digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
 *     <p> The number of digits in the result for the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1188
 *     specified then the default value is {@code 6}. If the precision is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
 *     than the number of digits which would appear after the decimal point in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
 *     the string returned by {@link Float#toString(float)} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
 *     Double#toString(double)} respectively, then the value will be rounded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
 *     For a canonical representation of the value, use {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
 *     Float#toString(float)} or {@link Double#toString(double)} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
 *     appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1198
 *     <p>If the {@code ','} flag is given, then an {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1201
 * <tr><td valign="top"> {@code 'E'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
 *     <td valign="top"> <tt>'&#92;u0045'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1203
 *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1204
 *     will be {@code 'E'} (<tt>'&#92;u0045'</tt>).
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1205
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1206
 * <tr><td valign="top"> {@code 'g'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
 *     <td valign="top"> <tt>'&#92;u0067'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
 *     <td> Requires the output to be formatted in general scientific notation
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1209
 *     as described below. The <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
 *     algorithm</a> is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
 *     <p> After rounding for the precision, the formatting of the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
 *     magnitude <i>m</i> depends on its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
 *     <p> If <i>m</i> is greater than or equal to 10<sup>-4</sup> but less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
 *     than 10<sup>precision</sup> then it is represented in <i><a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
 *     href="#decimal">decimal format</a></i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
 *     <p> If <i>m</i> is less than 10<sup>-4</sup> or greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
 *     10<sup>precision</sup>, then it is represented in <i><a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
 *     href="#scientific">computerized scientific notation</a></i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
 *     <p> The total number of significant digits in <i>m</i> is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
 *     precision.  If the precision is not specified, then the default value is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1225
 *     {@code 6}.  If the precision is {@code 0}, then it is taken to be
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1226
 *     {@code 1}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1227
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1228
 *     <p> If the {@code '#'} flag is given then an {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1231
 * <tr><td valign="top"> {@code 'G'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
 *     <td valign="top"> <tt>'&#92;u0047'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1233
 *     <td> The upper-case variant of {@code 'g'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1234
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1235
 * <tr><td valign="top"> {@code 'f'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
 *     <td valign="top"> <tt>'&#92;u0066'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
 *     <td> Requires the output to be formatted using <a name="decimal">decimal
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1238
 *     format</a>.  The <a href="#L10nAlgorithm">localization algorithm</a> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
 *     applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
 *     <p> The result is a string that represents the sign and magnitude
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
 *     (absolute value) of the argument.  The formatting of the sign is
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1243
 *     described in the <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
 *     value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
 *     <p> If <i>m</i> NaN or infinite, the literal strings "NaN" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
 *     "Infinity", respectively, will be output.  These values are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
 *     localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
 *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
 *     leading zeroes, followed by the decimal separator followed by one or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
 *     more decimal digits representing the fractional part of <i>m</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
 *     <p> The number of digits in the result for the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1257
 *     specified then the default value is {@code 6}. If the precision is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
 *     than the number of digits which would appear after the decimal point in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
 *     the string returned by {@link Float#toString(float)} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
 *     Double#toString(double)} respectively, then the value will be rounded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1823
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  1263
 *     For a canonical representation of the value, use {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
 *     Float#toString(float)} or {@link Double#toString(double)} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
 *     appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1267
 * <tr><td valign="top"> {@code 'a'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
 *     <td valign="top"> <tt>'&#92;u0061'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
 *     <td> Requires the output to be formatted in hexadecimal exponential
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
 *     form.  No localization is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
 *     <p> The result is a string that represents the sign and magnitude
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
 *     (absolute value) of the argument <i>x</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
 *     <p> If <i>x</i> is negative or a negative-zero value then the result
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1276
 *     will begin with {@code '-'} (<tt>'&#92;u002d'</tt>).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
 *     <p> If <i>x</i> is positive or a positive-zero value and the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1279
 *     {@code '+'} flag is given then the result will begin with {@code '+'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
 *     (<tt>'&#92;u002b'</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
 *     <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
 *     <li> If the value is NaN or infinite, the literal strings "NaN" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
 *     "Infinity", respectively, will be output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
 *     <li> If <i>m</i> is zero then it is represented by the string
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1290
 *     {@code "0x0.0p0"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1291
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1292
 *     <li> If <i>m</i> is a {@code double} value with a normalized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
 *     representation then substrings are used to represent the significand and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
 *     exponent fields.  The significand is represented by the characters
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1295
 *     {@code "0x1."} followed by the hexadecimal representation of the rest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
 *     of the significand as a fraction.  The exponent is represented by
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1297
 *     {@code 'p'} (<tt>'&#92;u0070'</tt>) followed by a decimal string of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
 *     unbiased exponent as if produced by invoking {@link
19196
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1299
 *     Integer#toString(int) Integer.toString} on the exponent value.  If the
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1300
 *     precision is specified, the value is rounded to the given number of
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1301
 *     hexadecimal digits.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1303
 *     <li> If <i>m</i> is a {@code double} value with a subnormal
19196
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1304
 *     representation then, unless the precision is specified to be in the range
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1305
 *     1 through 12, inclusive, the significand is represented by the characters
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1306
 *     {@code '0x0.'} followed by the hexadecimal representation of the rest of
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1307
 *     the significand as a fraction, and the exponent represented by
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1308
 *     {@code 'p-1022'}.  If the precision is in the interval
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1309
 *     [1,&nbsp;12], the subnormal value is normalized such that it
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1310
 *     begins with the characters {@code '0x1.'}, rounded to the number of
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1311
 *     hexadecimal digits of precision, and the exponent adjusted
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1312
 *     accordingly.  Note that there must be at least one nonzero digit in a
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1313
 *     subnormal significand.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
 *     </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1317
 *     <p> If the {@code '('} or {@code ','} flags are given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1320
 * <tr><td valign="top"> {@code 'A'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
 *     <td valign="top"> <tt>'&#92;u0041'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1322
 *     <td> The upper-case variant of {@code 'a'}.  The entire string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
 *     representing the number will be converted to upper case including the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1324
 *     {@code 'x'} (<tt>'&#92;u0078'</tt>) and {@code 'p'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1325
 *     (<tt>'&#92;u0070'</tt> and all hexadecimal digits {@code 'a'} -
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1326
 *     {@code 'f'} (<tt>'&#92;u0061'</tt> - <tt>'&#92;u0066'</tt>).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
 * Long apply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1333
 * <p> If the {@code '#'} flag is given, then the decimal separator will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
 * always be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
 * <p> If no <a name="floatdFlags">flags</a> are given the default formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
 * is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1341
 * <li> The output is right-justified within the {@code width}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1342
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1343
 * <li> Negative numbers begin with a {@code '-'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
 * <li> Positive numbers and positive zero do not include a sign or extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
 * leading space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
 * <li> No grouping separators are included
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
 * <li> The decimal separator will only appear if a digit follows it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
 * <p> The <a name="floatDWidth">width</a> is the minimum number of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
 * to be written to the output.  This includes any signs, digits, grouping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
 * separators, decimal separators, exponential symbol, radix indicator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
 * parentheses, and strings representing infinity and NaN as applicable.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
 * the length of the converted value is less than the width then the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
 * will be padded by spaces (<tt>'&#92;u0020'</tt>) until the total number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
 * characters equals width.  The padding is on the left by default.  If the
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1361
 * {@code '-'} flag is given then the padding will be on the right.  If width
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
 * is not specified then there is no minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1364
 * <p> If the <a name="floatDPrec">conversion</a> is {@code 'e'},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1365
 * {@code 'E'} or {@code 'f'}, then the precision is the number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
 * after the decimal separator.  If the precision is not specified, then it is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1367
 * assumed to be {@code 6}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1368
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1369
 * <p> If the conversion is {@code 'g'} or {@code 'G'}, then the precision is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
 * the total number of significant digits in the resulting magnitude after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
 * rounding.  If the precision is not specified, then the default value is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1372
 * {@code 6}.  If the precision is {@code 0}, then it is taken to be
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1373
 * {@code 1}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1374
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1375
 * <p> If the conversion is {@code 'a'} or {@code 'A'}, then the precision
19196
5368bd038f19 6476168: (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
bpb
parents: 18797
diff changeset
  1376
 * is the number of hexadecimal digits after the radix point.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
 * precision is not provided, then all of the digits as returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
 * Double#toHexString(double)} will be output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
 *
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
  1380
 * <p><a name="dnbdec"><b> BigDecimal </b></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
 * <p> The following conversions may be applied {@link java.math.BigDecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
 * BigDecimal}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
 * <table cellpadding=5 summary="floatConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1387
 * <tr><td valign="top"> {@code 'e'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
 *     <td> Requires the output to be formatted using <a
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
  1390
 *     name="bscientific">computerized scientific notation</a>.  The <a
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1391
 *     href="#L10nAlgorithm">localization algorithm</a> is applied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
 *     <p> If <i>m</i> is positive-zero or negative-zero, then the exponent
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1396
 *     will be {@code "+00"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
 *     <p> Otherwise, the result is a string that represents the sign and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
 *     magnitude (absolute value) of the argument.  The formatting of the sign
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1400
 *     is described in the <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
 *     value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
 *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
 *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
 *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
 *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
 *     integer part of <i>a</i>, as a single decimal digit, followed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
 *     decimal separator followed by decimal digits representing the fractional
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1410
 *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
 *     (<tt>'&#92;u0065'</tt>), followed by the sign of the exponent, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
 *     by a representation of <i>n</i> as a decimal integer, as produced by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
 *     method {@link Long#toString(long, int)}, and zero-padded to include at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
 *     least two digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
 *     <p> The number of digits in the result for the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1418
 *     specified then the default value is {@code 6}.  If the precision is
8799
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1419
 *     less than the number of digits to the right of the decimal point then
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1420
 *     the value will be rounded using the
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1421
 *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
 *     For a canonical representation of the value, use {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
 *     BigDecimal#toString()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1426
 *     <p> If the {@code ','} flag is given, then an {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1429
 * <tr><td valign="top"> {@code 'E'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
 *     <td valign="top"> <tt>'&#92;u0045'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1431
 *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1432
 *     will be {@code 'E'} (<tt>'&#92;u0045'</tt>).
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1433
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1434
 * <tr><td valign="top"> {@code 'g'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
 *     <td valign="top"> <tt>'&#92;u0067'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
 *     <td> Requires the output to be formatted in general scientific notation
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1437
 *     as described below. The <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
 *     algorithm</a> is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
 *     <p> After rounding for the precision, the formatting of the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
 *     magnitude <i>m</i> depends on its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
 *     <p> If <i>m</i> is greater than or equal to 10<sup>-4</sup> but less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
 *     than 10<sup>precision</sup> then it is represented in <i><a
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
  1445
 *     href="#bdecimal">decimal format</a></i>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
 *     <p> If <i>m</i> is less than 10<sup>-4</sup> or greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
 *     10<sup>precision</sup>, then it is represented in <i><a
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
  1449
 *     href="#bscientific">computerized scientific notation</a></i>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
 *     <p> The total number of significant digits in <i>m</i> is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
 *     precision.  If the precision is not specified, then the default value is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1453
 *     {@code 6}.  If the precision is {@code 0}, then it is taken to be
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1454
 *     {@code 1}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1455
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1456
 *     <p> If the {@code '#'} flag is given then an {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
 *     FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1459
 * <tr><td valign="top"> {@code 'G'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
 *     <td valign="top"> <tt>'&#92;u0047'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1461
 *     <td> The upper-case variant of {@code 'g'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1462
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1463
 * <tr><td valign="top"> {@code 'f'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
 *     <td valign="top"> <tt>'&#92;u0066'</tt>
9689
53a4e9b16900 7043234: (fmt) java.util.Formatter links in javadoc to BigDecimal need to be fixed
sherman
parents: 9266
diff changeset
  1465
 *     <td> Requires the output to be formatted using <a name="bdecimal">decimal
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1466
 *     format</a>.  The <a href="#L10nAlgorithm">localization algorithm</a> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
 *     applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
 *     <p> The result is a string that represents the sign and magnitude
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
 *     (absolute value) of the argument.  The formatting of the sign is
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1471
 *     described in the <a href="#L10nAlgorithm">localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
 *     value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
 *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
 *     leading zeroes, followed by the decimal separator followed by one or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
 *     more decimal digits representing the fractional part of <i>m</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
 *     <p> The number of digits in the result for the fractional part of
8799
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1480
 *     <i>m</i> or <i>a</i> is equal to the precision. If the precision is not
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1481
 *     specified then the default value is {@code 6}.  If the precision is
8799
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1482
 *     less than the number of digits to the right of the decimal point
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1483
 *     then the value will be rounded using the
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  1484
 *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
 *     For a canonical representation of the value, use {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
 *     BigDecimal#toString()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
 * Long apply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1494
 * <p> If the {@code '#'} flag is given, then the decimal separator will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
 * always be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
 * <p> The <a href="#floatdFlags">default behavior</a> when no flags are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
 * given is the same as for Float and Double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
 * <p> The specification of <a href="#floatDWidth">width</a> and <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
 * href="#floatDPrec">precision</a> is the same as defined for Float and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
 * Double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
 * <h4><a name="ddt">Date/Time</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1506
 * <p> This conversion may be applied to {@code long}, {@link Long}, {@link
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  1507
 * Calendar}, {@link Date} and {@link TemporalAccessor TemporalAccessor}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
 * <table cellpadding=5 summary="DTConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1511
 * <tr><td valign="top"> {@code 't'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
 *     <td valign="top"> <tt>'&#92;u0074'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
 *     <td> Prefix for date and time conversion characters.
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1514
 * <tr><td valign="top"> {@code 'T'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1516
 *     <td> The upper-case variant of {@code 't'}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
 * <p> The following date and time conversion character suffixes are defined
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1521
 * for the {@code 't'} and {@code 'T'} conversions.  The types are similar to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1522
 * but not completely identical to those defined by GNU {@code date} and
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1523
 * POSIX {@code strftime(3c)}.  Additional conversion types are provided to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1524
 * access Java-specific functionality (e.g. {@code 'L'} for milliseconds
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
 * within the second).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
 * <p> The following conversion characters are used for formatting times:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
 * <table cellpadding=5 summary="time">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1531
 * <tr><td valign="top"> {@code 'H'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
 *     <td valign="top"> <tt>'&#92;u0048'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
 *     <td> Hour of the day for the 24-hour clock, formatted as two digits with
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1534
 *     a leading zero as necessary i.e. {@code 00 - 23}. {@code 00}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
 *     corresponds to midnight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1537
 * <tr><td valign="top">{@code 'I'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
 *     <td valign="top"> <tt>'&#92;u0049'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
 *     <td> Hour for the 12-hour clock, formatted as two digits with a leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1540
 *     zero as necessary, i.e.  {@code 01 - 12}.  {@code 01} corresponds to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
 *     one o'clock (either morning or afternoon).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1543
 * <tr><td valign="top">{@code 'k'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
 *     <td valign="top"> <tt>'&#92;u006b'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1545
 *     <td> Hour of the day for the 24-hour clock, i.e. {@code 0 - 23}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1546
 *     {@code 0} corresponds to midnight.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1547
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1548
 * <tr><td valign="top">{@code 'l'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
 *     <td valign="top"> <tt>'&#92;u006c'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1550
 *     <td> Hour for the 12-hour clock, i.e. {@code 1 - 12}.  {@code 1}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
 *     corresponds to one o'clock (either morning or afternoon).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1553
 * <tr><td valign="top">{@code 'M'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
 *     <td valign="top"> <tt>'&#92;u004d'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
 *     <td> Minute within the hour formatted as two digits with a leading zero
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1556
 *     as necessary, i.e.  {@code 00 - 59}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1557
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1558
 * <tr><td valign="top">{@code 'S'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
 *     <td valign="top"> <tt>'&#92;u0053'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
 *     <td> Seconds within the minute, formatted as two digits with a leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1561
 *     zero as necessary, i.e. {@code 00 - 60} ("{@code 60}" is a special
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
 *     value required to support leap seconds).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1564
 * <tr><td valign="top">{@code 'L'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
 *     <td valign="top"> <tt>'&#92;u004c'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
 *     <td> Millisecond within the second formatted as three digits with
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1567
 *     leading zeros as necessary, i.e. {@code 000 - 999}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1568
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1569
 * <tr><td valign="top">{@code 'N'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
 *     <td valign="top"> <tt>'&#92;u004e'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
 *     <td> Nanosecond within the second, formatted as nine digits with leading
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1572
 *     zeros as necessary, i.e. {@code 000000000 - 999999999}.  The precision
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
 *     of this value is limited by the resolution of the underlying operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
 *     system or hardware.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1576
 * <tr><td valign="top">{@code 'p'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
 *     <td valign="top"> <tt>'&#92;u0070'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
 *     <td> Locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
 *     java.text.DateFormatSymbols#getAmPmStrings morning or afternoon} marker
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1580
 *     in lower case, e.g."{@code am}" or "{@code pm}".  Use of the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1581
 *     conversion prefix {@code 'T'} forces this output to upper case.  (Note
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1582
 *     that {@code 'p'} produces lower-case output.  This is different from
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1583
 *     GNU {@code date} and POSIX {@code strftime(3c)} which produce
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
 *     upper-case output.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1586
 * <tr><td valign="top">{@code 'z'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
 *     <td valign="top"> <tt>'&#92;u007a'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
 *     <td> <a href="http://www.ietf.org/rfc/rfc0822.txt">RFC&nbsp;822</a>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1589
 *     style numeric time zone offset from GMT, e.g. {@code -0800}.  This
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
 *     value will be adjusted as necessary for Daylight Saving Time.  For
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1591
 *     {@code long}, {@link Long}, and {@link Date} the time zone used is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1592
 *     the {@linkplain TimeZone#getDefault() default time zone} for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
 *     instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1595
 * <tr><td valign="top">{@code 'Z'}
7273
3367d89043cf 6615506: (fmt spec) Date/Time conversion table missing column for 'Z'
sherman
parents: 6489
diff changeset
  1596
 *     <td valign="top"> <tt>'&#92;u005a'</tt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
 *     <td> A string representing the abbreviation for the time zone.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
 *     value will be adjusted as necessary for Daylight Saving Time.  For
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1599
 *     {@code long}, {@link Long}, and {@link Date} the time zone used is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1600
 *     the {@linkplain TimeZone#getDefault() default time zone} for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
 *     instance of the Java virtual machine.  The Formatter's locale will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
 *     supersede the locale of the argument (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1604
 * <tr><td valign="top">{@code 's'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
 *     <td valign="top"> <tt>'&#92;u0073'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
 *     <td> Seconds since the beginning of the epoch starting at 1 January 1970
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1607
 *     {@code 00:00:00} UTC, i.e. {@code Long.MIN_VALUE/1000} to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1608
 *     {@code Long.MAX_VALUE/1000}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1609
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1610
 * <tr><td valign="top">{@code 'Q'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
 *     <td valign="top"> <tt>'&#92;u004f'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
 *     <td> Milliseconds since the beginning of the epoch starting at 1 January
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1613
 *     1970 {@code 00:00:00} UTC, i.e. {@code Long.MIN_VALUE} to
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1614
 *     {@code Long.MAX_VALUE}. The precision of this value is limited by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
 *     the resolution of the underlying operating system or hardware.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
 * <p> The following conversion characters are used for formatting dates:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
 * <table cellpadding=5 summary="date">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1623
 * <tr><td valign="top">{@code 'B'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
 *     <td valign="top"> <tt>'&#92;u0042'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
 *     <td> Locale-specific {@linkplain java.text.DateFormatSymbols#getMonths
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1626
 *     full month name}, e.g. {@code "January"}, {@code "February"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1627
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1628
 * <tr><td valign="top">{@code 'b'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
 *     <td valign="top"> <tt>'&#92;u0062'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
 *     <td> Locale-specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
 *     java.text.DateFormatSymbols#getShortMonths abbreviated month name},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1632
 *     e.g. {@code "Jan"}, {@code "Feb"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1633
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1634
 * <tr><td valign="top">{@code 'h'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
 *     <td valign="top"> <tt>'&#92;u0068'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1636
 *     <td> Same as {@code 'b'}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1637
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1638
 * <tr><td valign="top">{@code 'A'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
 *     <td valign="top"> <tt>'&#92;u0041'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
 *     <td> Locale-specific full name of the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
 *     java.text.DateFormatSymbols#getWeekdays day of the week},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1642
 *     e.g. {@code "Sunday"}, {@code "Monday"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1643
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1644
 * <tr><td valign="top">{@code 'a'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
 *     <td valign="top"> <tt>'&#92;u0061'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
 *     <td> Locale-specific short name of the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
 *     java.text.DateFormatSymbols#getShortWeekdays day of the week},
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1648
 *     e.g. {@code "Sun"}, {@code "Mon"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1649
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1650
 * <tr><td valign="top">{@code 'C'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
 *     <td valign="top"> <tt>'&#92;u0043'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1652
 *     <td> Four-digit year divided by {@code 100}, formatted as two digits
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1653
 *     with leading zero as necessary, i.e. {@code 00 - 99}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1654
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1655
 * <tr><td valign="top">{@code 'Y'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
 *     <td valign="top"> <tt>'&#92;u0059'</tt> <td> Year, formatted to at least
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1657
 *     four digits with leading zeros as necessary, e.g. {@code 0092} equals
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1658
 *     {@code 92} CE for the Gregorian calendar.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1659
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1660
 * <tr><td valign="top">{@code 'y'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
 *     <td valign="top"> <tt>'&#92;u0079'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
 *     <td> Last two digits of the year, formatted with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1663
 *     necessary, i.e. {@code 00 - 99}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1664
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1665
 * <tr><td valign="top">{@code 'j'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
 *     <td valign="top"> <tt>'&#92;u006a'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
 *     <td> Day of year, formatted as three digits with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1668
 *     necessary, e.g. {@code 001 - 366} for the Gregorian calendar.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1669
 *     {@code 001} corresponds to the first day of the year.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1670
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1671
 * <tr><td valign="top">{@code 'm'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
 *     <td valign="top"> <tt>'&#92;u006d'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
 *     <td> Month, formatted as two digits with leading zeros as necessary,
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1674
 *     i.e. {@code 01 - 13}, where "{@code 01}" is the first month of the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1675
 *     year and ("{@code 13}" is a special value required to support lunar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
 *     calendars).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1678
 * <tr><td valign="top">{@code 'd'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
 *     <td valign="top"> <tt>'&#92;u0064'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
 *     <td> Day of month, formatted as two digits with leading zeros as
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1681
 *     necessary, i.e. {@code 01 - 31}, where "{@code 01}" is the first day
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
 *     of the month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1684
 * <tr><td valign="top">{@code 'e'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1686
 *     <td> Day of month, formatted as two digits, i.e. {@code 1 - 31} where
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1687
 *     "{@code 1}" is the first day of the month.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
 * <p> The following conversion characters are used for formatting common
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
 * date/time compositions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
 * <table cellpadding=5 summary="composites">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1696
 * <tr><td valign="top">{@code 'R'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
 *     <td valign="top"> <tt>'&#92;u0052'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1698
 *     <td> Time formatted for the 24-hour clock as {@code "%tH:%tM"}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1699
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1700
 * <tr><td valign="top">{@code 'T'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1702
 *     <td> Time formatted for the 24-hour clock as {@code "%tH:%tM:%tS"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1703
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1704
 * <tr><td valign="top">{@code 'r'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
 *     <td valign="top"> <tt>'&#92;u0072'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1706
 *     <td> Time formatted for the 12-hour clock as {@code "%tI:%tM:%tS
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1707
 *     %Tp"}.  The location of the morning or afternoon marker
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1708
 *     ({@code '%Tp'}) may be locale-dependent.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1709
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1710
 * <tr><td valign="top">{@code 'D'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
 *     <td valign="top"> <tt>'&#92;u0044'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1712
 *     <td> Date formatted as {@code "%tm/%td/%ty"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1713
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1714
 * <tr><td valign="top">{@code 'F'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
 *     <td valign="top"> <tt>'&#92;u0046'</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
 *     <td> <a href="http://www.w3.org/TR/NOTE-datetime">ISO&nbsp;8601</a>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1717
 *     complete date formatted as {@code "%tY-%tm-%td"}.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1718
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1719
 * <tr><td valign="top">{@code 'c'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
 *     <td valign="top"> <tt>'&#92;u0063'</tt>
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1721
 *     <td> Date and time formatted as {@code "%ta %tb %td %tT %tZ %tY"},
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1722
 *     e.g. {@code "Sun Jul 20 16:17:00 EDT 1969"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1726
 * <p> The {@code '-'} flag defined for <a href="#dFlags">General
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1727
 * conversions</a> applies.  If the {@code '#'} flag is given, then a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
 * FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
 *
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1730
 * <p> The width is the minimum number of characters to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
 * be written to the output.  If the length of the converted value is less than
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1732
 * the {@code width} then the output will be padded by spaces
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
 * (<tt>'&#92;u0020'</tt>) until the total number of characters equals width.
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1734
 * The padding is on the left by default.  If the {@code '-'} flag is given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
 * then the padding will be on the right.  If width is not specified then there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
 * is no minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
 * <p> The precision is not applicable.  If the precision is specified then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
 * {@link IllegalFormatPrecisionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
 * <h4><a name="dper">Percent</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
 * <p> The conversion does not correspond to any argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
 * <table cellpadding=5 summary="DTConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1747
 * <tr><td valign="top">{@code '%'}
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1748
 *     <td> The result is a literal {@code '%'} (<tt>'&#92;u0025'</tt>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
 *
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  1750
 * <p> The width is the minimum number of characters to
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1751
 * be written to the output including the {@code '%'}.  If the length of the
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1752
 * converted value is less than the {@code width} then the output will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
 * padded by spaces (<tt>'&#92;u0020'</tt>) until the total number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
 * characters equals width.  The padding is on the left.  If width is not
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1755
 * specified then just the {@code '%'} is output.
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1756
 *
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1757
 * <p> The {@code '-'} flag defined for <a href="#dFlags">General
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
 * conversions</a> applies.  If any other flags are provided, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
 * {@link FormatFlagsConversionMismatchException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
 * <p> The precision is not applicable.  If the precision is specified an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
 * {@link IllegalFormatPrecisionException} will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
 * <h4><a name="dls">Line Separator</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
 * <p> The conversion does not correspond to any argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
 * <table cellpadding=5 summary="DTConv">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1772
 * <tr><td valign="top">{@code 'n'}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
 *     <td> the platform-specific line separator as returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
 *     System#getProperty System.getProperty("line.separator")}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
 * <p> Flags, width, and precision are not applicable.  If any are provided an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
 * {@link IllegalFormatFlagsException}, {@link IllegalFormatWidthException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
 * and {@link IllegalFormatPrecisionException}, respectively will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
 * <h4><a name="dpos">Argument Index</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
 * <p> Format specifiers can reference arguments in three ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
 * <li> <i>Explicit indexing</i> is used when the format specifier contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
 * argument index.  The argument index is a decimal integer indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
 * position of the argument in the argument list.  The first argument is
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1791
 * referenced by "{@code 1$}", the second by "{@code 2$}", etc.  An argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
 * may be referenced more than once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
 * <p> For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
 *   formatter.format("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
 *                    "a", "b", "c", "d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
 *   // -&gt; "d c b a d c b a"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
 * <li> <i>Relative indexing</i> is used when the format specifier contains a
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1803
 * {@code '<'} (<tt>'&#92;u003c'</tt>) flag which causes the argument for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
 * the previous format specifier to be re-used.  If there is no previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
 * argument, then a {@link MissingFormatArgumentException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
 *    formatter.format("%s %s %&lt;s %&lt;s", "a", "b", "c", "d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
 *    // -&gt; "a b b b"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
 *    // "c" and "d" are ignored because they are not referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
 * <li> <i>Ordinary indexing</i> is used when the format specifier contains
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1814
 * neither an argument index nor a {@code '<'} flag.  Each format specifier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
 * which uses ordinary indexing is assigned a sequential implicit index into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
 * argument list which is independent of the indices used by explicit or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
 * relative indexing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
 *   formatter.format("%s %s %s %s", "a", "b", "c", "d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
 *   // -&gt; "a b c d"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
 * <p> It is possible to have a format string which uses all forms of indexing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
 * for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
 *   formatter.format("%2$s %s %&lt;s %s", "a", "b", "c", "d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
 *   // -&gt; "b a a b"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
 *   // "c" and "d" are ignored because they are not referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
 * <p> The maximum number of arguments is limited by the maximum dimension of a
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8799
diff changeset
  1836
 * Java array as defined by
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8799
diff changeset
  1837
 * <cite>The Java&trade; Virtual Machine Specification</cite>.
28518
9a6247bbed98 8042262: Javadoc typo in java.util.Formatter
sherman
parents: 28302
diff changeset
  1838
 * If the argument index does not correspond to an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
 * available argument, then a {@link MissingFormatArgumentException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
 * <p> If there are more arguments than format specifiers, the extra arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
 * are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
 *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1844
 * <p> Unless otherwise specified, passing a {@code null} argument to any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
 * method or constructor in this class will cause a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
 * NullPointerException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
 * @author  Iris Clark
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
public final class Formatter implements Closeable, Flushable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    private Appendable a;
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1853
    private final Locale l;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    private IOException lastException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1857
    private final char zero;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    private static double scaleUp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    // 1 (sign) + 19 (max # sig digits) + 1 ('.') + 1 ('e') + 1 (sign)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    // + 3 (max # exp digits) + 4 (error) = 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
    private static final int MAX_FD_CHARS = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1864
    /**
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1865
     * Returns a charset object for the given charset name.
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1866
     * @throws NullPointerException          is csn is null
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1867
     * @throws UnsupportedEncodingException  if the charset is not supported
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1868
     */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1869
    private static Charset toCharset(String csn)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1870
        throws UnsupportedEncodingException
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1871
    {
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7966
diff changeset
  1872
        Objects.requireNonNull(csn, "charsetName");
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1873
        try {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1874
            return Charset.forName(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1875
        } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1876
            // UnsupportedEncodingException should be thrown
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1877
            throw new UnsupportedEncodingException(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1878
        }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1879
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1880
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1881
    private static final Appendable nonNullAppendable(Appendable a) {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1882
        if (a == null)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1883
            return new StringBuilder();
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1884
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1885
        return a;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1886
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1887
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1888
    /* Private constructors */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1889
    private Formatter(Locale l, Appendable a) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        this.a = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        this.l = l;
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1892
        this.zero = getZero(l);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1893
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1894
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1895
    private Formatter(Charset charset, Locale l, File file)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1896
        throws FileNotFoundException
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1897
    {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1898
        this(l,
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1899
             new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * Constructs a new formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * <p> The destination of the formatted output is a {@link StringBuilder}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * which may be retrieved by invoking {@link #out out()} and whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * current content may be converted into a string by invoking {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * #toString toString()}.  The locale used is the {@linkplain
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1909
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1910
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
    public Formatter() {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1914
        this(Locale.getDefault(Locale.Category.FORMAT), new StringBuilder());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * Constructs a new formatter with the specified destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1920
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1921
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1922
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1923
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * @param  a
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1926
     *         Destination for the formatted output.  If {@code a} is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1927
     *         {@code null} then a {@link StringBuilder} will be created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
    public Formatter(Appendable a) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1930
        this(Locale.getDefault(Locale.Category.FORMAT), nonNullAppendable(a));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * Constructs a new formatter with the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * <p> The destination of the formatted output is a {@link StringBuilder}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * which may be retrieved by invoking {@link #out out()} and whose current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * content may be converted into a string by invoking {@link #toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * toString()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1943
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    public Formatter(Locale l) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1947
        this(l, new StringBuilder());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * Constructs a new formatter with the specified destination and locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @param  a
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1954
     *         Destination for the formatted output.  If {@code a} is
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1955
     *         {@code null} then a {@link StringBuilder} will be created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  1959
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    public Formatter(Appendable a, Locale l) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1963
        this(l, nonNullAppendable(a));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * Constructs a new formatter with the specified file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * <p> The charset used is the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1973
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1974
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1975
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1976
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     *         The name of the file to use as the destination of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     *         formatter.  If the file exists then it will be truncated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     *         zero size; otherwise, a new file will be created.  The output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     *         will be written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     *          If the given file name does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
    public Formatter(String fileName) throws FileNotFoundException {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1996
        this(Locale.getDefault(Locale.Category.FORMAT),
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  1997
             new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * Constructs a new formatter with the specified file name and charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2003
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2004
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2005
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2006
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     *         The name of the file to use as the destination of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     *         formatter.  If the file exists then it will be truncated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     *         zero size; otherwise, a new file will be created.  The output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     *         will be written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     *          If the given file name does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    public Formatter(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
  2035
        this(fileName, csn, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * Constructs a new formatter with the specified file name, charset, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     *         The name of the file to use as the destination of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     *         formatter.  If the file exists then it will be truncated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     *         zero size; otherwise, a new file will be created.  The output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     *         will be written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2054
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     *          If the given file name does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    public Formatter(String fileName, String csn, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2074
        this(toCharset(csn), l, new File(fileName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * Constructs a new formatter with the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * <p> The charset used is the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2084
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2085
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2086
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2087
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     *         The file to use as the destination of this formatter.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     *         file exists then it will be truncated to zero size; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     *         a new file will be created.  The output will be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     *         file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     *          write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    public Formatter(File file) throws FileNotFoundException {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2107
        this(Locale.getDefault(Locale.Category.FORMAT),
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2108
             new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * Constructs a new formatter with the specified file and charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2114
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2115
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2116
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2117
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     *         The file to use as the destination of this formatter.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     *         file exists then it will be truncated to zero size; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     *         a new file will be created.  The output will be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     *         file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     *          write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    public Formatter(File file, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
  2146
        this(file, csn, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * Constructs a new formatter with the specified file, charset, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     *         The file to use as the destination of this formatter.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     *         file exists then it will be truncated to zero size; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     *         a new file will be created.  The output will be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     *         file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2165
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     *          write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    public Formatter(File file, String csn, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2185
        this(toCharset(csn), l, file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * Constructs a new formatter with the specified print stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2191
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2192
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2193
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2194
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * <p> Characters are written to the given {@link java.io.PrintStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * PrintStream} object and are therefore encoded using that object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * @param  ps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     *         The stream to use as the destination of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
    public Formatter(PrintStream ps) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2204
        this(Locale.getDefault(Locale.Category.FORMAT),
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7966
diff changeset
  2205
             (Appendable)Objects.requireNonNull(ps));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * Constructs a new formatter with the specified output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * <p> The charset used is the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2215
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2216
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2217
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2218
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @param  os
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     *         The output stream to use as the destination of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     *         The output will be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    public Formatter(OutputStream os) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2225
        this(Locale.getDefault(Locale.Category.FORMAT),
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2226
             new BufferedWriter(new OutputStreamWriter(os)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     * Constructs a new formatter with the specified output stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2233
     * <p> The locale used is the {@linkplain
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2234
     * Locale#getDefault(Locale.Category) default locale} for
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2235
     * {@linkplain Locale.Category#FORMAT formatting} for this instance of the Java
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  2236
     * virtual machine.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * @param  os
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     *         The output stream to use as the destination of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     *         The output will be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
    public Formatter(OutputStream os, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
  2252
        this(os, csn, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * Constructs a new formatter with the specified output stream, charset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * and locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * @param  os
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     *         The output stream to use as the destination of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     *         The output will be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2269
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    public Formatter(OutputStream os, String csn, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
        throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2278
        this(l, new BufferedWriter(new OutputStreamWriter(os, csn)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2281
    private static char getZero(Locale l) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        if ((l != null) && !l.equals(Locale.US)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
            DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2284
            return dfs.getZeroDigit();
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2285
        } else {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 7816
diff changeset
  2286
            return '0';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * Returns the locale set by the construction of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     * <p> The {@link #format(java.util.Locale,String,Object...) format} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
     * for this object which has a locale argument does not change this value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2296
     * @return  {@code null} if no localization is applied, otherwise a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     *          locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    public Locale locale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        return l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     * Returns the destination for the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     * @return  The destination for the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    public Appendable out() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
    /**
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2323
     * Returns the result of invoking {@code toString()} on the destination
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * for the output.  For example, the following code formats text into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * {@link StringBuilder} then retrieves the resultant string:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     *   Formatter f = new Formatter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     *   f.format("Last reboot at %tc", lastRebootDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
     *   String s = f.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
     *   // -&gt; s == "Last reboot at Sat Jan 01 00:00:00 PST 2000"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
     * <p> An invocation of this method behaves in exactly the same way as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     *     out().toString() </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2340
     * <p> Depending on the specification of {@code toString} for the {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * Appendable}, the returned string may or may not contain the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     * written to the destination.  For instance, buffers typically return
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2343
     * their contents in {@code toString()}, but streams cannot since the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     * data is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2346
     * @return  The result of invoking {@code toString()} on the destination
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     *          for the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        return a.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     * Flushes this formatter.  If the destination implements the {@link
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2360
     * java.io.Flushable} interface, its {@code flush} method will be invoked.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
     * <p> Flushing a formatter writes any buffered output in the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
     * to the underlying stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        if (a instanceof Flushable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                ((Flushable)a).flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                lastException = ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * Closes this formatter.  If the destination implements the {@link
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2382
     * java.io.Closeable} interface, its {@code close} method will be invoked.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * <p> Closing a formatter allows it to release resources it may be holding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * (such as open files).  If the formatter is already closed, then invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     * <p> Attempting to invoke any methods except {@link #ioException()} in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * this formatter after it has been closed will result in a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     * FormatterClosedException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
    public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        if (a == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
            if (a instanceof Closeable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                ((Closeable)a).close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            lastException = ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            a = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    private void ensureOpen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        if (a == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
            throw new FormatterClosedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    /**
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2411
     * Returns the {@code IOException} last thrown by this formatter's {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * Appendable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2414
     * <p> If the destination's {@code append()} method never throws
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2415
     * {@code IOException}, then this method will always return {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     *
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2417
     * @return  The last exception thrown by the Appendable or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     *          no such exception exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
    public IOException ioException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        return lastException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * Writes a formatted string to this object's destination using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * specified format string and arguments.  The locale used is the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     * defined during the construction of this formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
     *         A format string as described in <a href="#syntax">Format string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
     *         syntax</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
     *         extra arguments are ignored.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8799
diff changeset
  2438
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     * @throws  IllegalFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     *          formatting errors, see the <a href="#detail">Details</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     *          section of the formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
     * @return  This formatter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    public Formatter format(String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        return format(l, format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
     * Writes a formatted string to this object's destination using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     * specified locale, format string, and arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     *         The {@linkplain java.util.Locale locale} to apply during
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  2464
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     *         is applied.  This does not change this object's locale that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     *         set during construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     *         A format string as described in <a href="#syntax">Format string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     *         syntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
     *         extra arguments are ignored.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8799
diff changeset
  2477
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * @throws  IllegalFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     *          formatting errors, see the <a href="#detail">Details</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     *          section of the formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * @throws  FormatterClosedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     *          If this formatter has been closed by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     *          #close()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * @return  This formatter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
    public Formatter format(Locale l, String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        // index of last argument referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        int last = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        // last ordinary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        int lasto = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2501
        List<FormatString> fsa = parse(format);
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 21368
diff changeset
  2502
        for (FormatString fs : fsa) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            int index = fs.index();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                switch (index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                case -2:  // fixed string, "%n", or "%%"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                    fs.print(null, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                case -1:  // relative index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                    if (last < 0 || (args != null && last > args.length - 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                        throw new MissingFormatArgumentException(fs.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                    fs.print((args == null ? null : args[last]), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                case 0:  // ordinary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                    lasto++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                    last = lasto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                    if (args != null && lasto > args.length - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                        throw new MissingFormatArgumentException(fs.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                    fs.print((args == null ? null : args[lasto]), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                default:  // explicit index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
                    last = index - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
                    if (args != null && last > args.length - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
                        throw new MissingFormatArgumentException(fs.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
                    fs.print((args == null ? null : args[last]), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                lastException = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
    // %[argument_index$][flags][width][.precision][t]conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    private static final String formatSpecifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        = "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    private static Pattern fsPattern = Pattern.compile(formatSpecifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2541
    /**
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2542
     * Finds format specifiers in the format string.
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2543
     */
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2544
    private List<FormatString> parse(String s) {
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 7273
diff changeset
  2545
        ArrayList<FormatString> al = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        Matcher m = fsPattern.matcher(s);
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2547
        for (int i = 0, len = s.length(); i < len; ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            if (m.find(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
                // Anything between the start of the string and the beginning
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
                // of the format specifier is either fixed text or contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
                // an invalid format string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
                if (m.start() != i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
                    // Make sure we didn't miss any invalid format specifiers
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2554
                    checkText(s, i, m.start());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
                    // Assume previous characters were fixed text
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2556
                    al.add(new FixedString(s, i, m.start()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2559
                al.add(new FormatSpecifier(s, m));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
                i = m.end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
                // No more valid format specifiers.  Check for possible invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
                // format specifiers.
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2564
                checkText(s, i, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
                // The rest of the string is fixed text
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2566
                al.add(new FixedString(s, i, s.length()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        }
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2570
        return al;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2573
    private static void checkText(String s, int start, int end) {
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2574
        for (int i = start; i < end; i++) {
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2575
            // Any '%' found in the region starts an invalid format specifier.
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2576
            if (s.charAt(i) == '%') {
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2577
                char c = (i == end - 1) ? '%' : s.charAt(i + 1);
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2578
                throw new UnknownFormatConversionException(String.valueOf(c));
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2579
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
    private interface FormatString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        int index();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        void print(Object arg, Locale l) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
    private class FixedString implements FormatString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        private String s;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2591
        private int start;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2592
        private int end;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2593
        FixedString(String s, int start, int end) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2594
            this.s = s;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2595
            this.start = start;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2596
            this.end = end;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2597
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        public int index() { return -2; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
        public void print(Object arg, Locale l)
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2600
            throws IOException { a.append(s, start, end); }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2601
        public String toString() { return s.substring(start, end); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
18774
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2604
    /**
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2605
     * Enum for {@code BigDecimal} formatting.
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2606
     */
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2607
    public enum BigDecimalLayoutForm {
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2608
        /**
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2609
         * Format the {@code BigDecimal} in computerized scientific notation.
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2610
         */
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2611
        SCIENTIFIC,
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2612
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2613
        /**
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2614
         * Format the {@code BigDecimal} as a decimal number.
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2615
         */
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2616
        DECIMAL_FLOAT
e951a7044fed 8019857: Fix doclint errors in java.util.Format*
bpb
parents: 18545
diff changeset
  2617
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    private class FormatSpecifier implements FormatString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
        private int index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
        private Flags f = Flags.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
        private int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
        private int precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        private boolean dt = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        private char c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2627
        private int index(String s, int start, int end) {
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2628
            if (start >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
                try {
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2630
                    // skip the trailing '$'
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2631
                    index = Integer.parseInt(s, start, end - 1, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
                } catch (NumberFormatException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
                    assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
                index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
        public int index() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2645
        private Flags flags(String s, int start, int end) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2646
            f = Flags.parse(s, start, end);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
            if (f.contains(Flags.PREVIOUS))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
                index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
            return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2652
        private int width(String s, int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
            width = -1;
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2654
            if (start >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
                try {
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2656
                    width = Integer.parseInt(s, start, end, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
                    if (width < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
                        throw new IllegalFormatWidthException(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
                } catch (NumberFormatException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
                    assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2666
        private int precision(String s, int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            precision = -1;
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2668
            if (start >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                try {
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2670
                    // skip the leading '.'
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2671
                    precision = Integer.parseInt(s, start + 1, end, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                    if (precision < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                        throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                } catch (NumberFormatException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                    assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            return precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2681
        private char conversion(char conv) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2682
            c = conv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
            if (!dt) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2684
                if (!Conversion.isValid(c)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
                    throw new UnknownFormatConversionException(String.valueOf(c));
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2686
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2687
                if (Character.isUpperCase(c)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
                    f.add(Flags.UPPERCASE);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2689
                    c = Character.toLowerCase(c);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2690
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2691
                if (Conversion.isText(c)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
                    index = -2;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2693
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2698
        FormatSpecifier(String s, Matcher m) {
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2699
            index(s, m.start(1), m.end(1));
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2700
            flags(s, m.start(2), m.end(2));
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2701
            width(s, m.start(3), m.end(3));
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2702
            precision(s, m.start(4), m.end(4));
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2703
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2704
            int tTStart = m.start(5);
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2705
            if (tTStart >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                dt = true;
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2707
                if (s.charAt(tTStart) == 'T') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
                    f.add(Flags.UPPERCASE);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2709
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            }
27731
3cba975130c0 8065070: (fmt) Avoid creating substrings when building FormatSpecifier
redestad
parents: 26733
diff changeset
  2711
            conversion(s.charAt(m.start(6)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            if (dt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
                checkDateTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            else if (Conversion.isGeneral(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                checkGeneral();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            else if (Conversion.isCharacter(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                checkCharacter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            else if (Conversion.isInteger(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
                checkInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
            else if (Conversion.isFloat(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                checkFloat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
            else if (Conversion.isText(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                checkText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
                throw new UnknownFormatConversionException(String.valueOf(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
        public void print(Object arg, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
            if (dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
                printDateTime(arg, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
            switch(c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
            case Conversion.DECIMAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
            case Conversion.OCTAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
            case Conversion.HEXADECIMAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
                printInteger(arg, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            case Conversion.SCIENTIFIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            case Conversion.GENERAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
            case Conversion.DECIMAL_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
            case Conversion.HEXADECIMAL_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                printFloat(arg, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
            case Conversion.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            case Conversion.CHARACTER_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                printCharacter(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
            case Conversion.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
                printBoolean(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            case Conversion.STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
                printString(arg, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            case Conversion.HASHCODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
                printHashCode(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            case Conversion.LINE_SEPARATOR:
4355
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 4185
diff changeset
  2760
                a.append(System.lineSeparator());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
            case Conversion.PERCENT_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                a.append('%');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        private void printInteger(Object arg, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            if (arg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
                print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            else if (arg instanceof Byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                print(((Byte)arg).byteValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
            else if (arg instanceof Short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
                print(((Short)arg).shortValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            else if (arg instanceof Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
                print(((Integer)arg).intValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            else if (arg instanceof Long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                print(((Long)arg).longValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            else if (arg instanceof BigInteger)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
                print(((BigInteger)arg), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                failConversion(c, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
        private void printFloat(Object arg, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            if (arg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            else if (arg instanceof Float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                print(((Float)arg).floatValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            else if (arg instanceof Double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                print(((Double)arg).doubleValue(), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            else if (arg instanceof BigDecimal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                print(((BigDecimal)arg), l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                failConversion(c, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
        private void printDateTime(Object arg, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            if (arg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
                print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            Calendar cal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            // Instead of Calendar.setLenient(true), perhaps we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            // wrap the IllegalArgumentException that might be thrown?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            if (arg instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                // Note that the following method uses an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                // default time zone (TimeZone.getDefaultRef().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
                cal = Calendar.getInstance(l == null ? Locale.US : l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                cal.setTimeInMillis((Long)arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            } else if (arg instanceof Date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
                // Note that the following method uses an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                // default time zone (TimeZone.getDefaultRef().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                cal = Calendar.getInstance(l == null ? Locale.US : l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                cal.setTime((Date)arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
            } else if (arg instanceof Calendar) {
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  2820
                cal = (Calendar) ((Calendar) arg).clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                cal.setLenient(true);
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  2822
            } else if (arg instanceof TemporalAccessor) {
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  2823
                print((TemporalAccessor) arg, c, l);
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  2824
                return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                failConversion(c, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            // Use the provided locale so that invocations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
            // localizedMagnitude() use optimizations for null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            print(cal, c, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
        private void printCharacter(Object arg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            if (arg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
                print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            String s = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            if (arg instanceof Character) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                s = ((Character)arg).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            } else if (arg instanceof Byte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                byte i = ((Byte)arg).byteValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                if (Character.isValidCodePoint(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                    s = new String(Character.toChars(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
                    throw new IllegalFormatCodePointException(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            } else if (arg instanceof Short) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
                short i = ((Short)arg).shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                if (Character.isValidCodePoint(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                    s = new String(Character.toChars(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
                    throw new IllegalFormatCodePointException(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            } else if (arg instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                int i = ((Integer)arg).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
                if (Character.isValidCodePoint(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
                    s = new String(Character.toChars(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
                    throw new IllegalFormatCodePointException(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
                failConversion(c, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
            print(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
        private void printString(Object arg, Locale l) throws IOException {
3416
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2866
            if (arg instanceof Formattable) {
4185
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2867
                Formatter fmt = Formatter.this;
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2868
                if (fmt.locale() != l)
8d87b7274c30 6898220: Optimize Formatter.parse (including String.printf)
martin
parents: 3416
diff changeset
  2869
                    fmt = new Formatter(fmt.out(), l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
                ((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
            } else {
3416
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2872
                if (f.contains(Flags.ALTERNATE))
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2873
                    failMismatch(Flags.ALTERNATE, 's');
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2874
                if (arg == null)
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2875
                    print("null");
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2876
                else
0dd4f82becda 5063507: (fmt) missing exception for "%#s" format specifier
sherman
parents: 1939
diff changeset
  2877
                    print(arg.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        private void printBoolean(Object arg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
            String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
            if (arg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                s = ((arg instanceof Boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                     ? ((Boolean)arg).toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                     : Boolean.toString(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                s = Boolean.toString(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
            print(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
        private void printHashCode(Object arg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            String s = (arg == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
                        ? "null"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
                        : Integer.toHexString(arg.hashCode()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
            print(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
        private void print(String s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
            if (precision != -1 && precision < s.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                s = s.substring(0, precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
            if (f.contains(Flags.UPPERCASE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                s = s.toUpperCase();
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2904
            appendJustified(a, s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2907
        private Appendable appendJustified(Appendable a, CharSequence cs) throws IOException {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2908
             if (width == -1) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2909
                 return a.append(cs);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2910
             }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2911
             boolean padRight = f.contains(Flags.LEFT_JUSTIFY);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2912
             int sp = width - cs.length();
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2913
             if (padRight) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2914
                 a.append(cs);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2915
             }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2916
             for (int i = 0; i < sp; i++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2917
                 a.append(' ');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2918
             }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2919
             if (!padRight) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2920
                 a.append(cs);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2921
             }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  2922
             return a;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
        public String toString() {
11135
fb2447d0a09c 5063455: (fmt) MissingFormatArgumentException.getFormatSpecifier() incorrect return value
sherman
parents: 10608
diff changeset
  2926
            StringBuilder sb = new StringBuilder("%");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            // Flags.UPPERCASE is set internally for legal conversions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
            Flags dupf = f.dup().remove(Flags.UPPERCASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
            sb.append(dupf.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            if (index > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
                sb.append(index).append('$');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
            if (width != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                sb.append(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            if (precision != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
                sb.append('.').append(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            if (dt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
                sb.append(f.contains(Flags.UPPERCASE) ? 'T' : 't');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            sb.append(f.contains(Flags.UPPERCASE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                      ? Character.toUpperCase(c) : c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
        private void checkGeneral() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
            if ((c == Conversion.BOOLEAN || c == Conversion.HASHCODE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
                && f.contains(Flags.ALTERNATE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
                failMismatch(Flags.ALTERNATE, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
            // '-' requires a width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
                throw new MissingFormatWidthException(toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
            checkBadFlags(Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
                          Flags.GROUP, Flags.PARENTHESES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
        private void checkDateTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            if (precision != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
                throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            if (!DateTime.isValid(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
                throw new UnknownFormatConversionException("t" + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
                          Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
            // '-' requires a width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
                throw new MissingFormatWidthException(toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
        private void checkCharacter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            if (precision != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
                throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                          Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            // '-' requires a width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
            if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                throw new MissingFormatWidthException(toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
        private void checkInteger() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            checkNumeric();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            if (precision != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
                throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            if (c == Conversion.DECIMAL_INTEGER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
                checkBadFlags(Flags.ALTERNATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            else if (c == Conversion.OCTAL_INTEGER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
                checkBadFlags(Flags.GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                checkBadFlags(Flags.GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
        private void checkBadFlags(Flags ... badFlags) {
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 21368
diff changeset
  2990
            for (Flags badFlag : badFlags)
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 21368
diff changeset
  2991
                if (f.contains(badFlag))
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 21368
diff changeset
  2992
                    failMismatch(badFlag, c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
        private void checkFloat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
            checkNumeric();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
            if (c == Conversion.DECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
            } else if (c == Conversion.HEXADECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                checkBadFlags(Flags.PARENTHESES, Flags.GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
            } else if (c == Conversion.SCIENTIFIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                checkBadFlags(Flags.GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
            } else if (c == Conversion.GENERAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                checkBadFlags(Flags.ALTERNATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
        private void checkNumeric() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            if (width != -1 && width < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
                throw new IllegalFormatWidthException(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
            if (precision != -1 && precision < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
            // '-' and '0' require a width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
            if (width == -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
                && (f.contains(Flags.LEFT_JUSTIFY) || f.contains(Flags.ZERO_PAD)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
                throw new MissingFormatWidthException(toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
            // bad combination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                || (f.contains(Flags.LEFT_JUSTIFY) && f.contains(Flags.ZERO_PAD)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                throw new IllegalFormatFlagsException(f.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
        private void checkText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
            if (precision != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
                throw new IllegalFormatPrecisionException(precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
            case Conversion.PERCENT_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
                if (f.valueOf() != Flags.LEFT_JUSTIFY.valueOf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
                    && f.valueOf() != Flags.NONE.valueOf())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
                    throw new IllegalFormatFlagsException(f.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
                // '-' requires a width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
                if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
                    throw new MissingFormatWidthException(toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            case Conversion.LINE_SEPARATOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
                if (width != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
                    throw new IllegalFormatWidthException(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
                if (f.valueOf() != Flags.NONE.valueOf())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
                    throw new IllegalFormatFlagsException(f.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
        private void print(byte value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            long v = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
            if (value < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
                && (c == Conversion.OCTAL_INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
                    || c == Conversion.HEXADECIMAL_INTEGER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                v += (1L << 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
                assert v >= 0 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
            print(v, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
        private void print(short value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
            long v = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
            if (value < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
                && (c == Conversion.OCTAL_INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
                    || c == Conversion.HEXADECIMAL_INTEGER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
                v += (1L << 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
                assert v >= 0 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            print(v, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
        private void print(int value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
            long v = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
            if (value < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
                && (c == Conversion.OCTAL_INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
                    || c == Conversion.HEXADECIMAL_INTEGER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                v += (1L << 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
                assert v >= 0 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
            print(v, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
        private void print(long value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
            if (c == Conversion.DECIMAL_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
                boolean neg = value < 0;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3087
                String valueStr = Long.toString(value, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
                // leading sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
                leadingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
                // the value
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3093
                localizedMagnitude(sb, valueStr, neg ? 1 : 0, f, adjustWidth(width, f, neg), l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
                // trailing sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
                trailingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            } else if (c == Conversion.OCTAL_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
                checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
                              Flags.PLUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
                String s = Long.toOctalString(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
                int len = (f.contains(Flags.ALTERNATE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
                           ? s.length() + 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
                           : s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
                // apply ALTERNATE (radix indicator for octal) before ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
                if (f.contains(Flags.ALTERNATE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                    sb.append('0');
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3108
                if (f.contains(Flags.ZERO_PAD)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3109
                    trailingZeros(sb, width - len);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3110
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
                sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
            } else if (c == Conversion.HEXADECIMAL_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
                checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
                              Flags.PLUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
                String s = Long.toHexString(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
                int len = (f.contains(Flags.ALTERNATE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
                           ? s.length() + 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
                           : s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
                // apply ALTERNATE (radix indicator for hex) before ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
                if (f.contains(Flags.ALTERNATE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
                    sb.append(f.contains(Flags.UPPERCASE) ? "0X" : "0x");
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3123
                if (f.contains(Flags.ZERO_PAD)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3124
                    trailingZeros(sb, width - len);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3125
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
                if (f.contains(Flags.UPPERCASE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
                    s = s.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
                sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3132
            appendJustified(a, sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
        // neg := val < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
        private StringBuilder leadingSign(StringBuilder sb, boolean neg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
            if (!neg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
                if (f.contains(Flags.PLUS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                    sb.append('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
                } else if (f.contains(Flags.LEADING_SPACE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                    sb.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
                if (f.contains(Flags.PARENTHESES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
                    sb.append('(');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
                    sb.append('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            return sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
        // neg := val < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        private StringBuilder trailingSign(StringBuilder sb, boolean neg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            if (neg && f.contains(Flags.PARENTHESES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
                sb.append(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
            return sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
        private void print(BigInteger value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            boolean neg = value.signum() == -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            BigInteger v = value.abs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            // leading sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
            leadingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
            // the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            if (c == Conversion.DECIMAL_INTEGER) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3169
                localizedMagnitude(sb, v.toString(), 0, f, adjustWidth(width, f, neg), l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
            } else if (c == Conversion.OCTAL_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
                String s = v.toString(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
                int len = s.length() + sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
                if (neg && f.contains(Flags.PARENTHESES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
                    len++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
                // apply ALTERNATE (radix indicator for octal) before ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
                if (f.contains(Flags.ALTERNATE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
                    len++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
                    sb.append('0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
                if (f.contains(Flags.ZERO_PAD)) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3183
                    trailingZeros(sb, width - len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
                sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            } else if (c == Conversion.HEXADECIMAL_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
                String s = v.toString(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
                int len = s.length() + sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                if (neg && f.contains(Flags.PARENTHESES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
                    len++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                // apply ALTERNATE (radix indicator for hex) before ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                if (f.contains(Flags.ALTERNATE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                    len += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
                    sb.append(f.contains(Flags.UPPERCASE) ? "0X" : "0x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                }
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3198
                if (f.contains(Flags.ZERO_PAD)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3199
                    trailingZeros(sb, width - len);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3200
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
                if (f.contains(Flags.UPPERCASE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
                    s = s.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
                sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            // trailing sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
            trailingSign(sb, (value.signum() == -1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3210
            appendJustified(a, sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
        private void print(float value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
            print((double) value, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        private void print(double value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
            boolean neg = Double.compare(value, 0.0) == -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
            if (!Double.isNaN(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                double v = Math.abs(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
                // leading sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
                leadingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                // the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                if (!Double.isInfinite(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                    print(sb, v, l, f, c, precision, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
                    sb.append(f.contains(Flags.UPPERCASE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
                              ? "INFINITY" : "Infinity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                // trailing sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
                trailingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                sb.append(f.contains(Flags.UPPERCASE) ? "NAN" : "NaN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3241
            appendJustified(a, sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
        // !Double.isInfinite(value) && !Double.isNaN(value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
        private void print(StringBuilder sb, double value, Locale l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
                           Flags f, char c, int precision, boolean neg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
            if (c == Conversion.SCIENTIFIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                // Create a new FormattedFloatingDecimal with the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
                // precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
                int prec = (precision == -1 ? 6 : precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
                FormattedFloatingDecimal fd
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3255
                        = FormattedFloatingDecimal.valueOf(value, prec,
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3256
                          FormattedFloatingDecimal.Form.SCIENTIFIC);
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3257
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3258
                StringBuilder mant = new StringBuilder().append(fd.getMantissa());
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3259
                addZeros(mant, prec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                // If the precision is zero and the '#' flag is set, add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                // requested decimal point.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3263
                if (f.contains(Flags.ALTERNATE) && (prec == 0)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3264
                    mant.append('.');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3265
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                char[] exp = (value == 0.0)
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3268
                    ? new char[] {'+','0','0'} : fd.getExponent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                int newW = width;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3271
                if (width != -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                    newW = adjustWidth(width - exp.length - 1, f, neg);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3273
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3274
                localizedMagnitude(sb, mant, 0, f, newW, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
                char sign = exp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
                assert(sign == '+' || sign == '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
                sb.append(sign);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3282
                localizedMagnitudeExp(sb, exp, 1, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            } else if (c == Conversion.DECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                // Create a new FormattedFloatingDecimal with the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                // precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                int prec = (precision == -1 ? 6 : precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                FormattedFloatingDecimal fd
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3289
                        = FormattedFloatingDecimal.valueOf(value, prec,
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3290
                          FormattedFloatingDecimal.Form.DECIMAL_FLOAT);
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3291
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3292
                StringBuilder mant = new StringBuilder().append(fd.getMantissa());
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3293
                addZeros(mant, prec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                // If the precision is zero and the '#' flag is set, add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                // requested decimal point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                if (f.contains(Flags.ALTERNATE) && (prec == 0))
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3298
                    mant.append('.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
                int newW = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                if (width != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
                    newW = adjustWidth(width, f, neg);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3303
                localizedMagnitude(sb, mant, 0, f, newW, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
            } else if (c == Conversion.GENERAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                int prec = precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
                if (precision == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                    prec = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
                else if (precision == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
                    prec = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3311
                char[] exp;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3312
                StringBuilder mant = new StringBuilder();
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3313
                int expRounded;
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3314
                if (value == 0.0) {
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3315
                    exp = null;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3316
                    mant.append('0');
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3317
                    expRounded = 0;
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3318
                } else {
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3319
                    FormattedFloatingDecimal fd
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3320
                        = FormattedFloatingDecimal.valueOf(value, prec,
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 16852
diff changeset
  3321
                          FormattedFloatingDecimal.Form.GENERAL);
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3322
                    exp = fd.getExponent();
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3323
                    mant.append(fd.getMantissa());
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3324
                    expRounded = fd.getExponentRounded();
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3325
                }
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3326
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                if (exp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
                    prec -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                } else {
18545
5f4e734fad1b 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
bpb
parents: 18143
diff changeset
  3330
                    prec -= expRounded + 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3333
                addZeros(mant, prec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
                // If the precision is zero and the '#' flag is set, add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
                // requested decimal point.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3336
                if (f.contains(Flags.ALTERNATE) && (prec == 0)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3337
                    mant.append('.');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3338
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
                int newW = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
                if (width != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
                    if (exp != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                        newW = adjustWidth(width - exp.length - 1, f, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
                        newW = adjustWidth(width, f, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
                }
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3347
                localizedMagnitude(sb, mant, 0, f, newW, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
                if (exp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
                    sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
                    char sign = exp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
                    assert(sign == '+' || sign == '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                    sb.append(sign);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3356
                    localizedMagnitudeExp(sb, exp, 1, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
            } else if (c == Conversion.HEXADECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
                int prec = precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
                if (precision == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
                    // assume that we want all of the digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
                    prec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
                else if (precision == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
                    prec = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                String s = hexDouble(value, prec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3368
                StringBuilder va = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                boolean upper = f.contains(Flags.UPPERCASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
                sb.append(upper ? "0X" : "0x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3372
                if (f.contains(Flags.ZERO_PAD)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3373
                    trailingZeros(sb, width - s.length() - 2);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3374
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
                int idx = s.indexOf('p');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
                if (upper) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3378
                    String tmp = s.substring(0, idx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
                    // don't localize hex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
                    tmp = tmp.toUpperCase(Locale.US);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3381
                    va.append(tmp);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3382
                } else {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3383
                    va.append(s, 0, idx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                }
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3385
                if (prec != 0) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3386
                    addZeros(va, prec);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3387
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3388
                sb.append(va);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                sb.append(upper ? 'P' : 'p');
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3390
                sb.append(s, idx+1, s.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
        // Add zeros to the requested precision.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3395
        private void addZeros(StringBuilder sb, int prec) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            // Look for the dot.  If we don't find one, the we'll need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
            // it before we add the zeros.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3398
            int len = sb.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
            int i;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3400
            for (i = 0; i < len; i++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3401
                if (sb.charAt(i) == '.') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                    break;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3403
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            boolean needDot = false;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3406
            if (i == len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                needDot = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
            // Determine existing precision.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3411
            int outPrec = len - i - (needDot ? 0 : 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
            assert (outPrec <= prec);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3413
            if (outPrec == prec) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3414
                return;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3415
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            // Add dot if previously determined to be necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
            if (needDot) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3419
                sb.append('.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
            // Add zeros.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3423
            trailingZeros(sb, prec - outPrec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
        // Method assumes that d > 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
        private String hexDouble(double d, int prec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
            // Let Double.toHexString handle simple cases
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3429
            if (!Double.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
                // remove "0x"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
                return Double.toHexString(d).substring(2);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3432
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
                assert(prec >= 1 && prec <= 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9689
diff changeset
  3435
                int exponent  = Math.getExponent(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                boolean subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                    = (exponent == DoubleConsts.MIN_EXPONENT - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                // If this is subnormal input so normalize (could be faster to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                // do as integer operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                if (subnormal) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9689
diff changeset
  3442
                    scaleUp = Math.scalb(1.0, 54);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                    d *= scaleUp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
                    // Calculate the exponent.  This is not just exponent + 54
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
                    // since the former is not the normalized exponent.
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9689
diff changeset
  3446
                    exponent = Math.getExponent(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
                    assert exponent >= DoubleConsts.MIN_EXPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
                        exponent <= DoubleConsts.MAX_EXPONENT: exponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                int precision = 1 + prec*4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                int shiftDistance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                    =  DoubleConsts.SIGNIFICAND_WIDTH - precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                assert(shiftDistance >= 1 && shiftDistance < DoubleConsts.SIGNIFICAND_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                long doppel = Double.doubleToLongBits(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
                // Deterime the number of bits to keep.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                long newSignif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
                    = (doppel & (DoubleConsts.EXP_BIT_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                                 | DoubleConsts.SIGNIF_BIT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                                     >> shiftDistance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                // Bits to round away.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
                long roundingBits = doppel & ~(~0L << shiftDistance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
                // To decide how to round, look at the low-order bit of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
                // working significand, the highest order discarded bit (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                // round bit) and whether any of the lower order discarded bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                // are nonzero (the sticky bit).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                boolean leastZero = (newSignif & 0x1L) == 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                boolean round
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                    = ((1L << (shiftDistance - 1) ) & roundingBits) != 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                boolean sticky  = shiftDistance > 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
                    (~(1L<< (shiftDistance - 1)) & roundingBits) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                if((leastZero && round && sticky) || (!leastZero && round)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                    newSignif++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                long signBit = doppel & DoubleConsts.SIGN_BIT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                newSignif = signBit | (newSignif << shiftDistance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
                double result = Double.longBitsToDouble(newSignif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                if (Double.isInfinite(result) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
                    // Infinite result generated by rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
                    return "1.0p1024";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
                    String res = Double.toHexString(result).substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
                    if (!subnormal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
                        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                        // Create a normalized subnormal string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                        int idx = res.indexOf('p');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                        if (idx == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                            // No 'p' character in hex string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
                            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
                            // Get exponent and append at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
                            String exp = res.substring(idx + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
                            int iexp = Integer.parseInt(exp) -54;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
                            return res.substring(0, idx) + "p"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
                                + Integer.toString(iexp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        private void print(BigDecimal value, Locale l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            if (c == Conversion.HEXADECIMAL_FLOAT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
                failConversion(c, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
            boolean neg = value.signum() == -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
            BigDecimal v = value.abs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
            // leading sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            leadingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            // the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
            print(sb, v, l, f, c, precision, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            // trailing sign indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            trailingSign(sb, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3525
            appendJustified(a, sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
        // value > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
        private void print(StringBuilder sb, BigDecimal value, Locale l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
                           Flags f, char c, int precision, boolean neg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
            if (c == Conversion.SCIENTIFIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
                // Create a new BigDecimal with the desired precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                int prec = (precision == -1 ? 6 : precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                int scale = value.scale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                int origPrec = value.precision();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                int nzeros = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                int compPrec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
                if (prec > origPrec - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
                    compPrec = origPrec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
                    nzeros = prec - (origPrec - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
                    compPrec = prec + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                MathContext mc = new MathContext(compPrec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                BigDecimal v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                    = new BigDecimal(value.unscaledValue(), scale, mc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
                BigDecimalLayout bdl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
                    = new BigDecimalLayout(v.unscaledValue(), v.scale(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
                                           BigDecimalLayoutForm.SCIENTIFIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3556
                StringBuilder mant = bdl.mantissa();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
                // Add a decimal point if necessary.  The mantissa may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
                // contain a decimal point if the scale is zero (the internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
                // representation has no fractional part) or the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                // precision is one. Append a decimal point if '#' is set or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                // we require zero padding to get to the requested precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                if ((origPrec == 1 || !bdl.hasDot())
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3564
                        && (nzeros > 0 || (f.contains(Flags.ALTERNATE)))) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3565
                    mant.append('.');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3566
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
                // Add trailing zeros in the case precision is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                // the number of available digits after the decimal separator.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3570
                trailingZeros(mant, nzeros);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3571
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3572
                StringBuilder exp = bdl.exponent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                int newW = width;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3574
                if (width != -1) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3575
                    newW = adjustWidth(width - exp.length() - 1, f, neg);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3576
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3577
                localizedMagnitude(sb, mant, 0, f, newW, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
                Flags flags = f.dup().remove(Flags.GROUP);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3582
                char sign = exp.charAt(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
                assert(sign == '+' || sign == '-');
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3584
                sb.append(sign);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3585
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3586
                sb.append(localizedMagnitude(null, exp, 1, flags, -1, l));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
            } else if (c == Conversion.DECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                // Create a new BigDecimal with the desired precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
                int prec = (precision == -1 ? 6 : precision);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
                int scale = value.scale();
1823
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3591
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3592
                if (scale > prec) {
8799
99032bb1a2b9 6796662: (fmt spec) Formatter spec on BigDecimal output should not reference Float a
sherman
parents: 8166
diff changeset
  3593
                    // more "scale" digits than the requested "precision"
1823
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3594
                    int compPrec = value.precision();
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3595
                    if (compPrec <= scale) {
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3596
                        // case of 0.xxxxxx
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3597
                        value = value.setScale(prec, RoundingMode.HALF_UP);
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3598
                    } else {
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3599
                        compPrec -= (scale - prec);
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3600
                        value = new BigDecimal(value.unscaledValue(),
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3601
                                               scale,
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3602
                                               new MathContext(compPrec));
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3603
                    }
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3604
                }
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3605
                BigDecimalLayout bdl = new BigDecimalLayout(
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3606
                                           value.unscaledValue(),
23d42a96635e 6476425: (fmt)java.util.Formatter.print() throws IllegalArgumentException on large BigDecima
sherman
parents: 2
diff changeset
  3607
                                           value.scale(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
                                           BigDecimalLayoutForm.DECIMAL_FLOAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3610
                StringBuilder mant = bdl.mantissa();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
                int nzeros = (bdl.scale() < prec ? prec - bdl.scale() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
                // Add a decimal point if necessary.  The mantissa may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
                // contain a decimal point if the scale is zero (the internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                // representation has no fractional part).  Append a decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                // point if '#' is set or we require zero padding to get to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                // requested precision.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3618
                if (bdl.scale() == 0 && (f.contains(Flags.ALTERNATE)
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3619
                        || nzeros > 0)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3620
                    mant.append('.');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3621
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
                // Add trailing zeros if the precision is greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
                // number of available digits after the decimal separator.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3625
                trailingZeros(mant, nzeros);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3626
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3627
                localizedMagnitude(sb, mant, 0, f, adjustWidth(width, f, neg), l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
            } else if (c == Conversion.GENERAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
                int prec = precision;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
                if (precision == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
                    prec = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
                else if (precision == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                    prec = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
                BigDecimal tenToTheNegFour = BigDecimal.valueOf(1, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
                BigDecimal tenToThePrec = BigDecimal.valueOf(1, -prec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
                if ((value.equals(BigDecimal.ZERO))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
                    || ((value.compareTo(tenToTheNegFour) != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
                        && (value.compareTo(tenToThePrec) == -1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
                    int e = - value.scale()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
                        + (value.unscaledValue().toString().length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
                    // xxx.yyy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
                    //   g precision (# sig digits) = #x + #y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
                    //   f precision = #y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
                    //   exponent = #x - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
                    // => f precision = g precision - exponent - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
                    // 0.000zzz
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
                    //   g precision (# sig digits) = #z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
                    //   f precision = #0 (after '.') + #z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
                    //   exponent = - #0 (after '.') - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
                    // => f precision = g precision - exponent - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
                    prec = prec - e - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                    print(sb, value, l, f, Conversion.DECIMAL_FLOAT, prec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
                          neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
                    print(sb, value, l, f, Conversion.SCIENTIFIC, prec - 1, neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
            } else if (c == Conversion.HEXADECIMAL_FLOAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
                // This conversion isn't supported.  The error should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
                // reported earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
        private class BigDecimalLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
            private StringBuilder mant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
            private StringBuilder exp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
            private boolean dot = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
            private int scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
            public BigDecimalLayout(BigInteger intVal, int scale, BigDecimalLayoutForm form) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
                layout(intVal, scale, form);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
            public boolean hasDot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
                return dot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
            public int scale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                return scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3686
            public StringBuilder mantissa() {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3687
                return mant;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
            // The exponent will be formatted as a sign ('+' or '-') followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
            // by the exponent zero-padded to include at least two digits.
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3692
            public StringBuilder exponent() {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3693
                return exp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
            private void layout(BigInteger intVal, int scale, BigDecimalLayoutForm form) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3697
                String coeff = intVal.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
                this.scale = scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
                // Construct a buffer, with sufficient capacity for all cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
                // If E-notation is needed, length will be: +1 if negative, +1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
                // if '.' needed, +2 for "E+", + up to 10 for adjusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
                // exponent.  Otherwise it could have +1 if negative, plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
                // leading "0.00000"
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3705
                int len = coeff.length();
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3706
                mant = new StringBuilder(len + 14);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
                if (scale == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
                    if (len > 1) {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3710
                        mant.append(coeff.charAt(0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
                        if (form == BigDecimalLayoutForm.SCIENTIFIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
                            mant.append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
                            dot = true;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3714
                            mant.append(coeff, 1, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
                            exp = new StringBuilder("+");
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3716
                            if (len < 10) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3717
                                exp.append('0').append(len - 1);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3718
                            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
                                exp.append(len - 1);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3720
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
                        } else {
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3722
                            mant.append(coeff, 1, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
                        mant.append(coeff);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3726
                        if (form == BigDecimalLayoutForm.SCIENTIFIC) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
                            exp = new StringBuilder("+00");
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3728
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
                    }
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3730
                } else if (form == BigDecimalLayoutForm.DECIMAL_FLOAT) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
                    // count of padding zeros
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3732
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3733
                    if (scale >= len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                        // 0.xxx form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
                        mant.append("0.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                        dot = true;
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3737
                        trailingZeros(mant, scale - len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                        mant.append(coeff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
                    } else {
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3740
                        if (scale > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
                            // xx.xx form
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3742
                            int pad = len - scale;
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3743
                            mant.append(coeff, 0, pad);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
                            mant.append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
                            dot = true;
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3746
                            mant.append(coeff, pad, len);
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3747
                        } else { // scale < 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
                            // xx form
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3749
                            mant.append(coeff, 0, len);
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3750
                            if (intVal.signum() != 0) {
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3751
                                trailingZeros(mant, -scale);
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3752
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
                            this.scale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
                    // x.xxx form
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3758
                    mant.append(coeff.charAt(0));
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3759
                    if (len > 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
                        mant.append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
                        dot = true;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3762
                        mant.append(coeff, 1, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
                    exp = new StringBuilder();
28302
5de69b0d3a84 8059175: Zero BigDecimal with negative scale prints leading zeroes in String.format
bpb
parents: 27731
diff changeset
  3765
                    long adjusted = -(long) scale + (len - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
                    if (adjusted != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
                        long abs = Math.abs(adjusted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
                        // require sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
                        exp.append(adjusted < 0 ? '-' : '+');
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3770
                        if (abs < 10) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
                            exp.append('0');
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3772
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
                        exp.append(abs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
                        exp.append("+00");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
        private int adjustWidth(int width, Flags f, boolean neg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
            int newW = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            if (newW != -1 && neg && f.contains(Flags.PARENTHESES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                newW--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            return newW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3788
        // Add trailing zeros
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3789
        private void trailingZeros(StringBuilder sb, int nzeros) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3790
            for (int i = 0; i < nzeros; i++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3791
                sb.append('0');
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3792
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3795
        private void print(Calendar t, char c, Locale l)  throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
            print(sb, t, c, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3800
            if (f.contains(Flags.UPPERCASE)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3801
                appendJustified(a, sb.toString().toUpperCase());
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3802
            } else {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3803
                appendJustified(a, sb);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3804
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3807
        private Appendable print(StringBuilder sb, Calendar t, char c, Locale l)
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3808
                throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
            if (sb == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
            case DateTime.HOUR_OF_DAY_0: // 'H' (00 - 23)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
            case DateTime.HOUR_0:        // 'I' (01 - 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            case DateTime.HOUR_OF_DAY:   // 'k' (0 - 23) -- like H
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            case DateTime.HOUR:        { // 'l' (1 - 12) -- like I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
                int i = t.get(Calendar.HOUR_OF_DAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
                if (c == DateTime.HOUR_0 || c == DateTime.HOUR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                    i = (i == 0 || i == 12 ? 12 : i % 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
                Flags flags = (c == DateTime.HOUR_OF_DAY_0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                               || c == DateTime.HOUR_0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
                               ? Flags.ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                               : Flags.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                sb.append(localizedMagnitude(null, i, flags, 2, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
            case DateTime.MINUTE:      { // 'M' (00 - 59)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                int i = t.get(Calendar.MINUTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                sb.append(localizedMagnitude(null, i, flags, 2, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
            case DateTime.NANOSECOND:  { // 'N' (000000000 - 999999999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                int i = t.get(Calendar.MILLISECOND) * 1000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
                sb.append(localizedMagnitude(null, i, flags, 9, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
            case DateTime.MILLISECOND: { // 'L' (000 - 999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
                int i = t.get(Calendar.MILLISECOND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
                sb.append(localizedMagnitude(null, i, flags, 3, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
            case DateTime.MILLISECOND_SINCE_EPOCH: { // 'Q' (0 - 99...?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
                long i = t.getTimeInMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
                Flags flags = Flags.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
                sb.append(localizedMagnitude(null, i, flags, width, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
            case DateTime.AM_PM:       { // 'p' (am or pm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
                // Calendar.AM = 0, Calendar.PM = 1, LocaleElements defines upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
                String[] ampm = { "AM", "PM" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
                if (l != null && l != Locale.US) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
                    DateFormatSymbols dfs = DateFormatSymbols.getInstance(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
                    ampm = dfs.getAmPmStrings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
                String s = ampm[t.get(Calendar.AM_PM)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
                sb.append(s.toLowerCase(l != null ? l : Locale.US));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
            case DateTime.SECONDS_SINCE_EPOCH: { // 's' (0 - 99...?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
                long i = t.getTimeInMillis() / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
                Flags flags = Flags.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
                sb.append(localizedMagnitude(null, i, flags, width, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
            case DateTime.SECOND:      { // 'S' (00 - 60 - leap second)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
                int i = t.get(Calendar.SECOND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
                sb.append(localizedMagnitude(null, i, flags, 2, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
            case DateTime.ZONE_NUMERIC: { // 'z' ({-|+}####) - ls minus?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
                int i = t.get(Calendar.ZONE_OFFSET) + t.get(Calendar.DST_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
                boolean neg = i < 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
                sb.append(neg ? '-' : '+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                if (neg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                    i = -i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
                int min = i / 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
                // combine minute and hour into a single integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                int offset = (min / 60) * 100 + (min % 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
                sb.append(localizedMagnitude(null, offset, flags, 4, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
            case DateTime.ZONE:        { // 'Z' (symbol)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
                TimeZone tz = t.getTimeZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                sb.append(tz.getDisplayName((t.get(Calendar.DST_OFFSET) != 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                                           TimeZone.SHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
                                            (l == null) ? Locale.US : l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
            // Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
            case DateTime.NAME_OF_DAY_ABBREV:     // 'a'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
            case DateTime.NAME_OF_DAY:          { // 'A'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
                int i = t.get(Calendar.DAY_OF_WEEK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                Locale lt = ((l == null) ? Locale.US : l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
                if (c == DateTime.NAME_OF_DAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
                    sb.append(dfs.getWeekdays()[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
                    sb.append(dfs.getShortWeekdays()[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
            case DateTime.NAME_OF_MONTH_ABBREV:   // 'b'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
            case DateTime.NAME_OF_MONTH_ABBREV_X: // 'h' -- same b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            case DateTime.NAME_OF_MONTH:        { // 'B'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
                int i = t.get(Calendar.MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
                Locale lt = ((l == null) ? Locale.US : l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
                DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
                if (c == DateTime.NAME_OF_MONTH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
                    sb.append(dfs.getMonths()[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
                    sb.append(dfs.getShortMonths()[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
            case DateTime.CENTURY:                // 'C' (00 - 99)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
            case DateTime.YEAR_2:                 // 'y' (00 - 99)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
            case DateTime.YEAR_4:               { // 'Y' (0000 - 9999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
                int i = t.get(Calendar.YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                int size = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
                case DateTime.CENTURY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
                    i /= 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
                case DateTime.YEAR_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
                    i %= 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
                case DateTime.YEAR_4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
                    size = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                sb.append(localizedMagnitude(null, i, flags, size, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
            case DateTime.DAY_OF_MONTH_0:         // 'd' (01 - 31)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
            case DateTime.DAY_OF_MONTH:         { // 'e' (1 - 31) -- like d
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                int i = t.get(Calendar.DATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                Flags flags = (c == DateTime.DAY_OF_MONTH_0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                               ? Flags.ZERO_PAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                               : Flags.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
                sb.append(localizedMagnitude(null, i, flags, 2, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
            case DateTime.DAY_OF_YEAR:          { // 'j' (001 - 366)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
                int i = t.get(Calendar.DAY_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                sb.append(localizedMagnitude(null, i, flags, 3, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
            case DateTime.MONTH:                { // 'm' (01 - 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                int i = t.get(Calendar.MONTH) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
                Flags flags = Flags.ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
                sb.append(localizedMagnitude(null, i, flags, 2, l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
            // Composites
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
            case DateTime.TIME:         // 'T' (24 hour hh:mm:ss - %tH:%tM:%tS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
            case DateTime.TIME_24_HOUR:    { // 'R' (hh:mm same as %H:%M)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
                char sep = ':';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
                print(sb, t, DateTime.HOUR_OF_DAY_0, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
                print(sb, t, DateTime.MINUTE, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
                if (c == DateTime.TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
                    sb.append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                    print(sb, t, DateTime.SECOND, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
            case DateTime.TIME_12_HOUR:    { // 'r' (hh:mm:ss [AP]M)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
                char sep = ':';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
                print(sb, t, DateTime.HOUR_0, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
                print(sb, t, DateTime.MINUTE, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
                print(sb, t, DateTime.SECOND, l).append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
                // this may be in wrong place for some locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
                StringBuilder tsb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                print(tsb, t, DateTime.AM_PM, l);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  3981
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                sb.append(tsb.toString().toUpperCase(l != null ? l : Locale.US));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
            case DateTime.DATE_TIME:    { // 'c' (Sat Nov 04 12:02:33 EST 1999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                char sep = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                print(sb, t, DateTime.NAME_OF_DAY_ABBREV, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
                print(sb, t, DateTime.NAME_OF_MONTH_ABBREV, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                print(sb, t, DateTime.TIME, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                print(sb, t, DateTime.ZONE, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                print(sb, t, DateTime.YEAR_4, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
            case DateTime.DATE:            { // 'D' (mm/dd/yy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                char sep = '/';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                print(sb, t, DateTime.MONTH, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                print(sb, t, DateTime.YEAR_2, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
            case DateTime.ISO_STANDARD_DATE: { // 'F' (%Y-%m-%d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                char sep = '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
                print(sb, t, DateTime.YEAR_4, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                print(sb, t, DateTime.MONTH, l).append(sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                print(sb, t, DateTime.DAY_OF_MONTH_0, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
            return sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4015
        private void print(TemporalAccessor t, char c, Locale l)  throws IOException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4016
            StringBuilder sb = new StringBuilder();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4017
            print(sb, t, c, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4018
            // justify based on width
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4019
            if (f.contains(Flags.UPPERCASE)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4020
                appendJustified(a, sb.toString().toUpperCase());
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4021
            } else {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4022
                appendJustified(a, sb);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4023
            }
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4024
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4025
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4026
        private Appendable print(StringBuilder sb, TemporalAccessor t, char c,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4027
                                 Locale l) throws IOException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4028
            if (sb == null)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4029
                sb = new StringBuilder();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4030
            try {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4031
                switch (c) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4032
                case DateTime.HOUR_OF_DAY_0: {  // 'H' (00 - 23)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4033
                    int i = t.get(ChronoField.HOUR_OF_DAY);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4034
                    sb.append(localizedMagnitude(null, i, Flags.ZERO_PAD, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4035
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4036
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4037
                case DateTime.HOUR_OF_DAY: {   // 'k' (0 - 23) -- like H
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4038
                    int i = t.get(ChronoField.HOUR_OF_DAY);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4039
                    sb.append(localizedMagnitude(null, i, Flags.NONE, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4040
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4041
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4042
                case DateTime.HOUR_0:      {  // 'I' (01 - 12)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4043
                    int i = t.get(ChronoField.CLOCK_HOUR_OF_AMPM);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4044
                    sb.append(localizedMagnitude(null, i, Flags.ZERO_PAD, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4045
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4046
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4047
                case DateTime.HOUR:        { // 'l' (1 - 12) -- like I
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4048
                    int i = t.get(ChronoField.CLOCK_HOUR_OF_AMPM);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4049
                    sb.append(localizedMagnitude(null, i, Flags.NONE, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4050
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4051
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4052
                case DateTime.MINUTE:      { // 'M' (00 - 59)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4053
                    int i = t.get(ChronoField.MINUTE_OF_HOUR);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4054
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4055
                    sb.append(localizedMagnitude(null, i, flags, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4056
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4057
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4058
                case DateTime.NANOSECOND:  { // 'N' (000000000 - 999999999)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4059
                    int i = t.get(ChronoField.MILLI_OF_SECOND) * 1000000;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4060
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4061
                    sb.append(localizedMagnitude(null, i, flags, 9, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4062
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4063
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4064
                case DateTime.MILLISECOND: { // 'L' (000 - 999)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4065
                    int i = t.get(ChronoField.MILLI_OF_SECOND);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4066
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4067
                    sb.append(localizedMagnitude(null, i, flags, 3, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4068
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4069
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4070
                case DateTime.MILLISECOND_SINCE_EPOCH: { // 'Q' (0 - 99...?)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4071
                    long i = t.getLong(ChronoField.INSTANT_SECONDS) * 1000L +
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4072
                             t.getLong(ChronoField.MILLI_OF_SECOND);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4073
                    Flags flags = Flags.NONE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4074
                    sb.append(localizedMagnitude(null, i, flags, width, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4075
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4076
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4077
                case DateTime.AM_PM:       { // 'p' (am or pm)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4078
                    // Calendar.AM = 0, Calendar.PM = 1, LocaleElements defines upper
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4079
                    String[] ampm = { "AM", "PM" };
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4080
                    if (l != null && l != Locale.US) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4081
                        DateFormatSymbols dfs = DateFormatSymbols.getInstance(l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4082
                        ampm = dfs.getAmPmStrings();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4083
                    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4084
                    String s = ampm[t.get(ChronoField.AMPM_OF_DAY)];
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4085
                    sb.append(s.toLowerCase(l != null ? l : Locale.US));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4086
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4087
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4088
                case DateTime.SECONDS_SINCE_EPOCH: { // 's' (0 - 99...?)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4089
                    long i = t.getLong(ChronoField.INSTANT_SECONDS);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4090
                    Flags flags = Flags.NONE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4091
                    sb.append(localizedMagnitude(null, i, flags, width, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4092
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4093
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4094
                case DateTime.SECOND:      { // 'S' (00 - 60 - leap second)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4095
                    int i = t.get(ChronoField.SECOND_OF_MINUTE);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4096
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4097
                    sb.append(localizedMagnitude(null, i, flags, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4098
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4099
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4100
                case DateTime.ZONE_NUMERIC: { // 'z' ({-|+}####) - ls minus?
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4101
                    int i = t.get(ChronoField.OFFSET_SECONDS);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4102
                    boolean neg = i < 0;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4103
                    sb.append(neg ? '-' : '+');
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4104
                    if (neg)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4105
                        i = -i;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4106
                    int min = i / 60;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4107
                    // combine minute and hour into a single integer
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4108
                    int offset = (min / 60) * 100 + (min % 60);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4109
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4110
                    sb.append(localizedMagnitude(null, offset, flags, 4, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4111
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4112
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4113
                case DateTime.ZONE:        { // 'Z' (symbol)
20795
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 19426
diff changeset
  4114
                    ZoneId zid = t.query(TemporalQueries.zone());
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4115
                    if (zid == null) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4116
                        throw new IllegalFormatConversionException(c, t.getClass());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4117
                    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4118
                    if (!(zid instanceof ZoneOffset) &&
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4119
                        t.isSupported(ChronoField.INSTANT_SECONDS)) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4120
                        Instant instant = Instant.from(t);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4121
                        sb.append(TimeZone.getTimeZone(zid.getId())
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4122
                                          .getDisplayName(zid.getRules().isDaylightSavings(instant),
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4123
                                                          TimeZone.SHORT,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4124
                                                          (l == null) ? Locale.US : l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4125
                        break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4126
                    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4127
                    sb.append(zid.getId());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4128
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4129
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4130
                // Date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4131
                case DateTime.NAME_OF_DAY_ABBREV:     // 'a'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4132
                case DateTime.NAME_OF_DAY:          { // 'A'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4133
                    int i = t.get(ChronoField.DAY_OF_WEEK) % 7 + 1;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4134
                    Locale lt = ((l == null) ? Locale.US : l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4135
                    DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4136
                    if (c == DateTime.NAME_OF_DAY)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4137
                        sb.append(dfs.getWeekdays()[i]);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4138
                    else
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4139
                        sb.append(dfs.getShortWeekdays()[i]);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4140
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4141
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4142
                case DateTime.NAME_OF_MONTH_ABBREV:   // 'b'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4143
                case DateTime.NAME_OF_MONTH_ABBREV_X: // 'h' -- same b
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4144
                case DateTime.NAME_OF_MONTH:        { // 'B'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4145
                    int i = t.get(ChronoField.MONTH_OF_YEAR) - 1;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4146
                    Locale lt = ((l == null) ? Locale.US : l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4147
                    DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4148
                    if (c == DateTime.NAME_OF_MONTH)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4149
                        sb.append(dfs.getMonths()[i]);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4150
                    else
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4151
                        sb.append(dfs.getShortMonths()[i]);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4152
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4153
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4154
                case DateTime.CENTURY:                // 'C' (00 - 99)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4155
                case DateTime.YEAR_2:                 // 'y' (00 - 99)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4156
                case DateTime.YEAR_4:               { // 'Y' (0000 - 9999)
19426
daf0425c0ca6 8022193: java/time/test/java/util/TestFormatter.java failed in th locale.
rriggs
parents: 19196
diff changeset
  4157
                    int i = t.get(ChronoField.YEAR_OF_ERA);
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4158
                    int size = 2;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4159
                    switch (c) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4160
                    case DateTime.CENTURY:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4161
                        i /= 100;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4162
                        break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4163
                    case DateTime.YEAR_2:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4164
                        i %= 100;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4165
                        break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4166
                    case DateTime.YEAR_4:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4167
                        size = 4;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4168
                        break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4169
                    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4170
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4171
                    sb.append(localizedMagnitude(null, i, flags, size, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4172
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4173
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4174
                case DateTime.DAY_OF_MONTH_0:         // 'd' (01 - 31)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4175
                case DateTime.DAY_OF_MONTH:         { // 'e' (1 - 31) -- like d
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4176
                    int i = t.get(ChronoField.DAY_OF_MONTH);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4177
                    Flags flags = (c == DateTime.DAY_OF_MONTH_0
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4178
                                   ? Flags.ZERO_PAD
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4179
                                   : Flags.NONE);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4180
                    sb.append(localizedMagnitude(null, i, flags, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4181
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4182
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4183
                case DateTime.DAY_OF_YEAR:          { // 'j' (001 - 366)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4184
                    int i = t.get(ChronoField.DAY_OF_YEAR);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4185
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4186
                    sb.append(localizedMagnitude(null, i, flags, 3, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4187
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4188
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4189
                case DateTime.MONTH:                { // 'm' (01 - 12)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4190
                    int i = t.get(ChronoField.MONTH_OF_YEAR);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4191
                    Flags flags = Flags.ZERO_PAD;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4192
                    sb.append(localizedMagnitude(null, i, flags, 2, l));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4193
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4194
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4195
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4196
                // Composites
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4197
                case DateTime.TIME:         // 'T' (24 hour hh:mm:ss - %tH:%tM:%tS)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4198
                case DateTime.TIME_24_HOUR:    { // 'R' (hh:mm same as %H:%M)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4199
                    char sep = ':';
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4200
                    print(sb, t, DateTime.HOUR_OF_DAY_0, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4201
                    print(sb, t, DateTime.MINUTE, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4202
                    if (c == DateTime.TIME) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4203
                        sb.append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4204
                        print(sb, t, DateTime.SECOND, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4205
                    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4206
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4207
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4208
                case DateTime.TIME_12_HOUR:    { // 'r' (hh:mm:ss [AP]M)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4209
                    char sep = ':';
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4210
                    print(sb, t, DateTime.HOUR_0, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4211
                    print(sb, t, DateTime.MINUTE, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4212
                    print(sb, t, DateTime.SECOND, l).append(' ');
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4213
                    // this may be in wrong place for some locales
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4214
                    StringBuilder tsb = new StringBuilder();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4215
                    print(tsb, t, DateTime.AM_PM, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4216
                    sb.append(tsb.toString().toUpperCase(l != null ? l : Locale.US));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4217
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4218
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4219
                case DateTime.DATE_TIME:    { // 'c' (Sat Nov 04 12:02:33 EST 1999)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4220
                    char sep = ' ';
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4221
                    print(sb, t, DateTime.NAME_OF_DAY_ABBREV, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4222
                    print(sb, t, DateTime.NAME_OF_MONTH_ABBREV, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4223
                    print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4224
                    print(sb, t, DateTime.TIME, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4225
                    print(sb, t, DateTime.ZONE, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4226
                    print(sb, t, DateTime.YEAR_4, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4227
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4228
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4229
                case DateTime.DATE:            { // 'D' (mm/dd/yy)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4230
                    char sep = '/';
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4231
                    print(sb, t, DateTime.MONTH, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4232
                    print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4233
                    print(sb, t, DateTime.YEAR_2, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4234
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4235
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4236
                case DateTime.ISO_STANDARD_DATE: { // 'F' (%Y-%m-%d)
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4237
                    char sep = '-';
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4238
                    print(sb, t, DateTime.YEAR_4, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4239
                    print(sb, t, DateTime.MONTH, l).append(sep);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4240
                    print(sb, t, DateTime.DAY_OF_MONTH_0, l);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4241
                    break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4242
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4243
                default:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4244
                    assert false;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4245
                }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4246
            } catch (DateTimeException x) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4247
                throw new IllegalFormatConversionException(c, t.getClass());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4248
            }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4249
            return sb;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4250
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents: 15271
diff changeset
  4251
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
        // -- Methods to support throwing exceptions --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
        private void failMismatch(Flags f, char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
            String fs = f.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
            throw new FormatFlagsConversionMismatchException(fs, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
        private void failConversion(char c, Object arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
            throw new IllegalFormatConversionException(c, arg.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
        private char getZero(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
            if ((l != null) &&  !l.equals(locale())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
                return dfs.getZeroDigit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
            return zero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4271
        private StringBuilder localizedMagnitude(StringBuilder sb,
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4272
                long value, Flags f, int width, Locale l) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4273
            return localizedMagnitude(sb, Long.toString(value, 10), 0, f, width, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4276
        private StringBuilder localizedMagnitude(StringBuilder sb,
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4277
                CharSequence value, final int offset, Flags f, int width,
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4278
                Locale l) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4279
            if (sb == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                sb = new StringBuilder();
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4281
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
            int begin = sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
            char zero = getZero(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
            // determine localized grouping separator and size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
            char grpSep = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
            int  grpSize = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
            char decSep = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4291
            int len = value.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
            int dot = len;
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4293
            for (int j = offset; j < len; j++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4294
                if (value.charAt(j) == '.') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
                    dot = j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
            if (dot < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                if (l == null || l.equals(Locale.US)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
                    decSep  = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
                    decSep  = dfs.getDecimalSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
            if (f.contains(Flags.GROUP)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                if (l == null || l.equals(Locale.US)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                    grpSep = ',';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
                    grpSize = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
                    grpSep = dfs.getGroupingSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                    DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
                    grpSize = df.getGroupingSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
            // localize the digits inserting group separators as necessary
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4322
            for (int j = offset; j < len; j++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
                if (j == dot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
                    sb.append(decSep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
                    // no more group separators after the decimal separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
                    grpSep = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4330
                char c = value.charAt(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
                sb.append((char) ((c - '0') + zero));
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4332
                if (grpSep != '\0' && j != dot - 1 && ((dot - j) % grpSize == 1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
                    sb.append(grpSep);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4334
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
            // apply zero padding
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4338
            if (width != -1 && f.contains(Flags.ZERO_PAD)) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4339
                for (int k = sb.length(); k < width; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
                    sb.insert(begin, zero);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4341
                }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4342
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
            return sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
        }
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4346
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4347
        // Specialized localization of exponents, where the source value can only
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4348
        // contain characters '0' through '9', starting at index offset, and no
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4349
        // group separators is added for any locale.
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4350
        private void localizedMagnitudeExp(StringBuilder sb, char[] value,
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4351
                final int offset, Locale l) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4352
            char zero = getZero(l);
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4353
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4354
            int len = value.length;
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4355
            for (int j = offset; j < len; j++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4356
                char c = value[j];
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4357
                sb.append((char) ((c - '0') + zero));
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4358
            }
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4359
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
    private static class Flags {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
        private int flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
        static final Flags NONE          = new Flags(0);      // ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
        // duplicate declarations from Formattable.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
        static final Flags LEFT_JUSTIFY  = new Flags(1<<0);   // '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
        static final Flags UPPERCASE     = new Flags(1<<1);   // '^'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
        static final Flags ALTERNATE     = new Flags(1<<2);   // '#'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
        // numerics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
        static final Flags PLUS          = new Flags(1<<3);   // '+'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
        static final Flags LEADING_SPACE = new Flags(1<<4);   // ' '
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
        static final Flags ZERO_PAD      = new Flags(1<<5);   // '0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
        static final Flags GROUP         = new Flags(1<<6);   // ','
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
        static final Flags PARENTHESES   = new Flags(1<<7);   // '('
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
        // indexing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
        static final Flags PREVIOUS      = new Flags(1<<8);   // '<'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
        private Flags(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
            flags = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
        public int valueOf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
            return flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
        public boolean contains(Flags f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
            return (flags & f.valueOf()) == f.valueOf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
        public Flags dup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
            return new Flags(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
        private Flags add(Flags f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
            flags |= f.valueOf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
        public Flags remove(Flags f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            flags &= ~f.valueOf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4408
        public static Flags parse(String s, int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
            Flags f = new Flags(0);
26733
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4410
            for (int i = start; i < end; i++) {
bb835fd801b6 8050142: Optimize java.util.Formatter
bchristi
parents: 25859
diff changeset
  4411
                char c = s.charAt(i);
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 21368
diff changeset
  4412
                Flags v = parse(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
                if (f.contains(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
                    throw new DuplicateFormatFlagsException(v.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
                f.add(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
        // parse those flags which may be provided by users
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
        private static Flags parse(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
            case '-': return LEFT_JUSTIFY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
            case '#': return ALTERNATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            case '+': return PLUS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            case ' ': return LEADING_SPACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
            case '0': return ZERO_PAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
            case ',': return GROUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
            case '(': return PARENTHESES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
            case '<': return PREVIOUS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
                throw new UnknownFormatFlagsException(String.valueOf(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
1939
5153d540b7a8 6799343: (fmt) java.util.Formatter uses plainlink instead of linkplain
darcy
parents: 1823
diff changeset
  4436
        // Returns a string representation of the current {@code Flags}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
        public static String toString(Flags f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
            return f.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            if (contains(LEFT_JUSTIFY))  sb.append('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
            if (contains(UPPERCASE))     sb.append('^');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
            if (contains(ALTERNATE))     sb.append('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
            if (contains(PLUS))          sb.append('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
            if (contains(LEADING_SPACE)) sb.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
            if (contains(ZERO_PAD))      sb.append('0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
            if (contains(GROUP))         sb.append(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
            if (contains(PARENTHESES))   sb.append('(');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
            if (contains(PREVIOUS))      sb.append('<');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
    private static class Conversion {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
        // Byte, Short, Integer, Long, BigInteger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
        // (and associated primitives due to autoboxing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
        static final char DECIMAL_INTEGER     = 'd';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
        static final char OCTAL_INTEGER       = 'o';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
        static final char HEXADECIMAL_INTEGER = 'x';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
        static final char HEXADECIMAL_INTEGER_UPPER = 'X';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
        // Float, Double, BigDecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
        // (and associated primitives due to autoboxing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
        static final char SCIENTIFIC          = 'e';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
        static final char SCIENTIFIC_UPPER    = 'E';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
        static final char GENERAL             = 'g';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
        static final char GENERAL_UPPER       = 'G';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
        static final char DECIMAL_FLOAT       = 'f';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
        static final char HEXADECIMAL_FLOAT   = 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
        static final char HEXADECIMAL_FLOAT_UPPER = 'A';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
        // Character, Byte, Short, Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
        // (and associated primitives due to autoboxing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
        static final char CHARACTER           = 'c';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        static final char CHARACTER_UPPER     = 'C';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        // java.util.Date, java.util.Calendar, long
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
        static final char DATE_TIME           = 't';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        static final char DATE_TIME_UPPER     = 'T';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        // if (arg.TYPE != boolean) return boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        // if (arg != null) return true; else return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        static final char BOOLEAN             = 'b';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        static final char BOOLEAN_UPPER       = 'B';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        // if (arg instanceof Formattable) arg.formatTo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        // else arg.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
        static final char STRING              = 's';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
        static final char STRING_UPPER        = 'S';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
        // arg.hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
        static final char HASHCODE            = 'h';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
        static final char HASHCODE_UPPER      = 'H';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
        static final char LINE_SEPARATOR      = 'n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
        static final char PERCENT_SIGN        = '%';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
        static boolean isValid(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
            return (isGeneral(c) || isInteger(c) || isFloat(c) || isText(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
                    || c == 't' || isCharacter(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
        // Returns true iff the Conversion is applicable to all objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
        static boolean isGeneral(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
            case BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
            case BOOLEAN_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
            case STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
            case STRING_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
            case HASHCODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
            case HASHCODE_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
        // Returns true iff the Conversion is applicable to character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
        static boolean isCharacter(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
            case CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
            case CHARACTER_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
        // Returns true iff the Conversion is an integer type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
        static boolean isInteger(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
            case DECIMAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
            case OCTAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
            case HEXADECIMAL_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
            case HEXADECIMAL_INTEGER_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
        // Returns true iff the Conversion is a floating-point type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
        static boolean isFloat(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
            case SCIENTIFIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
            case SCIENTIFIC_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            case GENERAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
            case GENERAL_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
            case DECIMAL_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
            case HEXADECIMAL_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
            case HEXADECIMAL_FLOAT_UPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
        // Returns true iff the Conversion does not require an argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
        static boolean isText(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
            case LINE_SEPARATOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
            case PERCENT_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
    private static class DateTime {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
        static final char HOUR_OF_DAY_0 = 'H'; // (00 - 23)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
        static final char HOUR_0        = 'I'; // (01 - 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
        static final char HOUR_OF_DAY   = 'k'; // (0 - 23) -- like H
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
        static final char HOUR          = 'l'; // (1 - 12) -- like I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
        static final char MINUTE        = 'M'; // (00 - 59)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
        static final char NANOSECOND    = 'N'; // (000000000 - 999999999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
        static final char MILLISECOND   = 'L'; // jdk, not in gnu (000 - 999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
        static final char MILLISECOND_SINCE_EPOCH = 'Q'; // (0 - 99...?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
        static final char AM_PM         = 'p'; // (am or pm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
        static final char SECONDS_SINCE_EPOCH = 's'; // (0 - 99...?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
        static final char SECOND        = 'S'; // (00 - 60 - leap second)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
        static final char TIME          = 'T'; // (24 hour hh:mm:ss)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
        static final char ZONE_NUMERIC  = 'z'; // (-1200 - +1200) - ls minus?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
        static final char ZONE          = 'Z'; // (symbol)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
        // Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
        static final char NAME_OF_DAY_ABBREV    = 'a'; // 'a'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
        static final char NAME_OF_DAY           = 'A'; // 'A'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
        static final char NAME_OF_MONTH_ABBREV  = 'b'; // 'b'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
        static final char NAME_OF_MONTH         = 'B'; // 'B'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
        static final char CENTURY               = 'C'; // (00 - 99)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
        static final char DAY_OF_MONTH_0        = 'd'; // (01 - 31)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
        static final char DAY_OF_MONTH          = 'e'; // (1 - 31) -- like d
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
// *    static final char ISO_WEEK_OF_YEAR_2    = 'g'; // cross %y %V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
// *    static final char ISO_WEEK_OF_YEAR_4    = 'G'; // cross %Y %V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
        static final char NAME_OF_MONTH_ABBREV_X  = 'h'; // -- same b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        static final char DAY_OF_YEAR           = 'j'; // (001 - 366)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
        static final char MONTH                 = 'm'; // (01 - 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
// *    static final char DAY_OF_WEEK_1         = 'u'; // (1 - 7) Monday
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
// *    static final char WEEK_OF_YEAR_SUNDAY   = 'U'; // (0 - 53) Sunday+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
// *    static final char WEEK_OF_YEAR_MONDAY_01 = 'V'; // (01 - 53) Monday+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
// *    static final char DAY_OF_WEEK_0         = 'w'; // (0 - 6) Sunday
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
// *    static final char WEEK_OF_YEAR_MONDAY   = 'W'; // (00 - 53) Monday
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
        static final char YEAR_2                = 'y'; // (00 - 99)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
        static final char YEAR_4                = 'Y'; // (0000 - 9999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
        // Composites
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
        static final char TIME_12_HOUR  = 'r'; // (hh:mm:ss [AP]M)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
        static final char TIME_24_HOUR  = 'R'; // (hh:mm same as %H:%M)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
// *    static final char LOCALE_TIME   = 'X'; // (%H:%M:%S) - parse format?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        static final char DATE_TIME             = 'c';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
                                            // (Sat Nov 04 12:02:33 EST 1999)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
        static final char DATE                  = 'D'; // (mm/dd/yy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
        static final char ISO_STANDARD_DATE     = 'F'; // (%Y-%m-%d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
// *    static final char LOCALE_DATE           = 'x'; // (mm/dd/yy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
        static boolean isValid(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
            case HOUR_OF_DAY_0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
            case HOUR_0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
            case HOUR_OF_DAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
            case HOUR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
            case MINUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
            case NANOSECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
            case MILLISECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
            case MILLISECOND_SINCE_EPOCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
            case AM_PM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
            case SECONDS_SINCE_EPOCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
            case SECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
            case TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
            case ZONE_NUMERIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
            case ZONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
            // Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
            case NAME_OF_DAY_ABBREV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
            case NAME_OF_DAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
            case NAME_OF_MONTH_ABBREV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
            case NAME_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
            case CENTURY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
            case DAY_OF_MONTH_0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
            case DAY_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
// *        case ISO_WEEK_OF_YEAR_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
// *        case ISO_WEEK_OF_YEAR_4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
            case NAME_OF_MONTH_ABBREV_X:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
            case DAY_OF_YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
            case MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
// *        case DAY_OF_WEEK_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
// *        case WEEK_OF_YEAR_SUNDAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
// *        case WEEK_OF_YEAR_MONDAY_01:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
// *        case DAY_OF_WEEK_0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
// *        case WEEK_OF_YEAR_MONDAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
            case YEAR_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
            case YEAR_4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
            // Composites
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            case TIME_12_HOUR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
            case TIME_24_HOUR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
// *        case LOCALE_TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
            case DATE_TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
            case DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
            case ISO_STANDARD_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
// *        case LOCALE_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
}