com.linkedin.dagli.objectio.CollectionWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectio-core Show documentation
Show all versions of objectio-core Show documentation
DAG-oriented machine learning framework for bug-resistant, readable, efficient, maintainable and trivially deployable models in Java and other JVM languages
package com.linkedin.dagli.objectio;
import java.util.Collection;
/**
* Wraps a {@link Collection} as an {@link ObjectWriter}. Changes to the {@link CollectionWriter} will affect
* the wrapped collection, and vice-versa.
* @param
*/
public class CollectionWriter implements ObjectWriter {
private Collection _collection;
/**
* Create a new wrapper around the given collection.
*
* @param collection the collection to be wrapped
*/
public CollectionWriter(Collection collection) {
_collection = collection;
}
/**
* @return the underlying collection
*/
public Collection getCollection() {
return _collection;
}
@Override
public void write(T appended) {
_collection.add(appended);
}
@Override
public ObjectReader createReader() {
return new IterableReader<>(_collection, _collection.size());
}
@Override
public long size64() {
return _collection.size();
}
/**
* Closing has no effect on the underlying collection.
*/
@Override
public void close() { }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy