| 1 | /* FieldPosition.java -- Keeps track of field positions while formatting
|
|---|
| 2 | Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.text;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * This class is used by the java.text formatting classes to track
|
|---|
| 43 | * field positions. A field position is defined by an identifier value
|
|---|
| 44 | * and begin and end index positions. The formatting classes in java.text
|
|---|
| 45 | * typically define constant values for the field identifiers.
|
|---|
| 46 | *
|
|---|
| 47 | * @author Aaron M. Renn ([email protected])
|
|---|
| 48 | * @author Per Bothner <[email protected]>
|
|---|
| 49 | */
|
|---|
| 50 | public class FieldPosition
|
|---|
| 51 | {
|
|---|
| 52 | /**
|
|---|
| 53 | * This is the field identifier value.
|
|---|
| 54 | */
|
|---|
| 55 | private int field_id;
|
|---|
| 56 |
|
|---|
| 57 | /**
|
|---|
| 58 | * This is the beginning index of the field.
|
|---|
| 59 | */
|
|---|
| 60 | private int begin;
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * This is the ending index of the field.
|
|---|
| 64 | */
|
|---|
| 65 | private int end;
|
|---|
| 66 |
|
|---|
| 67 | /**
|
|---|
| 68 | * This method initializes a new instance of <code>FieldPosition</code> to
|
|---|
| 69 | * have the specified field id.
|
|---|
| 70 | *
|
|---|
| 71 | * @param field_id The field identifier value.
|
|---|
| 72 | */
|
|---|
| 73 | public FieldPosition (int field_id)
|
|---|
| 74 | {
|
|---|
| 75 | this.field_id = field_id;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /**
|
|---|
| 79 | * This method returns the field identifier value for this object.
|
|---|
| 80 | *
|
|---|
| 81 | * @return The field identifier.
|
|---|
| 82 | */
|
|---|
| 83 | public int getField ()
|
|---|
| 84 | {
|
|---|
| 85 | return field_id;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /**
|
|---|
| 89 | * This method returns the beginning index for this field.
|
|---|
| 90 | *
|
|---|
| 91 | * @return The beginning index.
|
|---|
| 92 | */
|
|---|
| 93 | public int getBeginIndex ()
|
|---|
| 94 | {
|
|---|
| 95 | return begin;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * This method sets the beginning index of this field to the specified value.
|
|---|
| 100 | *
|
|---|
| 101 | * @param begin The new beginning index.
|
|---|
| 102 | */
|
|---|
| 103 | public void setBeginIndex (int begin)
|
|---|
| 104 | {
|
|---|
| 105 | this.begin = begin;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | /**
|
|---|
| 109 | * This method returns the ending index for the field.
|
|---|
| 110 | *
|
|---|
| 111 | * @return The ending index.
|
|---|
| 112 | */
|
|---|
| 113 | public int getEndIndex ()
|
|---|
| 114 | {
|
|---|
| 115 | return end;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * This method sets the ending index of this field to the specified value.
|
|---|
| 120 | *
|
|---|
| 121 | * @param end The new ending index.
|
|---|
| 122 | */
|
|---|
| 123 | public void setEndIndex (int end)
|
|---|
| 124 | {
|
|---|
| 125 | this.end = end;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * This method tests this object for equality against the specified object.
|
|---|
| 130 | * The objects will be considered equal if and only if:
|
|---|
| 131 | * <p>
|
|---|
| 132 | * <ul>
|
|---|
| 133 | * <li>The specified object is not <code>null</code>.
|
|---|
| 134 | * <li>The specified object is an instance of <code>FieldPosition</code>.
|
|---|
| 135 | * <li>The specified object has the same field identifier and beginning
|
|---|
| 136 | * and ending index as this object.
|
|---|
| 137 | * </ul>
|
|---|
| 138 | *
|
|---|
| 139 | * @param obj The object to test for equality to this object.
|
|---|
| 140 | *
|
|---|
| 141 | * @return <code>true</code> if the specified object is equal to
|
|---|
| 142 | * this object, <code>false</code> otherwise.
|
|---|
| 143 | */
|
|---|
| 144 | public boolean equals (Object obj)
|
|---|
| 145 | {
|
|---|
| 146 | if (! (obj instanceof FieldPosition))
|
|---|
| 147 | return false;
|
|---|
| 148 |
|
|---|
| 149 | FieldPosition fp = (FieldPosition) obj;
|
|---|
| 150 | return (field_id == fp.field_id
|
|---|
| 151 | && begin == fp.begin
|
|---|
| 152 | && end == fp.end);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | /**
|
|---|
| 156 | * This method returns a <code>String</code> representation of this
|
|---|
| 157 | * object.
|
|---|
| 158 | *
|
|---|
| 159 | * @return A <code>String</code> representation of this object.
|
|---|
| 160 | */
|
|---|
| 161 | public String toString ()
|
|---|
| 162 | {
|
|---|
| 163 | return (getClass ().getName () + "[field=" + getField () + ",beginIndex="
|
|---|
| 164 | + getBeginIndex () + ",endIndex=" + getEndIndex () + "]");
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|