J avolution v3.7 (J2SE 1.5+)

javolution.lang
Class TextFormat.Cursor

java.lang.Object
  extended by java.text.ParsePosition
      extended by javolution.lang.TextFormat.Cursor
Enclosing class:
TextFormat<T>

public static class TextFormat.Cursor
extends java.text.ParsePosition

This class represents a parsing cursor.


Method Summary
 int getIndex()
          Returns this cursor index.
 boolean hasNext(java.lang.CharSequence csq)
          Indicates if this cursor has not yet reached the end of the specified character sequence.
 void increment()
          Increments the cursor index by one.
 void increment(int i)
          Increments the cursor index by the specified value.
static TextFormat.Cursor newInstance()
          Returns a new cursor instance (possibly recycled).
 char next(java.lang.CharSequence csq)
          Returns the next character at the cursor position in the specified character sequence and increments the cursor position by one.
 void recycle()
          Recycles this cursor for reuse.
 void setIndex(int i)
          Sets the cursor index.
 boolean skip(char c, java.lang.CharSequence csq)
          Moves this cursor forward until it points to a character different from the character specified.
 boolean skip(CharSet charSet, java.lang.CharSequence csq)
          Moves this cursor forward until it points to a character different from any of the character in the specified set.
 
Methods inherited from class java.text.ParsePosition
equals, getErrorIndex, hashCode, setErrorIndex, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

newInstance

public static TextFormat.Cursor newInstance()
Returns a new cursor instance (possibly recycled).

Returns:
a cursor instance whose index is 0.

getIndex

public final int getIndex()
Returns this cursor index.

Overrides:
getIndex in class java.text.ParsePosition
Returns:
the index of the next character to parse.

setIndex

public final void setIndex(int i)
Sets the cursor index.

Overrides:
setIndex in class java.text.ParsePosition
Parameters:
i - the index of the next character to parse.

hasNext

public final boolean hasNext(java.lang.CharSequence csq)
Indicates if this cursor has not yet reached the end of the specified character sequence.

Parameters:
csq - the character sequence iterated by this cursor.
Returns:
this.getIndex() < csq.length()

next

public final char next(java.lang.CharSequence csq)
Returns the next character at the cursor position in the specified character sequence and increments the cursor position by one.

Parameters:
csq - the character sequence iterated by this cursor.
Returns:
the character at the cursor position.
Throws:
java.lang.IndexOutOfBoundsException - if (this.getIndex() < 0) || (this.getIndex(() >= csq.length())

skip

public final boolean skip(char c,
                          java.lang.CharSequence csq)
Moves this cursor forward until it points to a character different from the character specified.

Parameters:
c - the character to skip.
csq - the character sequence iterated by this cursor.
Returns:
true if this cursor points to a character different from the ones specified; false otherwise (e.g. end of sequence reached).

skip

public final boolean skip(CharSet charSet,
                          java.lang.CharSequence csq)
Moves this cursor forward until it points to a character different from any of the character in the specified set. For example:
  // Reads numbers separated by tabulations or spaces.
  FastTable<Integer> numbers = new FastTable<Integer>();
  while (cursor.skip(CharSet.SPACE_OR_TAB, csq)) {
      numbers.add(TypeFormat.parseInt(csq, cursor));
  }

Parameters:
charSet - the character to skip.
csq - the character sequence iterated by this cursor.
Returns:
true if this cursor points to a character different from the ones specified; false otherwise (e.g. end of sequence reached).

increment

public final void increment()
Increments the cursor index by one.


increment

public final void increment(int i)
Increments the cursor index by the specified value.

Parameters:
i - the increment value.

recycle

public final void recycle()
Recycles this cursor for reuse.


J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.