Created
January 24, 2013 07:17
-
-
Save zerosign/4618278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mathsolver.objects; | |
import com.mathsolver.utils.Scanner; | |
/** | |
* Class to embody the structure of LookAheadPointer | |
* | |
* | |
* @author zerosign <r1nlx0@gmail.com> | |
* | |
*/ | |
public class LookAheadPtr { | |
private int start; | |
private int counter; | |
private CharSequence text; | |
/** | |
* Constructor of this class | |
* counter always have an initial value zero | |
* | |
* @param start start of the current CharacterSequence | |
* @param text | |
*/ | |
public LookAheadPtr(int start, CharSequence text) { | |
super(); | |
this.start = start; | |
this.text = text; | |
this.counter = 0; | |
} | |
/** | |
* Method that get current position of lookahead | |
* pointer from underlying CharacterSequence | |
* | |
* @return | |
*/ | |
public int getPosition() { | |
return start+counter; | |
} | |
/** | |
* Getter for counter variable | |
* | |
* @return | |
*/ | |
public int getCounter() { | |
return counter; | |
} | |
/** | |
* Method to increment the counter as number | |
* | |
* @param number | |
*/ | |
public void incrementCounter(int number) { | |
counter+= number; | |
} | |
/** | |
* Method to increment the counter post-increment by 1 | |
* | |
*/ | |
public void incrementCounter() { | |
counter++; | |
} | |
/** | |
* Method to decrement the counter post-decrement by 1 | |
*/ | |
public void decrementCounter() { | |
counter--; | |
} | |
/** | |
* Method to increment start index post increment by number | |
* | |
* @param number | |
*/ | |
public void incrementStart(int number) { | |
start+= number; | |
} | |
/** | |
* Method to increment start index post increment by 1 | |
* | |
*/ | |
public void incrementStart() { | |
start++; | |
} | |
/** | |
* Getter for start index in CharSequence | |
* | |
* @return | |
*/ | |
public int getStart() { | |
return start; | |
} | |
/** | |
* Getter CharSequence of current lexeme | |
* computed from start index and counter value | |
* | |
* @return | |
*/ | |
public CharSequence getLexemeText() { | |
return text.subSequence(start, start+counter); | |
} | |
/** | |
* Getter of current char by computing | |
* it from start and counter | |
* | |
* | |
* @return | |
*/ | |
public char currentChar() { | |
return text.charAt(start+counter); | |
} | |
/** | |
* Method to reset LookAheadPtr | |
* (reset start & counter value) | |
* | |
*/ | |
public void reset() { | |
start = 0; | |
counter = 0; | |
} | |
/** | |
* Method that increment the current start | |
* to next start of lexeme. This method need to | |
* be called after lexeme is found in method | |
* {@link Scanner#scan(CharSequence) scan} | |
* | |
* | |
*/ | |
public void next() { | |
start += counter; | |
counter = 0; | |
} | |
/** | |
* Getter of the length of CharSequence | |
* | |
* @return | |
*/ | |
public int length() { | |
return text.length(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment