org.aksw.commons.collections.cache.CachingIterable Maven / Gradle / Ivy
package org.aksw.commons.collections.cache;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Iterables;
/**
* An iterable over an iterator that caches the iterator's results.
*
* @author raven
*
* @param
*/
public class CachingIterable
implements Iterable
{
protected Iterator delegate;
protected Cache extends List> cache; // = new Cache();
public CachingIterable(Iterator delegate) {
super();
this.delegate = delegate;
this.cache = new Cache<>(new ArrayList<>());
}
public CachingIterable(Iterator delegate, Cache extends List> cache) {
super();
this.delegate = delegate;
this.cache = cache;
}
@Override
public Iterator iterator() {
Iterator result = new CachingIterator(cache, delegate, 0);
return result;
}
@Override
public String toString() {
String result = Iterables.toString(this);
return result;
}
// public static Iterable newArrayListCachingIterable(Iterator delegate) {
// Cache cache = new Cache>(new ArrayList());
// Iterable result = new CachingIterable>(delegate, cache, 0);
// return result;
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy