com.alachisoft.ncache.common.Tokenizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package com.alachisoft.ncache.common;
public class Tokenizer implements java.util.Iterator {
private String text;
private char[] delims;
private String[] tokens;
private int index;
/**
* @param text
* @param delimiters SEND ONE CHAR ONLY - haven't tested for multiple delimiters
*/
public Tokenizer(String text, String delimiters) {
this.text = text;
delims = delimiters.toCharArray();
tokens = text.split(delimiters);
if (tokens.length == 1 && tokens[0].isEmpty())
tokens = new String[0];
index = -1; // First call of MoveNext will put the pointer on right position.
}
@Override
public final String next() {
return tokens[index]; //Hasan: this is absurd
}
/**
* Remaining tokens count
*
* @return
*/
public final int getCount() {
if (index < tokens.length) {
return tokens.length - index - 1;
} else {
return 0;
}
}
/**
* Determines if there are more tokens to return from text. Also moves the pointer to next token
*
* @return True if there are more tokens otherwise, false
*/
//public final boolean HasMoreTokens()
@Override
public final boolean hasNext() { //Hasan: bad design
if (index < tokens.length - 1) {
index++;
return true;
} else {
return false;
}
}
/**
* Performs the same action as NextToken
*
* @return
*/
public final Object getCurrent() {
return next();
}
/**
* Performs the same function as HasMoreTokens
*
* @return True if there are more tokens otherwise, false
*/
public final boolean MoveNext() {
return hasNext(); //Hasan: this is absurd
}
public final void Reset() {
index = -1;
}
@Override
@Deprecated
public final void remove() {
}
}