⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenizer.java

📁 A Java Framework for connecting to and exchanging data from GPS units to J2ME Mobile Devices. Serial
💻 JAVA
字号:
package com.libGPS4j2me.devices.StdGPS.parser;

import java.util.NoSuchElementException;

/**
 * Tokenizer used in Parser.
 * 
 * @author Dominik Schmidt
 */
public class Tokenizer {
	/**
	 * Delimiter string.
	 */
	private static final String DELIMITER = ",";

	private int currentPosition;

	private int nextPosition;

	private String s;

	/**
	 * Constructs a new tokenizer for the given string.
	 * 
	 * @param s String to be tokenized
	 */
	public Tokenizer(String s) {
		this.s = s;
		this.currentPosition = 0;
		this.nextPosition = s.indexOf(DELIMITER, currentPosition);
	}

	/**
	 * @return True, if there is a token left
	 */
	public boolean hasNext() {
		return nextPosition != -1 && currentPosition <= nextPosition;
	}

	/**
	 * 
	 * @return Next token
	 * @throws NoSuchElementException If there is no token left
	 */
	public String next() throws NoSuchElementException {
		if (!hasNext())
			throw new NoSuchElementException();

		String next = s.substring(currentPosition, nextPosition);

		currentPosition = nextPosition + 1;
		nextPosition = s.indexOf(DELIMITER, currentPosition);

		return next;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -