mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-06 20:33:54 +00:00
Implemented a DataRetrieverChainDefinitionRegistry
This commit is contained in:
1 parent
20637452a7
commit
a2b3ff2c32
8 files changed
+220
-2
No files matched your search
+7
-1
@@ -1,4 +1,4 @@
|
||||
package com.sap.sse.datamining.impl.components;
|
||||
package com.sap.sse.datamining.impl;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -77,6 +77,12 @@ public class TestDataRetrieverChainCreation {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreationWithExistingChainDefinition() {
|
||||
DataRetrieverChainDefinition<Collection<Test_Regatta>> chainClone = new SimpleDataRetrieverChainDefinition<>(dataRetrieverChainDefinition);
|
||||
assertThat(chainClone, is(dataRetrieverChainDefinition));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.sap.sse.datamining.impl;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.datamining.DataRetrieverChainDefinition;
|
||||
import com.sap.sse.datamining.components.Processor;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_classes.Test_Regatta;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_contexts.Test_HasLegOfCompetitorContext;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_contexts.Test_HasRaceContext;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_contexts.Test_HasRaceContextImpl;
|
||||
import com.sap.sse.datamining.test.util.components.TestLegOfCompetitorWithContextRetrievalProcessor;
|
||||
import com.sap.sse.datamining.test.util.components.TestRaceWithContextRetrievalProcessor;
|
||||
import com.sap.sse.datamining.test.util.components.TestRegattaRetrievalProcessor;
|
||||
|
||||
public class TestDataRetrieverChainDefinitionRegistry {
|
||||
|
||||
private DataRetrieverChainDefinition<Collection<Test_Regatta>> raceRetrieverChainDefinition;
|
||||
private DataRetrieverChainDefinition<Collection<Test_Regatta>> legRetrieverChainDefinition;
|
||||
private DataRetrieverChainDefinitionRegistry dataRetrieverChainDefinitionRegistry;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void initializeRetrieverChainsAndRegistry() {
|
||||
raceRetrieverChainDefinition = new SimpleDataRetrieverChainDefinition<>((Class<Collection<Test_Regatta>>)(Class<?>) Collection.class);
|
||||
Class<Processor<Collection<Test_Regatta>, Test_Regatta>> regattaRetrieverClass = (Class<Processor<Collection<Test_Regatta>, Test_Regatta>>)(Class<?>) TestRegattaRetrievalProcessor.class;
|
||||
raceRetrieverChainDefinition.startWith(regattaRetrieverClass, Test_Regatta.class);
|
||||
|
||||
Class<Processor<Test_Regatta, Test_HasRaceContext>> raceRetrieverClass =
|
||||
(Class<Processor<Test_Regatta, Test_HasRaceContext>>)(Class<?>) TestRaceWithContextRetrievalProcessor.class;
|
||||
raceRetrieverChainDefinition.addAsLast(regattaRetrieverClass,
|
||||
raceRetrieverClass,
|
||||
Test_HasRaceContext.class);
|
||||
|
||||
legRetrieverChainDefinition = new SimpleDataRetrieverChainDefinition<Collection<Test_Regatta>>(raceRetrieverChainDefinition);
|
||||
|
||||
Class<Processor<Test_HasRaceContext, Test_HasLegOfCompetitorContext>> legRetrieverClass =
|
||||
(Class<Processor<Test_HasRaceContext, Test_HasLegOfCompetitorContext>>)(Class<?>) TestLegOfCompetitorWithContextRetrievalProcessor.class;
|
||||
legRetrieverChainDefinition.addAsLast(raceRetrieverClass,
|
||||
legRetrieverClass,
|
||||
Test_HasLegOfCompetitorContext.class);
|
||||
|
||||
dataRetrieverChainDefinitionRegistry = new SimpleDataRetrieverChainDefinitionRegistry();
|
||||
dataRetrieverChainDefinitionRegistry.add(raceRetrieverChainDefinition);
|
||||
dataRetrieverChainDefinitionRegistry.add(legRetrieverChainDefinition);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetDataRetrieverChainDefinitions() {
|
||||
Class<Collection<Test_Regatta>> dataSourceType = (Class<Collection<Test_Regatta>>)(Class<?>) Collection.class;
|
||||
|
||||
Collection<DataRetrieverChainDefinition<Collection<Test_Regatta>>> expectedDataRetrieverChainDefinitions = new HashSet<>();
|
||||
expectedDataRetrieverChainDefinitions.add(raceRetrieverChainDefinition);
|
||||
assertThat(dataRetrieverChainDefinitionRegistry.getDataRetrieverChainDefinitions(dataSourceType, Test_HasRaceContext.class), is(expectedDataRetrieverChainDefinitions));
|
||||
|
||||
expectedDataRetrieverChainDefinitions = new HashSet<>();
|
||||
expectedDataRetrieverChainDefinitions.add(legRetrieverChainDefinition);
|
||||
assertThat(dataRetrieverChainDefinitionRegistry.getDataRetrieverChainDefinitions(dataSourceType, Test_HasLegOfCompetitorContext.class), is(expectedDataRetrieverChainDefinitions));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataRetrieverChainDefinitionsForNotRegisteresChain() {
|
||||
Collection<DataRetrieverChainDefinition<Test_Regatta>> expectedEmptyDataRetrieverChainDefinitions = new HashSet<DataRetrieverChainDefinition<Test_Regatta>>();
|
||||
assertThat(dataRetrieverChainDefinitionRegistry.getDataRetrieverChainDefinitions(Test_Regatta.class, Test_HasRaceContextImpl.class), is(expectedEmptyDataRetrieverChainDefinitions));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ Export-Package: com.sap.sse.datamining,
|
||||
com.sap.sse.datamining.impl.functions,
|
||||
com.sap.sse.datamining.impl.functions.criterias,
|
||||
com.sap.sse.datamining.impl.i18n
|
||||
Require-Bundle: com.sap.sse.datamining.shared;bundle-version="1.0.0"
|
||||
Require-Bundle: com.sap.sse.datamining.shared;bundle-version="1.0.0",
|
||||
com.sap.sse.common;bundle-version="1.0.0"
|
||||
Bundle-Activator: com.sap.sse.datamining.impl.DataMiningActivator
|
||||
Bundle-ActivationPolicy: lazy
|
||||
+4
@@ -1,8 +1,10 @@
|
||||
package com.sap.sse.datamining;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import com.sap.sse.datamining.components.Processor;
|
||||
import com.sap.sse.datamining.impl.DataRetrieverTypeWithInformation;
|
||||
|
||||
public interface DataRetrieverChainDefinition<DataSourceType> {
|
||||
|
||||
@@ -23,6 +25,8 @@ public interface DataRetrieverChainDefinition<DataSourceType> {
|
||||
Class<Processor<NextInputType, NextResultType>> nextRetrieverType,
|
||||
Class<NextResultType> retrievedDataType);
|
||||
|
||||
public Collection<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation();
|
||||
|
||||
public DataRetrieverChainBuilder<DataSourceType> startBuilding(ExecutorService executor);
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.sap.sse.datamining.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.sap.sse.datamining.DataRetrieverChainDefinition;
|
||||
|
||||
public interface DataRetrieverChainDefinitionRegistry {
|
||||
|
||||
public void add(DataRetrieverChainDefinition<?> raceRetrieverChainDefinition);
|
||||
|
||||
public <DataSourceType> Collection<DataRetrieverChainDefinition<DataSourceType>> getDataRetrieverChainDefinitions(
|
||||
Class<DataSourceType> dataSourceType, Class<?> retrievedDataType);
|
||||
|
||||
}
|
||||
+31
@@ -21,4 +21,35 @@ public class DataRetrieverTypeWithInformation<InputType, RetrievedDataType> {
|
||||
return retrievedDataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((retrievedDataType == null) ? 0 : retrievedDataType.hashCode());
|
||||
result = prime * result + ((retrieverType == null) ? 0 : retrieverType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DataRetrieverTypeWithInformation<?, ?> other = (DataRetrieverTypeWithInformation<?, ?>) obj;
|
||||
if (retrievedDataType == null) {
|
||||
if (other.retrievedDataType != null)
|
||||
return false;
|
||||
} else if (!retrievedDataType.equals(other.retrievedDataType))
|
||||
return false;
|
||||
if (retrieverType == null) {
|
||||
if (other.retrieverType != null)
|
||||
return false;
|
||||
} else if (!retrieverType.equals(other.retrieverType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -20,6 +20,11 @@ public class SimpleDataRetrieverChainDefinition<DataSourceType> implements
|
||||
dataRetrieverTypesWithInformation = new ArrayList<>();
|
||||
}
|
||||
|
||||
public SimpleDataRetrieverChainDefinition(DataRetrieverChainDefinition<DataSourceType> dataRetrieverChainDefinition) {
|
||||
this(dataRetrieverChainDefinition.getDataSourceType());
|
||||
dataRetrieverTypesWithInformation.addAll(dataRetrieverChainDefinition.getDataRetrieverTypesWithInformation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DataSourceType> getDataSourceType() {
|
||||
return dataSourceType;
|
||||
@@ -78,10 +83,47 @@ public class SimpleDataRetrieverChainDefinition<DataSourceType> implements
|
||||
+ retrieverType.getSimpleName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation() {
|
||||
return dataRetrieverTypesWithInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataRetrieverChainBuilder<DataSourceType> startBuilding(ExecutorService executor) {
|
||||
return new SimpleDataRetrieverChainBuilder<>(executor, dataRetrieverTypesWithInformation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((dataRetrieverTypesWithInformation == null) ? 0 : dataRetrieverTypesWithInformation.hashCode());
|
||||
result = prime * result + ((dataSourceType == null) ? 0 : dataSourceType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SimpleDataRetrieverChainDefinition<?> other = (SimpleDataRetrieverChainDefinition<?>) obj;
|
||||
if (dataRetrieverTypesWithInformation == null) {
|
||||
if (other.dataRetrieverTypesWithInformation != null)
|
||||
return false;
|
||||
} else if (!dataRetrieverTypesWithInformation.equals(other.dataRetrieverTypesWithInformation))
|
||||
return false;
|
||||
if (dataSourceType == null) {
|
||||
if (other.dataSourceType != null)
|
||||
return false;
|
||||
} else if (!dataSourceType.equals(other.dataSourceType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.sap.sse.datamining.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sap.sse.common.Util.Pair;
|
||||
import com.sap.sse.datamining.DataRetrieverChainDefinition;
|
||||
|
||||
public class SimpleDataRetrieverChainDefinitionRegistry implements DataRetrieverChainDefinitionRegistry {
|
||||
|
||||
private Map<RegistrationKey, Collection<DataRetrieverChainDefinition<?>>> chainDefinitions;
|
||||
|
||||
public SimpleDataRetrieverChainDefinitionRegistry() {
|
||||
chainDefinitions = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DataRetrieverChainDefinition<?> raceRetrieverChainDefinition) {
|
||||
RegistrationKey key = new RegistrationKey(raceRetrieverChainDefinition.getDataSourceType(), raceRetrieverChainDefinition.getRetrievedDataType());
|
||||
if (!chainDefinitions.containsKey(key)) {
|
||||
chainDefinitions.put(key, new HashSet<DataRetrieverChainDefinition<?>>());
|
||||
}
|
||||
chainDefinitions.get(key).add(raceRetrieverChainDefinition);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <DataSourceType> Collection<DataRetrieverChainDefinition<DataSourceType>> getDataRetrieverChainDefinitions(
|
||||
Class<DataSourceType> dataSourceType, Class<?> retrievedDataType) {
|
||||
RegistrationKey key = new RegistrationKey(dataSourceType, retrievedDataType);
|
||||
return chainDefinitions.containsKey(key) ? (Collection<DataRetrieverChainDefinition<DataSourceType>>)(Collection<?>) chainDefinitions.get(key) : new HashSet<DataRetrieverChainDefinition<DataSourceType>>();
|
||||
}
|
||||
|
||||
private class RegistrationKey extends Pair<Class<?>, Class<?>> {
|
||||
private static final long serialVersionUID = 5351049808629967280L;
|
||||
|
||||
public RegistrationKey(Class<?> dataSourceType, Class<?> retrievedDataType) {
|
||||
super(dataSourceType, retrievedDataType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user