Replaced all FilteringRetriever with retrievers followed by a filter

This commit is contained in:
Lennart Hensler committed 2014-10-07 08:58:38 +02:00
1 parent 42204a87e9
commit 96a0052fed
12 files changed
+50 -144

No files matched your search

@@ -12,7 +12,6 @@ import com.sap.sse.datamining.DataRetrieverChainDefinition;
import com.sap.sse.datamining.components.FilterCriterion;
import com.sap.sse.datamining.components.Processor;
import com.sap.sse.datamining.impl.components.ParallelFilteringProcessor;
import com.sap.sse.datamining.impl.criterias.NonFilteringFilterCriterion;
public class SimpleDataRetrieverChainBuilder<DataSourceType> implements DataRetrieverChainBuilder<DataSourceType> {
@@ -133,14 +132,8 @@ public class SimpleDataRetrieverChainBuilder<DataSourceType> implements DataRetr
try {
retrieverConstructor = retrieverType.getConstructor(ExecutorService.class, Collection.class);
} catch (NoSuchMethodException | SecurityException e) {
// TODO Remove the inner try-catch, after all filtering retriever have been split up to a retriever
// followed by a filter
try {
retrieverConstructor = retrieverType.getConstructor(ExecutorService.class, Collection.class, FilterCriterion.class);
} catch (NoSuchMethodException | SecurityException e1) {
throw new IllegalArgumentException("Couldn't get an usable constructor from the given retrieverType '"
+ retrieverType.getSimpleName() + "'", e);
}
throw new IllegalArgumentException("Couldn't get an usable constructor from the given retrieverType '"
+ retrieverType.getSimpleName() + "'", e);
}
return constructRetriever(retrieverConstructor, retrievedDataType, resultReceivers, filter);
@@ -149,32 +142,20 @@ public class SimpleDataRetrieverChainBuilder<DataSourceType> implements DataRetr
private <ResultType> Processor<?, ResultType> constructRetriever(Constructor<Processor<?, ResultType>> retrieverConstructor, Class<ResultType> retrievedDataType,
Collection<Processor<ResultType, ?>> resultReceivers, FilterCriterion<ResultType> filter) {
try {
if (retrieverConstructor.getParameterTypes().length == 2) {
Collection<Processor<ResultType, ?>> retrievalResultReceivers = resultReceivers;
if (filter != null) {
Processor<ResultType, ?> filteringProcessor = new ParallelFilteringProcessor<ResultType>(retrievedDataType, executor, resultReceivers, filter);
retrievalResultReceivers = new ArrayList<>();
retrievalResultReceivers.add(filteringProcessor);
}
return retrieverConstructor.newInstance(executor, retrievalResultReceivers);
}
// TODO Remove the second if, after all filtering retriever have been split up to a retriever
// followed by a filter
if (retrieverConstructor.getParameterTypes().length == 3) {
if (filter == null) {
filter = new NonFilteringFilterCriterion<>(retrievedDataType);
}
return retrieverConstructor.newInstance(executor, resultReceivers, filter);
Collection<Processor<ResultType, ?>> retrievalResultReceivers = resultReceivers;
if (filter != null) {
Processor<ResultType, ?> filteringProcessor = new ParallelFilteringProcessor<ResultType>(
retrievedDataType, executor, resultReceivers, filter);
retrievalResultReceivers = new ArrayList<>();
retrievalResultReceivers.add(filteringProcessor);
}
return retrieverConstructor.newInstance(executor, retrievalResultReceivers);
} catch (InstantiationException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException e) {
throw new UnsupportedOperationException("Couldn't create a data retriever instance with the constructor "
+ retrieverConstructor.toString(), e);
}
throw new UnsupportedOperationException("Couldn't create a data retriever instance with the constructor "
+ retrieverConstructor.toString());
}
}
@@ -7,7 +7,6 @@ import java.util.concurrent.ExecutorService;
import com.sap.sse.datamining.DataRetrieverChainBuilder;
import com.sap.sse.datamining.DataRetrieverChainDefinition;
import com.sap.sse.datamining.components.FilterCriterion;
import com.sap.sse.datamining.components.Processor;
public class SimpleDataRetrieverChainDefinition<DataSourceType> implements
@@ -70,14 +69,8 @@ public class SimpleDataRetrieverChainDefinition<DataSourceType> implements
try {
retrieverType.getConstructor(ExecutorService.class, Collection.class);
} catch (NoSuchMethodException | SecurityException e) {
// TODO Remove the inner try-catch, after all filtering retriever have been split up to a retriever
// followed by a filter
try {
retrieverType.getConstructor(ExecutorService.class, Collection.class, FilterCriterion.class);
} catch (NoSuchMethodException | SecurityException e1) {
throw new IllegalArgumentException("Couldn't get an usable constructor from the given nextRetrieverType '"
+ retrieverType.getSimpleName() + "'", e);
}
throw new IllegalArgumentException("Couldn't get an usable constructor from the given nextRetrieverType '"
+ retrieverType.getSimpleName() + "'", e);
}
}
@@ -1,38 +0,0 @@
package com.sap.sse.datamining.impl.components;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import com.sap.sse.datamining.components.FilterCriterion;
import com.sap.sse.datamining.components.Processor;
public abstract class AbstractFilteringRetrievalProcessor<InputType, WorkingType, ResultType>
extends AbstractRetrievalProcessor<InputType, WorkingType, ResultType> {
private final FilterCriterion<ResultType> criteria;
public AbstractFilteringRetrievalProcessor(Class<InputType> inputType, Class<ResultType> resultType,
ExecutorService executor, Collection<Processor<ResultType, ?>> resultReceivers, FilterCriterion<ResultType> criteria) {
super(inputType, resultType, executor, resultReceivers);
this.criteria = criteria;
}
@Override
protected Callable<ResultType> createInstruction(final WorkingType partialElement) {
final Callable<ResultType> superInstruction = super.createInstruction(partialElement);
return new Callable<ResultType>() {
@Override
public ResultType call() throws Exception {
ResultType elementWithContext = superInstruction.call();
if (criteria.matches(elementWithContext)) {
return elementWithContext;
} else {
AbstractFilteringRetrievalProcessor.super.decrementRetrievedDataAmount();
return createInvalidResult();
}
}
};
}
}
@@ -1,22 +0,0 @@
package com.sap.sse.datamining.impl.components;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import com.sap.sse.datamining.components.FilterCriterion;
import com.sap.sse.datamining.components.Processor;
public abstract class AbstractSimpleFilteringRetrievalProcessor<InputType, ResultType> extends
AbstractFilteringRetrievalProcessor<InputType, ResultType, ResultType> {
public AbstractSimpleFilteringRetrievalProcessor(Class<InputType> inputType, Class<ResultType> resultType,
ExecutorService executor, Collection<Processor<ResultType, ?>> resultReceivers, FilterCriterion<ResultType> criteria) {
super(inputType, resultType, executor, resultReceivers, criteria);
}
@Override
protected ResultType convertWorkingToResultType(ResultType partialElement) {
return partialElement;
}
}