0N/A/*
2362N/A * Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation is copyrighted
0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
0N/A * materials are provided under terms of a License Agreement between Taligent
0N/A * and Sun. This technology is protected by multiple US and International
0N/A * patents. This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.text;
0N/A
0N/A
0N/A/**
0N/A * <code>ParsePosition</code> is a simple class used by <code>Format</code>
0N/A * and its subclasses to keep track of the current position during parsing.
0N/A * The <code>parseObject</code> method in the various <code>Format</code>
0N/A * classes requires a <code>ParsePosition</code> object as an argument.
0N/A *
0N/A * <p>
0N/A * By design, as you parse through a string with different formats,
0N/A * you can use the same <code>ParsePosition</code>, since the index parameter
0N/A * records the current position.
0N/A *
0N/A * @author Mark Davis
0N/A * @see java.text.Format
0N/A */
0N/A
0N/Apublic class ParsePosition {
0N/A
0N/A /**
0N/A * Input: the place you start parsing.
0N/A * <br>Output: position where the parse stopped.
0N/A * This is designed to be used serially,
0N/A * with each call setting index up for the next one.
0N/A */
0N/A int index = 0;
0N/A int errorIndex = -1;
0N/A
0N/A /**
0N/A * Retrieve the current parse position. On input to a parse method, this
0N/A * is the index of the character at which parsing will begin; on output, it
0N/A * is the index of the character following the last character parsed.
0N/A */
0N/A public int getIndex() {
0N/A return index;
0N/A }
0N/A
0N/A /**
0N/A * Set the current parse position.
0N/A */
0N/A public void setIndex(int index) {
0N/A this.index = index;
0N/A }
0N/A
0N/A /**
0N/A * Create a new ParsePosition with the given initial index.
0N/A */
0N/A public ParsePosition(int index) {
0N/A this.index = index;
0N/A }
0N/A /**
0N/A * Set the index at which a parse error occurred. Formatters
0N/A * should set this before returning an error code from their
0N/A * parseObject method. The default value is -1 if this is not set.
0N/A * @since 1.2
0N/A */
0N/A public void setErrorIndex(int ei)
0N/A {
0N/A errorIndex = ei;
0N/A }
0N/A
0N/A /**
0N/A * Retrieve the index at which an error occurred, or -1 if the
0N/A * error index has not been set.
0N/A * @since 1.2
0N/A */
0N/A public int getErrorIndex()
0N/A {
0N/A return errorIndex;
0N/A }
0N/A /**
0N/A * Overrides equals
0N/A */
0N/A public boolean equals(Object obj)
0N/A {
0N/A if (obj == null) return false;
0N/A if (!(obj instanceof ParsePosition))
0N/A return false;
0N/A ParsePosition other = (ParsePosition) obj;
0N/A return (index == other.index && errorIndex == other.errorIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns a hash code for this ParsePosition.
0N/A * @return a hash code value for this object
0N/A */
0N/A public int hashCode() {
0N/A return (errorIndex << 16) | index;
0N/A }
0N/A
0N/A /**
0N/A * Return a string representation of this ParsePosition.
0N/A * @return a string representation of this object
0N/A */
0N/A public String toString() {
0N/A return getClass().getName() +
0N/A "[index=" + index +
0N/A ",errorIndex=" + errorIndex + ']';
0N/A }
0N/A}