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

com.emc.mongoose.common.io.collection.ListOutput Maven / Gradle / Ivy

The newest version!
package com.emc.mongoose.common.io.collection;

import com.emc.mongoose.common.io.Output;

import java.io.IOException;
import java.util.List;

/**
 Created by kurila on 18.06.15.
 Writable collection of the data items.
 */
public class ListOutput
implements Output {
	
	protected final List items;
	
	public ListOutput(final List items) {
		this.items = items;
	}

	/**
	 @param item the data item to put
	 @throws IOException if the destination collection fails to add the data item
	 (due to capacity reasons for example)
	 */
	@Override
	public boolean put(final T item)
	throws IOException {
		return items.add(item);
	}

	/**
	 Bulk put of the data items from the specified buffer
	 @param buffer the buffer containing the data items to put
	 @return the count of the data items which have been written successfully
	 @throws IOException doesn't throw
	 */
	@Override
	public int put(final List buffer, final int from, final int to)
	throws IOException {
		for(final T item : buffer.subList(from, to)) {
			items.add(item);
		}
		return to - from;
	}

	
	@Override
	public final int put(final List items)
	throws IOException {
		return put(items, 0, items.size());
	}

	/**
	 @return the corresponding input
	 @throws IOException doesn't throw
	 */
	@Override
	public ListInput getInput()
	throws IOException {
		return new ListInput<>(items);
	}

	/**
	 does nothing
	 @throws IOException doesn't throw
	 */
	@Override
	public void close()
	throws IOException {
	}

	
	@Override
	public String toString() {
		return "listItemOutput<" + items.hashCode() + ">";
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy