src/java.base/share/classes/java/text/FieldPosition.java
author jboes
Tue, 24 Sep 2019 09:43:43 +0100
changeset 58288 48e480e56aad
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: bchristi, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2019, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    42
 * {@code FieldPosition} is a simple class used by {@code Format}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * and its subclasses to identify fields in formatted output. Fields can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * be identified in two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  <li>By an integer constant, whose names typically end with
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    47
 *      {@code _FIELD}. The constants are defined in the various
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    48
 *      subclasses of {@code Format}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    49
 *  <li>By a {@code Format.Field} constant, see {@code ERA_FIELD}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    50
 *      and its friends in {@code DateFormat} for an example.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    53
 * {@code FieldPosition} keeps track of the position of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * field within the formatted output with two indices: the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * of the first character of the field and the index of the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * character of the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    59
 * One version of the {@code format} method in the various
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    60
 * {@code Format} classes requires a {@code FieldPosition}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    61
 * object as an argument. You use this {@code format} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * to perform partial formatting or to get information about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * formatted output (such as the position of a field).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * If you are interested in the positions of all attributes in the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    67
 * formatted string use the {@code Format} method
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
    68
 * {@code formatToCharacterIterator}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author      Mark Davis
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 25859
diff changeset
    71
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see         java.text.Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
public class FieldPosition {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Input: Desired field to determine start and end offsets for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * The meaning depends on the subclass of Format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    int field = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Output: End offset of field in text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * If the field does not occur in the text, 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    int endIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Output: Start offset of field in text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * If the field does not occur in the text, 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int beginIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Desired field this FieldPosition is for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private Format.Field attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates a FieldPosition object for the given field.  Fields are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * identified by constants, whose names typically end with _FIELD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * in the various subclasses of Format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   104
     * @param field the field identifier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see java.text.NumberFormat#INTEGER_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see java.text.NumberFormat#FRACTION_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see java.text.DateFormat#YEAR_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see java.text.DateFormat#MONTH_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public FieldPosition(int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.field = field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Creates a FieldPosition object for the given field constant. Fields are
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   116
     * identified by constants defined in the various {@code Format}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * subclasses. This is equivalent to calling
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   118
     * {@code new FieldPosition(attribute, -1)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param attribute Format.Field constant identifying a field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public FieldPosition(Format.Field attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this(attribute, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   128
     * Creates a {@code FieldPosition} object for the given field.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The field is identified by an attribute constant from one of the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   130
     * {@code Field} subclasses as well as an integer field ID
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   131
     * defined by the {@code Format} subclasses. {@code Format}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   132
     * subclasses that are aware of {@code Field} should give precedence
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   133
     * to {@code attribute} and ignore {@code fieldID} if
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   134
     * {@code attribute} is not null. However, older {@code Format}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   135
     * subclasses may not be aware of {@code Field} and rely on
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   136
     * {@code fieldID}. If the field has no corresponding integer
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   137
     * constant, {@code fieldID} should be -1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param attribute Format.Field constant identifying a field
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19054
diff changeset
   140
     * @param fieldID integer constant identifying a field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public FieldPosition(Format.Field attribute, int fieldID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.attribute = attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this.field = fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Returns the field identifier as an attribute constant
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   150
     * from one of the {@code Field} subclasses. May return null if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * the field is specified only by an integer field ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return Identifier for the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public Format.Field getFieldAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Retrieves the field identifier.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   162
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   163
     * @return the field identifier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public int getField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Retrieves the index of the first character in the requested field.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   171
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   172
     * @return the begin index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public int getBeginIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return beginIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Retrieves the index of the character following the last character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * requested field.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   181
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   182
     * @return the end index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public int getEndIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return endIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Sets the begin index.  For use by subclasses of Format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   190
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   191
     * @param bi the begin index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public void setBeginIndex(int bi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        beginIndex = bi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Sets the end index.  For use by subclasses of Format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   200
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   201
     * @param ei the end index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void setEndIndex(int ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        endIndex = ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   209
     * Returns a {@code Format.FieldDelegate} instance that is associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * with the FieldPosition. When the delegate is notified of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * field the FieldPosition is associated with, the begin/end will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * adjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    Format.FieldDelegate getFieldDelegate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return new Delegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Overrides equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (obj == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!(obj instanceof FieldPosition))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        FieldPosition other = (FieldPosition) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (attribute == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (other.attribute != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        else if (!attribute.equals(other.attribute)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return (beginIndex == other.beginIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            && endIndex == other.endIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            && field == other.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns a hash code for this FieldPosition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return a hash code value for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return (field << 24) | (beginIndex << 16) | endIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Return a string representation of this FieldPosition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return  a string representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            "[field=" + field + ",attribute=" + attribute +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            ",beginIndex=" + beginIndex +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            ",endIndex=" + endIndex + ']';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   261
     * Return true if the receiver wants a {@code Format.Field} value and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   262
     * {@code attribute} is equal to it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private boolean matchesField(Format.Field attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (this.attribute != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return this.attribute.equals(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   272
     * Return true if the receiver wants a {@code Format.Field} value and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   273
     * {@code attribute} is equal to it, or true if the receiver
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   274
     * represents an inteter constant and {@code field} equals it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private boolean matchesField(Format.Field attribute, int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (this.attribute != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return this.attribute.equals(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return (field == this.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * An implementation of FieldDelegate that will adjust the begin/end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * of the FieldPosition if the arguments match the field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * the FieldPosition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private class Delegate implements Format.FieldDelegate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * Indicates whether the field has been  encountered before. If this
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   292
         * is true, and {@code formatted} is invoked, the begin/end
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * are not updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        private boolean encounteredField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        public void formatted(Format.Field attr, Object value, int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                              int end, StringBuffer buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (!encounteredField && matchesField(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                setBeginIndex(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                setEndIndex(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                encounteredField = (start != end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        public void formatted(int fieldID, Format.Field attr, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                              int start, int end, StringBuffer buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (!encounteredField && matchesField(attr, fieldID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                setBeginIndex(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                setEndIndex(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                encounteredField = (start != end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}