ParsePosition.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* ParsePosition.java -- Keep track of position while parsing.
  2. Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.text;
  32. /**
  33. * This class is used to keep track of the current position during parsing
  34. * operations.
  35. *
  36. * @author Aaron M. Renn (arenn@urbanophile.com)
  37. * @author Per Bothner (bothner@cygnus.com)
  38. */
  39. public class ParsePosition
  40. {
  41. /**
  42. * This is the index of the current parse position.
  43. */
  44. private int index;
  45. /**
  46. * This is the index of the position where an error occurred during parsing.
  47. */
  48. private int error_index;
  49. /**
  50. * This method initializes a new instance of <code>ParsePosition</code> to
  51. * have the specified initial index value.
  52. *
  53. * @param index The initial parsing index.
  54. */
  55. public ParsePosition (int index)
  56. {
  57. this.index = index;
  58. error_index = -1;
  59. }
  60. /**
  61. * This method returns the current parsing index.
  62. *
  63. * @return The current parsing index
  64. */
  65. public int getIndex ()
  66. {
  67. return index;
  68. }
  69. /**
  70. * This method sets the current parsing index to the specified value.
  71. *
  72. * @param index The new parsing index.
  73. */
  74. public void setIndex (int index)
  75. {
  76. this.index = index;
  77. }
  78. /**
  79. * This method returns the error index value. This value defaults to -1
  80. * unless explicitly set to another value.
  81. *
  82. * @return The error index.
  83. */
  84. public int getErrorIndex ()
  85. {
  86. return error_index;
  87. }
  88. /**
  89. * This method sets the error index to the specified value.
  90. *
  91. * @param error_index The new error index
  92. */
  93. public void setErrorIndex (int error_index)
  94. {
  95. this.error_index = error_index;
  96. }
  97. /**
  98. * This method tests the specified object for equality with this
  99. * object. The two objects will be considered equal if and only if
  100. * all of the following conditions are met.
  101. * <p>
  102. * <ul>
  103. * <li>The specified object is not <code>null</code>.</li>
  104. * <li>The specified object is an instance of <code>ParsePosition</code>.</li>
  105. * <li>The specified object has the same index and error index as
  106. * this object.</li>
  107. * </ul>
  108. *
  109. * @param obj The <code>Object</code> to test for equality against
  110. * this object.
  111. *
  112. * @return <code>true</code> if the specified object is equal to
  113. * this object, <code>false</code> otherwise.
  114. */
  115. public boolean equals (Object obj)
  116. {
  117. if (! (obj instanceof ParsePosition))
  118. return false;
  119. ParsePosition other = (ParsePosition) obj;
  120. return index == other.index && error_index == other.error_index;
  121. }
  122. /**
  123. * Return the hash code for this object.
  124. * @return the hash code
  125. */
  126. public int hashCode()
  127. {
  128. return index ^ error_index;
  129. }
  130. /**
  131. * This method returns a <code>String</code> representation of this
  132. * object.
  133. *
  134. * @return A <code>String</code> that represents this object.
  135. */
  136. public String toString ()
  137. {
  138. return (getClass ().getName () + "[index=" + getIndex ()
  139. + ",errorIndex=" + getErrorIndex () + "]");
  140. }
  141. }