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

com.linkedin.dagli.objectio.CollectionWriter Maven / Gradle / Ivy

Go to download

DAG-oriented machine learning framework for bug-resistant, readable, efficient, maintainable and trivially deployable models in Java and other JVM languages

There is a newer version: 15.0.0-beta9
Show newest version
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