package org.openlca.ilcd.io;

import java.io.Closeable;
import java.io.File;
import java.io.InputStream;
import java.util.Iterator;

import org.openlca.ilcd.commons.IDataSet;
import org.openlca.ilcd.sources.Source;

public interface DataStore extends Closeable {

	<T> T get(Class<T> type, String id) throws DataStoreException;

	InputStream getExternalDocument(String sourceId, String fileName)
			throws DataStoreException;

	void put(IDataSet ds) throws DataStoreException;

	void put(Source source, File[] files) throws DataStoreException;

	<T> boolean delete(Class<T> type, String id) throws DataStoreException;

	<T> Iterator<T> iterator(Class<T> type) throws DataStoreException;

	<T> boolean contains(Class<T> type, String id) throws DataStoreException;

}

@@ -124,16 +124,52 @@
 terator;
+%0Aimport java.util.function.Consumer;
 %0A%0Aimport
@@ -243,16 +243,73 @@
 .Source;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apublic
@@ -850,10 +850,379 @@
 ption;%0A%0A
+%09default %3CT extends IDataSet%3E void each(Class%3CT%3E type, Consumer%3CT%3E fn) %7B%0A%09%09try %7B%0A%09%09%09Iterator%3CT%3E it = iterator(type);%0A%09%09%09while (it.hasNext()) %7B%0A%09%09%09%09T t = it.next();%0A%09%09%09%09if (t != null) %7B%0A%09%09%09%09%09fn.accept(t);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09Logger log = LoggerFactory.getLogger(getClass());%0A%09%09%09log.error(%22failed to iterate over elements of type %22 + type, e);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

add an `each` method