com.github.akurilov.commons.io.collection.ListOutput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-commons Show documentation
Show all versions of java-commons Show documentation
Common functionality Java library
The newest version!
package com.github.akurilov.commons.io.collection;
import com.github.akurilov.commons.io.Output;
import java.util.List;
/**
* Writable collection of the items. Not thread safe.
*/
public class ListOutput
implements Output {
protected final List items;
public ListOutput(final List items) {
this.items = items;
}
/**
@param item the item to put
(due to capacity reasons for example)
*/
@Override
public boolean put(final T item) {
return items.add(item);
}
/**
Bulk put of the items from the specified buffer
@param buffer the buffer containing the items to put
@return the count of the items which have been written successfully
*/
@Override
public int put(final List buffer, final int from, final int to) {
for(var i = from; i < to; i ++) {
items.add(buffer.get(i));
}
return to - from;
}
@Override
public final int put(final List items) {
return put(items, 0, items.size());
}
/**
@return the corresponding input
*/
@Override
public ListInput getInput() {
return new ListInput<>(items);
}
/**
does nothing
*/
@Override
public void close() {
}
@Override
public String toString() {
return "listOutput<" + items.hashCode() + ">";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy