J avolution v5.2 (J2SE 1.5+)

javolution.text
Class TextFormat.Cursor

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

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

This class represents a parsing cursor over a character sequence (or subsequence). A cursor location may start and end at any predefined location within the character sequence iterated over (equivalent to parsing a subsequence of the character sequence input).


Method Summary
 boolean at(char c, java.lang.CharSequence csq)
          Indicates if this cursor points to the specified character in the specified character sequence.
 boolean at(CharSet charSet, java.lang.CharSequence csq)
          Indicates if this cursor points to one of the specified character.
 boolean at(java.lang.String pattern, java.lang.CharSequence csq)
          Indicates if this cursor points to the specified characters in the specified character sequence.
 boolean equals(java.lang.Object obj)
          Indicates if this cursor is equals to the specified object.
 int getEndIndex()
          Returns this cursor end index.
 int getErrorIndex()
          Returns the error index of this cursor if set; otherwise returns the current index.
 int getIndex()
          Returns this cursor index.
 int getStartIndex()
          Returns this cursor start index.
 int hashCode()
          Returns the hash code for this cursor.
 boolean hasNext()
          Indicates if this cursor has not reached the end index.
 TextFormat.Cursor increment()
          Increments the cursor index by one.
 TextFormat.Cursor increment(int i)
          Increments the cursor index by the specified value.
static TextFormat.Cursor newInstance(int start, int end)
          Returns a new, preallocated or recycled cursor instance (on the stack when executing in a StackContext).
 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.
static void recycle(TextFormat.Cursor instance)
          Recycles a cursor instance immediately (on the stack when executing in a StackContext).
 void setEndIndex(int end)
          Sets this cursor end index.
 void setErrorIndex(int errorIndex)
          Sets this cursor error index.
 void setIndex(int i)
          Sets the cursor current index.
 void setStartIndex(int start)
          Sets this cursor start 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.
 java.lang.String toString()
          Returns the string representation of this cursor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

newInstance

public static TextFormat.Cursor newInstance(int start,
                                            int end)
Returns a new, preallocated or recycled cursor instance (on the stack when executing in a StackContext).

Parameters:
start - the start index.
end - the end index (index after the last character to be read).
Returns:
a new or recycled cursor instance.

recycle

public static void recycle(TextFormat.Cursor instance)
Recycles a cursor instance immediately (on the stack when executing in a StackContext).

Parameters:
instance - the cursor instance being recycled.

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.

getStartIndex

public final int getStartIndex()
Returns this cursor start index.

Returns:
the start index.

getEndIndex

public final int getEndIndex()
Returns this cursor end index.

Returns:
the end index.

getErrorIndex

public final int getErrorIndex()
Returns the error index of this cursor if set; otherwise returns the current index.

Overrides:
getErrorIndex in class java.text.ParsePosition
Returns:
the error index.

setIndex

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

Overrides:
setIndex in class java.text.ParsePosition
Parameters:
i - the index of the next character to parse.
Throws:
java.lang.IllegalArgumentException - if ((i < getStartIndex()) || (i > getEndIndex()))

setStartIndex

public final void setStartIndex(int start)
Sets this cursor start index.

Parameters:
start - the start index.

setEndIndex

public final void setEndIndex(int end)
Sets this cursor end index.

Parameters:
end - the end index.

setErrorIndex

public final void setErrorIndex(int errorIndex)
Sets this cursor error index.

Overrides:
setErrorIndex in class java.text.ParsePosition
Parameters:
errorIndex - the error index.

hasNext

public final boolean hasNext()
Indicates if this cursor has not reached the end index.

Returns:
this.getIndex() < this.getEndIndex()

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. For example:
    for (char c=cursor.next(csq); c != 0; c = cursor.next(csq)) {
        ...
    }
    }

Parameters:
csq - the character sequence iterated by this cursor.
Returns:
the character at the current cursor position in the specified character sequence or '\u0000' if the end index has already been reached.

at

public final boolean at(char c,
                        java.lang.CharSequence csq)
Indicates if this cursor points to the specified character in the specified character sequence.

Parameters:
c - the character.
csq - the character sequence iterated by this cursor.
Returns:
true if the cursor next character is the one specified; false otherwise.

at

public final boolean at(CharSet charSet,
                        java.lang.CharSequence csq)
Indicates if this cursor points to one of the specified character.

Parameters:
charSet - the character set
csq - the character sequence iterated by this cursor.
Returns:
true if the cursor next character is one of the character contained by the character set; false otherwise.

at

public final boolean at(java.lang.String pattern,
                        java.lang.CharSequence csq)
Indicates if this cursor points to the specified characters in the specified character sequence.

Parameters:
pattern - the characters searched for.
csq - the character sequence iterated by this cursor.
Returns:
true if the cursor next character are the one specified in the pattern; false otherwise.

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 TextFormat.Cursor increment()
Increments the cursor index by one.

Returns:
this

increment

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

Parameters:
i - the increment value.
Returns:
this

toString

public java.lang.String toString()
Returns the string representation of this cursor.

Overrides:
toString in class java.text.ParsePosition
Returns:
the index value as a string.

equals

public boolean equals(java.lang.Object obj)
Indicates if this cursor is equals to the specified object.

Overrides:
equals in class java.text.ParsePosition
Returns:
true if the specified object is a cursor at the same index; false otherwise.

hashCode

public int hashCode()
Returns the hash code for this cursor.

Overrides:
hashCode in class java.text.ParsePosition
Returns:
the hash code value for this object

J avolution v5.2 (J2SE 1.5+)

Copyright © 2005 - 2007 Javolution.