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

org.aksw.commons.collections.cache.CachingIterable Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
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> cache; // = new Cache();

    public CachingIterable(Iterator delegate) {
        super();
        this.delegate = delegate;
        this.cache = new Cache<>(new ArrayList<>());
    }

    public CachingIterable(Iterator delegate, Cache> 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