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

org.unix4j.io.CompositeInput Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.io;

import java.util.Arrays;
import java.util.List;

import org.unix4j.line.Line;

/**
 * An input composed from multiple other inputs returning all lines of the first
 * input, then all lines of the of the second input etc.
 */
public class CompositeInput extends AbstractInput {

	private int index;
	private final List inputs;

	/**
	 * Constructor with inputs to combine.
	 * 
	 * @param inputs
	 *            the inputs to combine
	 */
	public CompositeInput(Input... inputs) {
		this(Arrays.asList(inputs));
	}

	/**
	 * Constructor with inputs to combine.
	 * 
	 * @param inputs
	 *            the inputs to combine
	 */
	public CompositeInput(List inputs) {
		this.inputs = inputs;
	}

	@Override
	public boolean hasMoreLines() {
		while (index < inputs.size()) {
			if (inputs.get(index).hasMoreLines()) {
				return true;
			}
			index++;
		}
		return false;
	}

	@Override
	public Line readLine() {
		if (hasMoreLines()) {
			return inputs.get(index).readLine();
		}
		return null;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + "(inputs=" + inputs + ")";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy