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

net.sf.gluebooster.java.booster.basic.container.IteratorByMatcher Maven / Gradle / Ivy

Go to download

Basic classes to support the development of applications. There should be as few dependencies on other frameworks as possible.

The newest version!
package net.sf.gluebooster.java.booster.basic.container;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;

/**
 * Iterates over match results.
 * 
 * @author cbauer
 *
 */
public class IteratorByMatcher implements Iterator {

	/**
	 * The input sequence used by the matcher
	 */
	private String input;

	/**
	 * The matcher
	 */
	private Matcher matcher;

	/**
	 * The result of the last find invocation.
	 */
	private Boolean lastFindResult = null;

	/**
	 * 
	 * @param matcher
	 * @param input
	 *            the matcher must already be reset to the input
	 */
	public IteratorByMatcher(Matcher matcher, CharSequence input) {
		this.input = input.toString();
		this.matcher = matcher;
	}

	@Override
	public boolean hasNext() {

		if (lastFindResult == null) {
			lastFindResult = matcher.find();
		}

		return lastFindResult;
	}

	@Override
	public Object next() {
		if (!hasNext()) {
			throw new NoSuchElementException("no next element");
		}

		return input.substring(matcher.start(), matcher.end());
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException("remove not yet supported");

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy