Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/text/ParsePosition.java
38829 views
/*1* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved27* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved28*29* The original version of this source code and documentation is copyrighted30* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These31* materials are provided under terms of a License Agreement between Taligent32* and Sun. This technology is protected by multiple US and International33* patents. This notice and attribution to Taligent may not be removed.34* Taligent is a registered trademark of Taligent, Inc.35*36*/3738package java.text;394041/**42* <code>ParsePosition</code> is a simple class used by <code>Format</code>43* and its subclasses to keep track of the current position during parsing.44* The <code>parseObject</code> method in the various <code>Format</code>45* classes requires a <code>ParsePosition</code> object as an argument.46*47* <p>48* By design, as you parse through a string with different formats,49* you can use the same <code>ParsePosition</code>, since the index parameter50* records the current position.51*52* @author Mark Davis53* @see java.text.Format54*/5556public class ParsePosition {5758/**59* Input: the place you start parsing.60* <br>Output: position where the parse stopped.61* This is designed to be used serially,62* with each call setting index up for the next one.63*/64int index = 0;65int errorIndex = -1;6667/**68* Retrieve the current parse position. On input to a parse method, this69* is the index of the character at which parsing will begin; on output, it70* is the index of the character following the last character parsed.71*72* @return the current parse position73*/74public int getIndex() {75return index;76}7778/**79* Set the current parse position.80*81* @param index the current parse position82*/83public void setIndex(int index) {84this.index = index;85}8687/**88* Create a new ParsePosition with the given initial index.89*90* @param index initial index91*/92public ParsePosition(int index) {93this.index = index;94}95/**96* Set the index at which a parse error occurred. Formatters97* should set this before returning an error code from their98* parseObject method. The default value is -1 if this is not set.99*100* @param ei the index at which an error occurred101* @since 1.2102*/103public void setErrorIndex(int ei)104{105errorIndex = ei;106}107108/**109* Retrieve the index at which an error occurred, or -1 if the110* error index has not been set.111*112* @return the index at which an error occurred113* @since 1.2114*/115public int getErrorIndex()116{117return errorIndex;118}119120/**121* Overrides equals122*/123public boolean equals(Object obj)124{125if (obj == null) return false;126if (!(obj instanceof ParsePosition))127return false;128ParsePosition other = (ParsePosition) obj;129return (index == other.index && errorIndex == other.errorIndex);130}131132/**133* Returns a hash code for this ParsePosition.134* @return a hash code value for this object135*/136public int hashCode() {137return (errorIndex << 16) | index;138}139140/**141* Return a string representation of this ParsePosition.142* @return a string representation of this object143*/144public String toString() {145return getClass().getName() +146"[index=" + index +147",errorIndex=" + errorIndex + ']';148}149}150151152