mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-02 17:19:37 +00:00
Implemented a CompoundFunction
This can be used for the user specific functions and to implement the transitive dimensions.
This commit is contained in:
1 parent
a32200ccb4
commit
dd4fa0c310
21 files changed
+481
-103
No files matched your search
+5
-1
@@ -122,11 +122,15 @@ public class TestProcessorQuery {
|
||||
return element.getValue() >= 10;
|
||||
}
|
||||
};
|
||||
Processor<Iterable<Number>> filteringRetrievalProcessor = new AbstractFilteringRetrievalProcessor<Iterable<Number>, Number>(ConcurrencyTestsUtil.getExecutor(), Arrays.asList(lengthGrouper), retrievalFilterCriteria) {
|
||||
Processor<Iterable<Number>> filteringRetrievalProcessor = new AbstractFilteringRetrievalProcessor<Iterable<Number>, Number, Number>(ConcurrencyTestsUtil.getExecutor(), Arrays.asList(lengthGrouper), retrievalFilterCriteria) {
|
||||
@Override
|
||||
protected Iterable<Number> retrieveData(Iterable<Number> element) {
|
||||
return element;
|
||||
}
|
||||
@Override
|
||||
protected Number contextifyElement(Number partialElement) {
|
||||
return partialElement;
|
||||
}
|
||||
};
|
||||
|
||||
query.setFirstProcessor(filteringRetrievalProcessor);
|
||||
|
||||
+5
-1
@@ -74,11 +74,15 @@ public class TestAbstractFilteringRetrievalProcessor {
|
||||
return element >= 0;
|
||||
}
|
||||
};
|
||||
filteringRetrievalProcessor = new AbstractFilteringRetrievalProcessor<Iterable<Integer>, Integer>(ConcurrencyTestsUtil.getExecutor(), Arrays.asList(resultReceiver), filterCriteria) {
|
||||
filteringRetrievalProcessor = new AbstractFilteringRetrievalProcessor<Iterable<Integer>, Integer, Integer>(ConcurrencyTestsUtil.getExecutor(), Arrays.asList(resultReceiver), filterCriteria) {
|
||||
@Override
|
||||
protected Iterable<Integer> retrieveData(Iterable<Integer> element) {
|
||||
return element;
|
||||
}
|
||||
@Override
|
||||
protected Integer contextifyElement(Integer partialElement) {
|
||||
return partialElement;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.sap.sse.datamining.impl.function;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.datamining.factories.FunctionFactory;
|
||||
import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.impl.functions.CompoundFunction;
|
||||
import com.sap.sse.datamining.shared.Unit;
|
||||
import com.sap.sse.datamining.test.function.test_classes.ContainerElement;
|
||||
import com.sap.sse.datamining.test.function.test_classes.ContainerElementImpl;
|
||||
import com.sap.sse.datamining.test.function.test_classes.MarkedContainer;
|
||||
import com.sap.sse.datamining.test.function.test_classes.MarkedContainerImpl;
|
||||
import com.sap.sse.datamining.test.util.TestsUtil;
|
||||
|
||||
public class TestCompoundFunction {
|
||||
|
||||
private Function<?> getContainerElementFunction;
|
||||
private Function<?> getNameFunction;
|
||||
|
||||
private Function<String> compoundFunction;
|
||||
|
||||
@Before
|
||||
public void initializeCompoundFunction() throws ClassCastException, NoSuchMethodException, SecurityException {
|
||||
List<Function<?>> functions = new ArrayList<>();
|
||||
getContainerElementFunction = FunctionFactory.createMethodWrappingFunction(MarkedContainer.class.getMethod("getContainerElement", new Class<?>[0]));
|
||||
functions.add(getContainerElementFunction);
|
||||
getNameFunction = FunctionFactory.createMethodWrappingFunction(ContainerElement.class.getMethod("getName", new Class<?>[0]));
|
||||
functions.add(getNameFunction);
|
||||
|
||||
compoundFunction = FunctionFactory.createCompoundFunction("TestCompoundFunction", functions);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstruction() {
|
||||
List<Function<?>> functions = new ArrayList<>();
|
||||
functions.add(getContainerElementFunction);
|
||||
new CompoundFunction<String>("IllegalCompoundFunction", functions, String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitialValues() {
|
||||
assertThat(compoundFunction.isDimension(), is(true));
|
||||
//This is a workaround, because the assertion, that to types are equal checks for an instance of the given class instead.
|
||||
assertThat("The actual declaring class did'nt match the expected one.",
|
||||
compoundFunction.getDeclaringClass().equals(MarkedContainer.class), is(true));
|
||||
assertThat(compoundFunction.getSimpleName(), is("TestCompoundFunction"));
|
||||
assertThat(compoundFunction.getLocalizedName(Locale.ENGLISH, TestsUtil.getTestStringMessages()), is("TestCompoundFunction"));
|
||||
assertThat(compoundFunction.getResultUnit(), is(Unit.None));
|
||||
assertThat(compoundFunction.getResultDecimals(), is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvocation() {
|
||||
String containerElementName = "TestElement";
|
||||
ContainerElement element = new ContainerElementImpl(containerElementName);
|
||||
MarkedContainer container = new MarkedContainerImpl(element);
|
||||
|
||||
String result = compoundFunction.tryToInvoke(container);
|
||||
assertThat(result, is(containerElementName));
|
||||
}
|
||||
|
||||
}
|
||||
+10
-9
@@ -11,6 +11,7 @@ import java.util.Locale;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.datamining.factories.FunctionDTOFactory;
|
||||
import com.sap.sse.datamining.factories.FunctionFactory;
|
||||
import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.i18n.DataMiningStringMessages;
|
||||
@@ -43,9 +44,9 @@ public class TestFunctionDTOConstruction {
|
||||
Function<?> dimension = FunctionFactory.createMethodWrappingFunction(dimensionMethod);
|
||||
|
||||
FunctionDTO expectedDimensionDTO = createExpectedDimensionDTO();
|
||||
assertThat(dimension.asDTO(), is(expectedDimensionDTO));
|
||||
assertThat(dimension.asDTO(Locale.ENGLISH, stringMessages), is(expectedDimensionDTO));
|
||||
assertThat(dimension.asDTO(Locale.GERMAN, stringMessages), is(expectedDimensionDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(dimension), is(expectedDimensionDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(dimension, Locale.ENGLISH, stringMessages), is(expectedDimensionDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(dimension, Locale.GERMAN, stringMessages), is(expectedDimensionDTO));
|
||||
}
|
||||
|
||||
public FunctionDTOImpl createExpectedDimensionDTO() {
|
||||
@@ -65,8 +66,8 @@ public class TestFunctionDTOConstruction {
|
||||
Function<?> sideEffectFreeValue = FunctionFactory.createMethodWrappingFunction(sideEffectFreeValueMethod);
|
||||
|
||||
FunctionDTO expectedDTO = createExpectedNullarySideEffectFreeValueDTO();
|
||||
assertThat(sideEffectFreeValue.asDTO(Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(sideEffectFreeValue.asDTO(Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(sideEffectFreeValue, Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(sideEffectFreeValue, Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
}
|
||||
|
||||
private FunctionDTO createExpectedNullarySideEffectFreeValueDTO() {
|
||||
@@ -86,8 +87,8 @@ public class TestFunctionDTOConstruction {
|
||||
Function<?> externalLibraryFunction = FunctionFactory.createMethodWrappingFunction(externalLibraryMethod);
|
||||
|
||||
FunctionDTO expectedDTO = createExpectedExternalLibraryFunctionDTO();
|
||||
assertThat(externalLibraryFunction.asDTO(Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(externalLibraryFunction.asDTO(Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(externalLibraryFunction, Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(externalLibraryFunction, Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
}
|
||||
|
||||
private FunctionDTO createExpectedExternalLibraryFunctionDTO() {
|
||||
@@ -107,8 +108,8 @@ public class TestFunctionDTOConstruction {
|
||||
Function<?> increment = FunctionFactory.createMethodWrappingFunction(incrementMethod);
|
||||
|
||||
FunctionDTO expectedDTO = createFunctionDTOWithParameters();
|
||||
assertThat(increment.asDTO(Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(increment.asDTO(Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(increment, Locale.ENGLISH, stringMessages), is(expectedDTO));
|
||||
assertThat(FunctionDTOFactory.createFunctionDTO(increment, Locale.GERMAN, stringMessages), is(expectedDTO));
|
||||
}
|
||||
|
||||
private FunctionDTO createFunctionDTOWithParameters() {
|
||||
|
||||
+3
-2
@@ -12,6 +12,7 @@ import java.util.Locale;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.datamining.factories.FunctionDTOFactory;
|
||||
import com.sap.sse.datamining.factories.FunctionFactory;
|
||||
import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.functions.FunctionProvider;
|
||||
@@ -91,7 +92,7 @@ public class TestFunctionProvider {
|
||||
public void testGetFunctionForDTO() {
|
||||
Method getRegattaNameMethod = FunctionTestsUtil.getMethodFromClass(DataTypeWithContext.class, "getRegattaName");
|
||||
Function<Object> getRegattaName = FunctionFactory.createMethodWrappingFunction(getRegattaNameMethod);
|
||||
FunctionDTO getRegattaNameDTO = getRegattaName.asDTO(Locale.ENGLISH, stringMessages);
|
||||
FunctionDTO getRegattaNameDTO = FunctionDTOFactory.createFunctionDTO(getRegattaName, Locale.ENGLISH, stringMessages);
|
||||
|
||||
FunctionProvider functionProvider = new RegistryFunctionsProvider(functionRegistry, FunctionTestsUtil.getExecutor());
|
||||
@SuppressWarnings("unchecked") // Hamcrest requires type matching of actual and expected type, so the Functions have to be specific (without <?>)
|
||||
@@ -103,7 +104,7 @@ public class TestFunctionProvider {
|
||||
public void testGetFunctionForUnregisteredDTO() {
|
||||
Method incrementMethod = FunctionTestsUtil.getMethodFromClass(SimpleClassWithMarkedMethods.class, "increment", int.class);
|
||||
Function<Object> increment = FunctionFactory.createMethodWrappingFunction(incrementMethod);
|
||||
FunctionDTO incrementDTO = increment.asDTO(Locale.ENGLISH, stringMessages);
|
||||
FunctionDTO incrementDTO = FunctionDTOFactory.createFunctionDTO(increment, Locale.ENGLISH, stringMessages);
|
||||
|
||||
FunctionProvider functionProvider = new RegistryFunctionsProvider(functionRegistry, FunctionTestsUtil.getExecutor());
|
||||
assertThat(functionProvider.getFunctionFor(incrementDTO), is(nullValue()));
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.sap.sse.datamining.test.function.test_classes;
|
||||
|
||||
import com.sap.sse.datamining.shared.annotations.Dimension;
|
||||
|
||||
public interface ContainerElement {
|
||||
|
||||
@Dimension(messageKey="name")
|
||||
public String getName();
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.sap.sse.datamining.test.function.test_classes;
|
||||
|
||||
public class ContainerElementImpl implements ContainerElement {
|
||||
|
||||
private String name;
|
||||
|
||||
public ContainerElementImpl(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.sap.sse.datamining.test.function.test_classes;
|
||||
|
||||
import com.sap.sse.datamining.shared.annotations.SideEffectFreeValue;
|
||||
|
||||
public interface MarkedContainer {
|
||||
|
||||
@SideEffectFreeValue(messageKey="containerElement")
|
||||
public ContainerElement getContainerElement();
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.sap.sse.datamining.test.function.test_classes;
|
||||
|
||||
public class MarkedContainerImpl implements MarkedContainer {
|
||||
|
||||
private ContainerElement containerElement;
|
||||
|
||||
public MarkedContainerImpl(ContainerElement containerElement) {
|
||||
this.containerElement = containerElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerElement getContainerElement() {
|
||||
return containerElement;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user