ParsePosition
Stay organized with collections
Save and categorize content based on your preferences.
ParsePosition
is a simple class used by Format
and its subclasses to keep track of the current position during parsing.
The parseObject
method in the various Format
classes requires a ParsePosition
object as an argument.
By design, as you parse through a string with different formats,
you can use the same ParsePosition
, since the index parameter
records the current position.
Public Constructor Summary
|
ParsePosition(int index)
Create a new ParsePosition with the given initial index.
|
Public Method Summary
boolean
|
|
int
|
getErrorIndex()
Retrieve the index at which an error occurred, or -1 if the
error index has not been set.
|
int
|
getIndex()
Retrieve the current parse position.
|
int
|
hashCode()
Returns a hash code for this ParsePosition.
|
void
|
setErrorIndex(int ei)
Set the index at which a parse error occurred.
|
void
|
setIndex(int index)
Set the current parse position.
|
String
|
toString()
Return a string representation of this ParsePosition.
|
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Public Constructors
public
ParsePosition
(int index)
Create a new ParsePosition with the given initial index.
Public Methods
public
boolean
equals
(Object obj)
Parameters
obj |
the object to compare this instance with. |
Returns
true
if the specified object is equal to this Object
; false
otherwise.
public
int
getErrorIndex
()
Retrieve the index at which an error occurred, or -1 if the
error index has not been set.
Returns
- the index at which an error occurred
public
int
getIndex
()
Retrieve the current parse position. On input to a parse method, this
is the index of the character at which parsing will begin; on output, it
is the index of the character following the last character parsed.
Returns
- the current parse position
public
int
hashCode
()
Returns a hash code for this ParsePosition.
Returns
- a hash code value for this object
public
void
setErrorIndex
(int ei)
Set the index at which a parse error occurred. Formatters
should set this before returning an error code from their
parseObject method. The default value is -1 if this is not set.
Parameters
ei |
the index at which an error occurred |
public
void
setIndex
(int index)
Set the current parse position.
Parameters
index |
the current parse position
|
public
String
toString
()
Return a string representation of this ParsePosition.
Returns
- a string representation of this object
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eParsePosition\u003c/code\u003e is a class used by \u003ccode\u003eFormat\u003c/code\u003e and its subclasses to track the current position during parsing.\u003c/p\u003e\n"],["\u003cp\u003eIt maintains an index to mark the parsing progress within a string.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eParsePosition\u003c/code\u003e includes methods to set and retrieve the current parsing position and the error index.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eFormat\u003c/code\u003e classes use \u003ccode\u003eParsePosition\u003c/code\u003e as an argument in their \u003ccode\u003eparseObject\u003c/code\u003e method for efficient parsing.\u003c/p\u003e\n"],["\u003cp\u003eThe same \u003ccode\u003eParsePosition\u003c/code\u003e instance can be used across multiple formats due to its index-based tracking.\u003c/p\u003e\n"]]],[],null,["public class **ParsePosition** extends [Object](../../../reference/java/lang/Object.html) \n`ParsePosition` is a simple class used by `Format`\nand its subclasses to keep track of the current position during parsing.\nThe `parseObject` method in the various `Format`\nclasses requires a `ParsePosition` object as an argument.\n\n\nBy design, as you parse through a string with different formats,\nyou can use the same `ParsePosition`, since the index parameter\nrecords the current position. \n\nSee Also\n\n- [Format](../../../reference/java/text/Format.html) \n\nPublic Constructor Summary\n\n|---|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [ParsePosition](../../../reference/java/text/ParsePosition.html#ParsePosition(int))(int index) Create a new ParsePosition with the given initial index. |\n\nPublic Method Summary\n\n|----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| boolean | [equals](../../../reference/java/text/ParsePosition.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Overrides equals |\n| int | [getErrorIndex](../../../reference/java/text/ParsePosition.html#getErrorIndex())() Retrieve the index at which an error occurred, or -1 if the error index has not been set. |\n| int | [getIndex](../../../reference/java/text/ParsePosition.html#getIndex())() Retrieve the current parse position. |\n| int | [hashCode](../../../reference/java/text/ParsePosition.html#hashCode())() Returns a hash code for this ParsePosition. |\n| void | [setErrorIndex](../../../reference/java/text/ParsePosition.html#setErrorIndex(int))(int ei) Set the index at which a parse error occurred. |\n| void | [setIndex](../../../reference/java/text/ParsePosition.html#setIndex(int))(int index) Set the current parse position. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/text/ParsePosition.html#toString())() Return a string representation of this ParsePosition. |\n\nInherited Method Summary \nFrom class [java.lang.Object](../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../reference/java/lang/Object.html) | [clone](../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nPublic Constructors \n\npublic\n**ParsePosition**\n(int index) \nCreate a new ParsePosition with the given initial index. \n\nParameters\n\n| index | initial index |\n|-------|---------------|\n\nPublic Methods \n\npublic boolean\n**equals**\n([Object](../../../reference/java/lang/Object.html) obj) \nOverrides equals \n\nParameters\n\n| obj | the object to compare this instance with. |\n|-----|-------------------------------------------|\n\nReturns\n\n- `true` if the specified object is equal to this `Object`; `false` otherwise. \n\npublic int\n**getErrorIndex**\n() \nRetrieve the index at which an error occurred, or -1 if the\nerror index has not been set. \n\nReturns\n\n- the index at which an error occurred \n\npublic int\n**getIndex**\n() \nRetrieve the current parse position. On input to a parse method, this\nis the index of the character at which parsing will begin; on output, it\nis the index of the character following the last character parsed. \n\nReturns\n\n- the current parse position \n\npublic int\n**hashCode**\n() \nReturns a hash code for this ParsePosition. \n\nReturns\n\n- a hash code value for this object \n\npublic void\n**setErrorIndex**\n(int ei) \nSet the index at which a parse error occurred. Formatters\nshould set this before returning an error code from their\nparseObject method. The default value is -1 if this is not set. \n\nParameters\n\n| ei | the index at which an error occurred |\n|----|--------------------------------------|\n\npublic void\n**setIndex**\n(int index) \nSet the current parse position. \n\nParameters\n\n| index | the current parse position |\n|-------|----------------------------|\n\npublic [String](../../../reference/java/lang/String.html)\n**toString**\n() \nReturn a string representation of this ParsePosition. \n\nReturns\n\n- a string representation of this object"]]