io.github.kits.json.tokenizer.JsonTokenList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whimthen-kits Show documentation
Show all versions of whimthen-kits Show documentation
Easy to use java tool library.
The newest version!
package io.github.kits.json.tokenizer;
import java.util.ArrayList;
import java.util.List;
/**
* @project: kits
* @created: with IDEA
* @author: whimthen
* @date: 2019-03-05-14:30 | March. Tuesday
*/
public class JsonTokenList {
private List tokens = new ArrayList<>();
private int pos = 0;
public void add(JsonToken token) {
tokens.add(token);
}
void clear() {
tokens.clear();
pos = 0;
}
public int size() {
return this.tokens.size();
}
public void remove(int index) {
if (index >= this.tokens.size()) {
throw new IndexOutOfBoundsException();
}
this.tokens.remove(index);
}
public JsonToken peek() {
return pos < tokens.size() ? tokens.get(pos) : null;
}
public JsonToken peekPrevious() {
return pos - 1 < 0 ? null : tokens.get(pos - 2);
}
public JsonToken next() {
return tokens.get(pos++);
}
public boolean hasMore() {
return pos < tokens.size();
}
@Override
public String toString() {
return "TokenList{" +
"tokens=" + tokens +
'}';
}
}