All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kits.json.tokenizer.JsonTokenList Maven / Gradle / Ivy

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 +
				'}';
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy