Commit a9b02fa7 authored by R.W.Majeed's avatar R.W.Majeed

Refactored ObservationProvider to use single Consumer as handler

parent 8f653f87
package de.sekmi.histream;
import java.util.function.Consumer;
public interface ObservationProvider{
void addHandler(ObservationHandler handler);
void removeHandler(ObservationHandler handler);
void setHandler(Consumer<Observation> consumer);
Class<?>[] getSupportedExtensions();
}
package de.sekmi.histream.impl;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.function.Consumer;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationHandler;
import de.sekmi.histream.ObservationProvider;
public abstract class AbstractObservationProvider implements ObservationProvider {
private LinkedList<ObservationHandler> handlers;
private Consumer<Observation> consumer;
public AbstractObservationProvider() {
handlers = new LinkedList<>();
}
@Override
public void addHandler(ObservationHandler handler) {
handlers.add(handler);
}
@Override
public void removeHandler(ObservationHandler handler) {
handlers.remove(handler);
public void setHandler(Consumer<Observation> consumer) {
this.consumer = consumer;
}
public void provideObservation(Observation observation){
Iterator<ObservationHandler> iter = handlers.iterator();
/*Iterator<ObservationHandler> iter = handlers.iterator();
while( iter.hasNext() ){
iter.next().accept(observation);
}
}*/
consumer.accept(observation);
}
}
......@@ -48,7 +48,7 @@ public class TestInsertXmlToI2b2 {
// load instance_num presets
visitStore.getStore().loadMaxInstanceNums();
provider.addHandler(inserter);
provider.setHandler(inserter);
reader.setContentHandler(provider);
reader.parse(new InputSource(new FileReader("src/test/resources/dwh-eav.xml")));
inserter.close();
......
......@@ -102,7 +102,7 @@ public class TestXmlReader {
});
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXObservationProvider provider = new SAXObservationProvider(factory);
provider.addHandler(handler);
provider.setHandler(handler);
reader.setContentHandler(provider);
reader.parse(new InputSource(new FileReader("src/test/resources/dwh-eav.xml")));
handler.finish();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment