Javolution 6.0.0 java
|
Public Member Functions | |
Cursor () | |
final int | getIndex () |
final void | setIndex (int i) |
final boolean | atEnd (CharSequence csq) |
final boolean | at (char c, CharSequence csq) |
final boolean | at (CharSet charSet, CharSequence csq) |
final boolean | at (String str, CharSequence csq) |
final char | currentChar (CharSequence csq) |
final char | nextChar (CharSequence csq) |
final boolean | skipAny (char c, CharSequence csq) |
final boolean | skipAny (CharSet charSet, CharSequence csq) |
final boolean | skip (char c, CharSequence csq) |
final boolean | skip (CharSet charSet, CharSequence csq) |
final boolean | skip (String str, CharSequence csq) |
final CharSequence | nextToken (CharSequence csq, char c) |
final CharSequence | nextToken (CharSequence csq, CharSet charSet) |
final CharSequence | head (CharSequence csq) |
final CharSequence | tail (CharSequence csq) |
final Cursor | increment () |
final Cursor | increment (int i) |
String | toString () |
boolean | equals (Object obj) |
int | hashCode () |
Private Attributes | |
int | index |
A parsing cursor over the characters read. Cursor allows for token iterations over any CharSequence. [code] String str = "this is a test"; Cursor cursor = new Cursor(); for (CharSequence token; (token=cursor.nextToken(str, ' '))!= null;) System.out.println(token); [/code] Prints the following output:
this is a test
Cursors are typically used with TextFormat instances. [code] // Parses decimal number (e.g. "xxx.xxxxxExx" or "NaN") public Decimal parse(CharSequence csq, Cursor cursor) throws IllegalArgumentException { TextFormat<LargeInteger> largeIntegerFormat = TextContext.getFormat(LargeInteger.class); if (cursor.skip("NaN", csq)) return Decimal.NaN; LargeInteger significand = LargeIntegerFormat.parse(csq, cursor); LargeInteger fraction = cursor.skip('.', csq) ? largeIntegerFormat.parse(csq, cursor) : LargeInteger.ZERO; int exponent = cursor.skip(CharSet.valueOf('E', 'e'), csq) ? TypeFormat.parseInt(csq, cursor) : 0; int fractionDigits = fraction.digitLength(); return Decimal.valueOf(significand.E(fractionDigits).plus(fraction), exponent - fractionDigits); } [/code]
Definition at line 44 of file Cursor.java.
javolution.text.Cursor.Cursor | ( | ) |
Default constructor.
Definition at line 54 of file Cursor.java.
Referenced by javolution.text.Cursor.equals().
final boolean javolution.text.Cursor.at | ( | char | c, |
CharSequence | csq | ||
) |
Indicates if this cursor points to the specified character in the specified character sequence.
c | the character to test. |
csq | the character sequence iterated by this cursor. |
csq.charAt(this.getIndex()) == c
Definition at line 93 of file Cursor.java.
References javolution.text.Cursor.index.
Referenced by javolution.text.Cursor.skip().
final boolean javolution.text.Cursor.at | ( | CharSet | charSet, |
CharSequence | csq | ||
) |
Indicates if this cursor points to any of the specified character in the specified character sequence.
charSet | any of the character to test. |
csq | the character sequence iterated by this cursor. |
csq.charAt(this.getIndex()) == c
Definition at line 105 of file Cursor.java.
References javolution.text.CharSet.contains(), and javolution.text.Cursor.index.
final boolean javolution.text.Cursor.at | ( | String | str, |
CharSequence | csq | ||
) |
Indicates if this cursor points to the specified characters in the specified sequence.
str | the characters to test. |
csq | the character sequence iterated by this cursor. |
true
if this cursor points to the specified characters; false
otherwise. Definition at line 119 of file Cursor.java.
References javolution.text.Cursor.index.
final boolean javolution.text.Cursor.atEnd | ( | CharSequence | csq | ) |
Indicates if this cursor points to the end of the specified character sequence.
csq | the character sequence iterated by this cursor. |
getIndex() >= csq.length()
Definition at line 81 of file Cursor.java.
References javolution.text.Cursor.index.
Referenced by javolution.text.TextFormat< FastCollection<?> >.parse(), javolution.text.TypeFormat.parseBoolean(), javolution.text.TypeFormat.parseByte(), javolution.text.TypeFormat.parseDouble(), javolution.text.TypeFormat.parseInt(), javolution.text.TypeFormat.parseLong(), and javolution.text.TypeFormat.parseShort().
final char javolution.text.Cursor.currentChar | ( | CharSequence | csq | ) |
Returns the current character at this cursor position.
csq | the character sequence iterated by this cursor. |
IndexOutOfBoundsException | if this.atEnd(csq) |
Definition at line 136 of file Cursor.java.
References javolution.text.Cursor.index.
boolean javolution.text.Cursor.equals | ( | Object | obj | ) |
Indicates if this cursor is equals to the specified object.
true
if the specified object is a cursor at the same index; false
otherwise. Definition at line 380 of file Cursor.java.
References javolution.text.Cursor.Cursor(), and javolution.text.Cursor.index.
final int javolution.text.Cursor.getIndex | ( | ) |
Returns this cursor index.
Definition at line 61 of file Cursor.java.
References javolution.text.Cursor.index.
Referenced by javolution.text.TypeFormat.parseBoolean(), javolution.text.TypeFormat.parseInt(), and javolution.text.TypeFormat.parseLong().
int javolution.text.Cursor.hashCode | ( | ) |
Returns the hash code for this cursor.
Definition at line 394 of file Cursor.java.
References javolution.text.Cursor.index.
final CharSequence javolution.text.Cursor.head | ( | CharSequence | csq | ) |
Returns the head of the specified character sequence until
this cursor position.
Definition at line 329 of file Cursor.java.
References javolution.text.Cursor.index.
final Cursor javolution.text.Cursor.increment | ( | ) |
Increments the cursor index by one.
this
Definition at line 348 of file Cursor.java.
Referenced by javolution.text.TypeFormat.parseBoolean(), javolution.text.TypeFormat.parseInt(), and javolution.text.TypeFormat.parseLong().
final Cursor javolution.text.Cursor.increment | ( | int | i | ) |
Increments the cursor index by the specified value.
i | the increment value. |
this
Definition at line 358 of file Cursor.java.
References javolution.text.Cursor.index.
final char javolution.text.Cursor.nextChar | ( | CharSequence | csq | ) |
Returns the next character at this cursor position.The cursor position is incremented by one.
csq | the character sequence iterated by this cursor. |
IndexOutOfBoundsException | if this.atEnd(csq) |
Definition at line 148 of file Cursor.java.
References javolution.text.Cursor.index.
final CharSequence javolution.text.Cursor.nextToken | ( | CharSequence | csq, |
char | c | ||
) |
Returns the subsequence from the specified cursor position not holding the specified character. For example:[code] CharSequence csq = "This is a test"; for (CharSequence token; (token=cursor.nextToken(csq, ' '))!= null;) { System.out.println(token); // Prints one word at a time. }[/code]
csq | the character sequence iterated by this cursor. |
c | the character being skipped. |
null
if none. Definition at line 278 of file Cursor.java.
References javolution.text.Cursor.index.
final CharSequence javolution.text.Cursor.nextToken | ( | CharSequence | csq, |
CharSet | charSet | ||
) |
Returns the subsequence from the specified cursor position not holding any of the characters specified. For example:[code] CharSequence csq = "This is a test"; for (CharSequence token; (token=cursor.nextToken(csq, CharSet.WHITESPACE))!= null;) { System.out.println(token); // Prints one word at a time. }[/code]
csq | the character sequence iterated by this cursor. |
charSet | the characters being skipped. |
null
if none. Definition at line 307 of file Cursor.java.
References javolution.text.CharSet.contains(), and javolution.text.Cursor.index.
final void javolution.text.Cursor.setIndex | ( | int | i | ) |
Sets the cursor current index.
i | the index of the next character to parse. |
Definition at line 70 of file Cursor.java.
References javolution.text.Cursor.index.
final boolean javolution.text.Cursor.skip | ( | char | c, |
CharSequence | csq | ||
) |
Moves this cursor forward only if at the specified character. This method is equivalent to: [code] if (at(c, csq)) increment(); [/code]
c | the character to skip. |
csq | the character sequence iterated by this cursor. |
true
if this cursor has skipped the specified character;false
otherwise. Definition at line 211 of file Cursor.java.
References javolution.text.Cursor.at(), and javolution.text.Cursor.index.
final boolean javolution.text.Cursor.skip | ( | CharSet | charSet, |
CharSequence | csq | ||
) |
Moves this cursor forward only if at any of the specified character. This method is equivalent to: [code] if (at(charSet, csq)) increment(); [/code]
charSet | holding the characters to skip. |
csq | the character sequence iterated by this cursor. |
true
if this cursor has skipped any the specified character;false
otherwise. Definition at line 233 of file Cursor.java.
References javolution.text.Cursor.at(), and javolution.text.Cursor.index.
final boolean javolution.text.Cursor.skip | ( | String | str, |
CharSequence | csq | ||
) |
Moves this cursor forward only if at the specified string. This method is equivalent to: [code] if (at(str, csq)) increment(str.length()); [/code]
str | the string to skip. |
csq | the character sequence iterated by this cursor. |
true
if this cursor has skipped the specified string;false
otherwise (e.g. end of sequence reached). Definition at line 256 of file Cursor.java.
References javolution.text.Cursor.at(), and javolution.text.Cursor.index.
final boolean javolution.text.Cursor.skipAny | ( | char | c, |
CharSequence | csq | ||
) |
Moves this cursor forward until it points to a character different from the specified character.
c | the character to skip. |
csq | the character sequence iterated by this cursor. |
true
if this cursor has skipped at least one character;false
otherwise (e.g. end of sequence reached). Definition at line 162 of file Cursor.java.
References javolution.text.Cursor.index.
final boolean javolution.text.Cursor.skipAny | ( | CharSet | charSet, |
CharSequence | csq | ||
) |
Moves this cursor forward until it points to a character different from any of the character in the specified set. For example: [code] // Reads numbers separated by tabulations or spaces. FastTable<Integer> numbers = new FastTable<Integer>(); while (cursor.skipAny(CharSet.SPACE_OR_TAB, csq)) { numbers.add(TypeFormat.parseInt(csq, cursor)); }[/code]
charSet | the character to skip. |
csq | the character sequence iterated by this cursor. |
true
if this cursor has skipped at least one character;false
otherwise (e.g. end of sequence reached). Definition at line 188 of file Cursor.java.
References javolution.text.CharSet.contains(), and javolution.text.Cursor.index.
final CharSequence javolution.text.Cursor.tail | ( | CharSequence | csq | ) |
Returns the tail of the specified character sequence starting at this cursor position.
Definition at line 339 of file Cursor.java.
References javolution.text.Cursor.index.
Referenced by javolution.text.TextFormat< FastCollection<?> >.parse(), javolution.text.TypeFormat.parseBoolean(), javolution.text.TypeFormat.parseByte(), javolution.text.TypeFormat.parseDouble(), javolution.text.TypeFormat.parseInt(), javolution.text.TypeFormat.parseLong(), and javolution.text.TypeFormat.parseShort().
String javolution.text.Cursor.toString | ( | ) |
Returns the string representation of this cursor.
Definition at line 369 of file Cursor.java.
References javolution.text.Cursor.index.
|
private |
Holds the index.
Definition at line 49 of file Cursor.java.
Referenced by javolution.text.Cursor.at(), javolution.text.Cursor.atEnd(), javolution.text.Cursor.currentChar(), javolution.text.Cursor.equals(), javolution.text.Cursor.getIndex(), javolution.text.Cursor.hashCode(), javolution.text.Cursor.head(), javolution.text.Cursor.increment(), javolution.text.Cursor.nextChar(), javolution.text.Cursor.nextToken(), javolution.text.Cursor.setIndex(), javolution.text.Cursor.skip(), javolution.text.Cursor.skipAny(), javolution.text.Cursor.tail(), and javolution.text.Cursor.toString().