Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / text / FieldPosition.java
blob6dd3a626705fd13ee9a1708a7834ad5bd45aae7a
1 /* FieldPosition.java -- Keeps track of field positions while formatting
2 Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package java.text;
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.
47 * @author Aaron M. Renn (arenn@urbanophile.com)
48 * @author Per Bothner (bothner@cygnus.com)
50 public class FieldPosition
52 /**
53 * This is the field identifier value.
55 private int field_id;
57 /**
58 * This is the beginning index of the field.
60 private int begin;
62 /**
63 * This is the ending index of the field.
65 private int end;
67 /**
68 * This is the field attribute value.
70 private Format.Field field_attribute;
72 /**
73 * This method initializes a new instance of <code>FieldPosition</code>
74 * to have the specified field attribute. The attribute will be used as
75 * an id. It is formally equivalent to calling FieldPosition(field, -1).
77 * @param field The field format attribute.
79 public FieldPosition (Format.Field field)
81 this(field, -1);
84 /**
85 * This method initializes a new instance of <code>FieldPosition</code>
86 * to have the specified field attribute. The attribute will be used as
87 * an id is non null. The integer field id is only used if the Format.Field
88 * attribute is not used by the formatter.
90 * @param field The field format attribute.
91 * @param field_id The field identifier value.
93 public FieldPosition (Format.Field field, int field_id)
95 this.field_attribute = field;
96 this.field_id = field_id;
99 /**
100 * This method initializes a new instance of <code>FieldPosition</code> to
101 * have the specified field id.
103 * @param field_id The field identifier value.
105 public FieldPosition (int field_id)
107 this.field_id = field_id;
111 * This method returns the field identifier value for this object.
113 * @return The field identifier.
115 public int getField ()
117 return field_id;
120 public Format.Field getFieldAttribute ()
122 return field_attribute;
126 * This method returns the beginning index for this field.
128 * @return The beginning index.
130 public int getBeginIndex ()
132 return begin;
136 * This method sets the beginning index of this field to the specified value.
138 * @param begin The new beginning index.
140 public void setBeginIndex (int begin)
142 this.begin = begin;
146 * This method returns the ending index for the field.
148 * @return The ending index.
150 public int getEndIndex ()
152 return end;
156 * This method sets the ending index of this field to the specified value.
158 * @param end The new ending index.
160 public void setEndIndex (int end)
162 this.end = end;
166 * This method tests this object for equality against the specified object.
167 * The objects will be considered equal if and only if:
168 * <p>
169 * <ul>
170 * <li>The specified object is not <code>null</code>.
171 * <li>The specified object has the same class as this object.
172 * <li>The specified object has the same field identifier, field attribute
173 * and beginning and ending index as this object.
174 * </ul>
176 * @param obj The object to test for equality to this object.
178 * @return <code>true</code> if the specified object is equal to
179 * this object, <code>false</code> otherwise.
181 public boolean equals (Object obj)
183 if (this == obj)
184 return true;
186 if (obj == null || obj.getClass() != this.getClass())
187 return false;
189 FieldPosition fp = (FieldPosition) obj;
190 return (field_id == fp.field_id
191 && (field_attribute == fp.field_attribute
192 || (field_attribute != null
193 && field_attribute.equals(fp.field_attribute)))
194 && begin == fp.begin
195 && end == fp.end);
200 * This method returns a hash value for this object
202 * @return A hash value for this object.
204 public int hashCode ()
206 int hash = 5;
208 hash = 31 * hash + field_id;
209 hash = 31 * hash + begin;
210 hash = 31 * hash + end;
211 hash = 31 * hash +
212 (null == field_attribute ? 0 : field_attribute.hashCode());
214 return hash;
218 * This method returns a <code>String</code> representation of this
219 * object.
221 * @return A <code>String</code> representation of this object.
223 public String toString ()
225 return (getClass ().getName ()
226 + "[field=" + getField ()
227 + ",attribute=" + getFieldAttribute ()
228 + ",beginIndex=" + getBeginIndex ()
229 + ",endIndex=" + getEndIndex ()
230 + "]");