mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-02 17:19:37 +00:00
Implemented a method in the function provider to get transitive dimensions
This commit is contained in:
1 parent
dd4fa0c310
commit
009a19708c
10 files changed
+60
-11
No files matched your search
+1
-1
@@ -50,7 +50,7 @@ public class TestCompoundFunction {
|
||||
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));
|
||||
compoundFunction.getDeclaringType().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));
|
||||
|
||||
+14
@@ -24,11 +24,13 @@ import com.sap.sse.datamining.impl.functions.PartitioningParallelMarkedFunctionR
|
||||
import com.sap.sse.datamining.impl.functions.RegistryFunctionsProvider;
|
||||
import com.sap.sse.datamining.impl.functions.SimpleFunctionRegistry;
|
||||
import com.sap.sse.datamining.shared.dto.FunctionDTO;
|
||||
import com.sap.sse.datamining.test.function.test_classes.ContainerElement;
|
||||
import com.sap.sse.datamining.test.function.test_classes.DataTypeWithContext;
|
||||
import com.sap.sse.datamining.test.function.test_classes.DataTypeWithContextImpl;
|
||||
import com.sap.sse.datamining.test.function.test_classes.DataTypeWithContextProcessor;
|
||||
import com.sap.sse.datamining.test.function.test_classes.ExtendingInterface;
|
||||
import com.sap.sse.datamining.test.function.test_classes.ExternalLibraryClass;
|
||||
import com.sap.sse.datamining.test.function.test_classes.MarkedContainer;
|
||||
import com.sap.sse.datamining.test.function.test_classes.SimpleClassWithMarkedMethods;
|
||||
import com.sap.sse.datamining.test.util.FunctionTestsUtil;
|
||||
import com.sap.sse.datamining.test.util.TestsUtil;
|
||||
@@ -48,6 +50,8 @@ public class TestFunctionProvider {
|
||||
classesToScan.add(DataTypeWithContext.class);
|
||||
classesToScan.add(DataTypeWithContextProcessor.class);
|
||||
classesToScan.add(ExtendingInterface.class);
|
||||
classesToScan.add(MarkedContainer.class);
|
||||
classesToScan.add(ContainerElement.class);
|
||||
ParallelFunctionRetriever markedFunctionRetriever = new PartitioningParallelMarkedFunctionRetriever(classesToScan, FunctionTestsUtil.getExecutor());
|
||||
functionRegistry.registerFunctionsRetrievedBy(markedFunctionRetriever);
|
||||
|
||||
@@ -116,4 +120,14 @@ public class TestFunctionProvider {
|
||||
assertThat(functionProvider.getFunctionFor(null), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTransitiveDimension() throws ClassCastException, NoSuchMethodException, SecurityException {
|
||||
FunctionProvider functionProvider = new RegistryFunctionsProvider(functionRegistry, FunctionTestsUtil.getExecutor());
|
||||
|
||||
Collection<Function<?>> expectedDimensions = new HashSet<>();
|
||||
expectedDimensions.add(FunctionFactory.createMethodWrappingFunction(ContainerElement.class.getMethod("getName",
|
||||
new Class<?>[0])));
|
||||
assertThat(functionProvider.getTransitiveDimensionsFor(MarkedContainer.class, 1), is(expectedDimensions));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class FunctionDTOFactory {
|
||||
|
||||
private static FunctionDTO createFunctionDTO(Function<?> function, String displayName) {
|
||||
String functionName = function.getSimpleName();
|
||||
String sourceTypeName = function.getDeclaringClass().getSimpleName();
|
||||
String sourceTypeName = function.getDeclaringType().getSimpleName();
|
||||
String returnTypeName = function.getReturnType().getSimpleName();
|
||||
List<String> parameterTypeNames = getParameterTypeNames(function);
|
||||
return new FunctionDTOImpl(functionName, sourceTypeName, returnTypeName, parameterTypeNames, displayName, function.isDimension());
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.sap.sse.datamining.shared.Unit;
|
||||
|
||||
public interface Function<ReturnType> {
|
||||
|
||||
public Class<?> getDeclaringClass();
|
||||
public Class<?> getDeclaringType();
|
||||
public Iterable<Class<?>> getParameters();
|
||||
public Class<ReturnType> getReturnType();
|
||||
|
||||
|
||||
+12
@@ -8,6 +8,18 @@ public interface FunctionProvider {
|
||||
|
||||
public Collection<Function<?>> getDimensionsFor(Class<?> dataType);
|
||||
|
||||
/**
|
||||
* Collects all dimensions for the given data type, where transitive dimensions will also be
|
||||
* collected. A transitive dimension is a dimension, that can be reached with functions of the
|
||||
* given data type.<br />
|
||||
* The depth defines the maximum amount of functions that can be between the data type and the
|
||||
* collected dimensions. A depth of 0 would collect only the dimensions of the given data type.
|
||||
* @param dataType
|
||||
* @param depth
|
||||
* @return
|
||||
*/
|
||||
public Collection<Function<?>> getTransitiveDimensionsFor(Class<?> dataType, int depth);
|
||||
|
||||
public Collection<Function<?>> getFunctionsFor(Class<?> sourceType);
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ public class CompoundFunction<ReturnType> extends AbstractFunction<ReturnType> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDeclaringClass() {
|
||||
return getFirstFunction().getDeclaringClass();
|
||||
public Class<?> getDeclaringType() {
|
||||
return getFirstFunction().getDeclaringType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class DeclaringTypeOrParameterTypeCriteria implements FilterCriteria<Func
|
||||
}
|
||||
|
||||
public boolean isDeclaringTypeMatching(Function<?> function, Class<?> expectingType) {
|
||||
return function.getDeclaringClass().equals(expectingType);
|
||||
return function.getDeclaringType().equals(expectingType);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -53,7 +53,7 @@ public class MethodWrappingFunction<ReturnType> extends AbstractFunction<ReturnT
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDeclaringClass() {
|
||||
public Class<?> getDeclaringType() {
|
||||
return method.getDeclaringClass();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class MethodWrappingFunction<ReturnType> extends AbstractFunction<ReturnT
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getDeclaringClass().getSimpleName() + "." + getMethodName() + "(" + parametersAsString() + ") : " + method.getReturnType().getSimpleName();
|
||||
return getDeclaringType().getSimpleName() + "." + getMethodName() + "(" + parametersAsString() + ") : " + method.getReturnType().getSimpleName();
|
||||
}
|
||||
|
||||
private String parametersAsString() {
|
||||
|
||||
+23
@@ -35,6 +35,29 @@ public class RegistryFunctionsProvider implements FunctionProvider {
|
||||
return filterForDeclaringType(functionRegistry.getAllDimensions(), dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Function<?>> getTransitiveDimensionsFor(Class<?> dataType, int depth) {
|
||||
Collection<Function<?>> dimensions = new HashSet<>();
|
||||
|
||||
Collection<Class<?>> typesToCheck = new HashSet<>();
|
||||
Collection<Class<?>> typesToAdd = new HashSet<>();
|
||||
typesToCheck.add(dataType);
|
||||
for (int i = 0; i <= depth; i++) {
|
||||
for (Class<?> type : typesToCheck) {
|
||||
for (Function<?> function : getFunctionsFor(type)) {
|
||||
if (function.isDimension()) {
|
||||
dimensions.add(function);
|
||||
}
|
||||
typesToAdd.add(function.getReturnType());
|
||||
}
|
||||
}
|
||||
typesToCheck.clear();
|
||||
typesToCheck.addAll(typesToAdd);
|
||||
typesToAdd.clear();
|
||||
}
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Function<?>> getFunctionsFor(Class<?> sourceType) {
|
||||
return filterForDeclaringType(functionRegistry.getAllRegisteredFunctions(), sourceType);
|
||||
|
||||
+3
-3
@@ -62,10 +62,10 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
}
|
||||
|
||||
private void putFunctionIntoMap(Function<?> function) {
|
||||
if (!registeredFunctionsMappedByDeclaringClass.containsKey(function.getDeclaringClass())) {
|
||||
registeredFunctionsMappedByDeclaringClass.put(function.getDeclaringClass(), new HashSet<Function<?>>());
|
||||
if (!registeredFunctionsMappedByDeclaringClass.containsKey(function.getDeclaringType())) {
|
||||
registeredFunctionsMappedByDeclaringClass.put(function.getDeclaringType(), new HashSet<Function<?>>());
|
||||
}
|
||||
registeredFunctionsMappedByDeclaringClass.get(function.getDeclaringClass()).add(function);
|
||||
registeredFunctionsMappedByDeclaringClass.get(function.getDeclaringType()).add(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user