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

net.sf.gluebooster.java.booster.basic.transformation.CallableByIterating 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.transformation;

import java.util.Iterator;

import net.sf.gluebooster.java.booster.essentials.eventsCommands.Callable;
import net.sf.gluebooster.java.booster.essentials.eventsCommands.CallableAbstraction;
import net.sf.gluebooster.java.booster.essentials.utils.ContainerBoostUtils;

/**
 * Expects an Iterable/Iterator and puts all values into another callable that is returned
 * 
 * @author cbauer
 *
 */
public class CallableByIterating extends CallableAbstraction {

	/**
	 * Is called with the elements of the iteration
	 */
	private Callable processor;

	public CallableByIterating(Callable processor) {
		setProcessor(processor);
	}

	@Override
	protected Callable callImpl(Object... iterable) throws Exception {

		if (iterable.length != 1) {
			throw new IllegalStateException("only size 1 supported");
		}

		Iterator iterator = ContainerBoostUtils.toIterator(iterable[0]);

		while (iterator.hasNext()) {
			processor.call(iterator.next());
		}

		return processor;
	}

	public Callable getProcessor() {
		return processor;
	}

	public void setProcessor(Callable processor) {
		this.processor = processor;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy