mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 14:56:41 +00:00
Cleaned the CompoundGroupKey
A CompoundGroupKey is now represented as a main key and a list of sub keys.
This commit is contained in:
1 parent
81db7f7093
commit
ca8db4cc82
12 files changed
+170
-126
No files matched your search
+1
-1
@@ -159,7 +159,7 @@ public abstract class AbstractResultsPresenter<SettingsType extends Settings> im
|
||||
if (currentResult != null) {
|
||||
isSimple = true;
|
||||
for (GroupKey groupKey : getCurrentResult().getResults().keySet()) {
|
||||
if (groupKey.hasSubKey()) {
|
||||
if (groupKey.hasSubKeys()) {
|
||||
isSimple = false;
|
||||
break;
|
||||
}
|
||||
|
||||
+12
-1
@@ -36,6 +36,7 @@ import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.client.shared.controls.SimpleObjectRenderer;
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.CompoundGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.GenericGroupKey;
|
||||
import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent;
|
||||
|
||||
@@ -338,7 +339,17 @@ public class ResultsChart extends AbstractResultsPresenterWithDataProviders<Sett
|
||||
}
|
||||
|
||||
private GroupKey groupKeyToSeriesKey(GroupKey groupKey) {
|
||||
return groupKey.hasSubKey() ? groupKey.getSubKey() : simpleResultSeriesKey;
|
||||
if (groupKey.hasSubKeys()) {
|
||||
List<GroupKey> subKeys = groupKey.getSubKeys();
|
||||
GroupKey subMainKey = subKeys.get(0);
|
||||
List<GroupKey> subSubKeys = new ArrayList<>();
|
||||
for (int i = 1; i < subKeys.size(); i++) {
|
||||
subSubKeys.add(subKeys.get(i));
|
||||
}
|
||||
return subSubKeys.isEmpty() ? subMainKey : new CompoundGroupKey(subMainKey, subSubKeys);
|
||||
} else {
|
||||
return simpleResultSeriesKey;
|
||||
}
|
||||
}
|
||||
|
||||
private Chart createChart() {
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ public class CubicRegressionPerCourseProcessor implements
|
||||
GroupKey compoundKey;
|
||||
try {
|
||||
compoundKey = GroupKeyFactory.createNestingCompoundKeyFor(key, PolarDataDimensionCollectionFactory
|
||||
.getCubicRegressionPerCourseClusterKeyDimensions().iterator());
|
||||
.getCubicRegressionPerCourseClusterKeyDimensions());
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ public class SpeedRegressionPerAngleClusterProcessor implements
|
||||
GroupKey compoundKey;
|
||||
try {
|
||||
compoundKey = GroupKeyFactory.createNestingCompoundKeyFor(key, PolarDataDimensionCollectionFactory
|
||||
.getSpeedRegressionPerAngleClusterClusterKeyDimensions().iterator());
|
||||
.getSpeedRegressionPerAngleClusterClusterKeyDimensions());
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sap.sse.datamining.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface GroupKey extends Serializable, Comparable<GroupKey> {
|
||||
@@ -14,7 +15,7 @@ public interface GroupKey extends Serializable, Comparable<GroupKey> {
|
||||
* Checks if this group key has a sub key. For example if the data was grouped primary by competitor and secondary by leg type.
|
||||
* @return true, if this group key has a sub key
|
||||
*/
|
||||
public boolean hasSubKey();
|
||||
public boolean hasSubKeys();
|
||||
|
||||
/**
|
||||
* @return the main key, if there is one. Otherwise it returns <code>this</code>.
|
||||
@@ -22,8 +23,14 @@ public interface GroupKey extends Serializable, Comparable<GroupKey> {
|
||||
public GroupKey getMainKey();
|
||||
|
||||
/**
|
||||
* @return the sub key or null, if there's none.
|
||||
* @return the sub keys or an empty list, if there are none.
|
||||
*/
|
||||
public GroupKey getSubKey();
|
||||
public List<GroupKey> getSubKeys();
|
||||
|
||||
//Enforce hash code and equals in all subclasses
|
||||
@Override
|
||||
public abstract boolean equals(Object other);
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
}
|
||||
-6
@@ -15,11 +15,5 @@ public abstract class AbstractGroupKey implements GroupKey {
|
||||
public int compareTo(GroupKey key) {
|
||||
return asString().compareTo(key.asString());
|
||||
}
|
||||
|
||||
//Enforce hash code and equals in all subclasses
|
||||
@Override
|
||||
public abstract boolean equals(Object other);
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package com.sap.sse.datamining.shared.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
|
||||
|
||||
public class CompoundGroupKey extends AbstractGroupKey {
|
||||
|
||||
private static final long serialVersionUID = -7902450253393172550L;
|
||||
|
||||
private GroupKey mainKey;
|
||||
private ArrayList<GroupKey> subKeys;
|
||||
|
||||
/**
|
||||
* Constructor for the GWT-Serialization. Don't use this!
|
||||
*/
|
||||
@Deprecated
|
||||
CompoundGroupKey() { }
|
||||
|
||||
public CompoundGroupKey(GroupKey mainKey, List<GroupKey> subKeys) {
|
||||
if (mainKey == null) {
|
||||
throw new IllegalArgumentException("The mainKey mustn't be null");
|
||||
}
|
||||
|
||||
this.mainKey = mainKey;
|
||||
this.subKeys = new ArrayList<>(subKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder builder = new StringBuilder(mainKey.asString());
|
||||
for (GroupKey groupKey : subKeys) {
|
||||
builder.append("(" + groupKey.asString());
|
||||
}
|
||||
for (int i = 0; i < subKeys.size(); i++) {
|
||||
builder.append(")");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubKeys() {
|
||||
return !subKeys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupKey getMainKey() {
|
||||
return mainKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupKey> getSubKeys() {
|
||||
return Collections.unmodifiableList(subKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GroupKey key) {
|
||||
int result;
|
||||
if (key instanceof CompoundGroupKey) {
|
||||
CompoundGroupKey compoundGroupKey = (CompoundGroupKey) key;
|
||||
result = mainKey.compareTo(compoundGroupKey.mainKey);
|
||||
if (result == 0) {
|
||||
result = Integer.compare(subKeys.size(), compoundGroupKey.subKeys.size());
|
||||
if (result == 0) {
|
||||
for (int i = 0; i < subKeys.size(); i++) {
|
||||
result = subKeys.get(i).compareTo(compoundGroupKey.subKeys.get(i));
|
||||
if (result != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = super.compareTo(key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((mainKey == null) ? 0 : mainKey.hashCode());
|
||||
result = prime * result + ((subKeys == null) ? 0 : subKeys.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;
|
||||
CompoundGroupKey other = (CompoundGroupKey) obj;
|
||||
if (mainKey == null) {
|
||||
if (other.mainKey != null)
|
||||
return false;
|
||||
} else if (!mainKey.equals(other.mainKey))
|
||||
return false;
|
||||
if (subKeys == null) {
|
||||
if (other.subKeys != null)
|
||||
return false;
|
||||
} else if (!subKeys.equals(other.subKeys))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -1,6 +1,8 @@
|
||||
package com.sap.sse.datamining.shared.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
@@ -26,7 +28,7 @@ public class GenericGroupKey<T> extends AbstractGroupKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubKey() {
|
||||
public boolean hasSubKeys() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,8 +38,8 @@ public class GenericGroupKey<T> extends AbstractGroupKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupKey getSubKey() {
|
||||
return null;
|
||||
public List<GroupKey> getSubKeys() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
package com.sap.sse.datamining.shared.impl;
|
||||
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
|
||||
|
||||
public class NestingCompoundGroupKey extends AbstractGroupKey {
|
||||
|
||||
private static final long serialVersionUID = -7902450253393172550L;
|
||||
|
||||
private GroupKey mainKey;
|
||||
private GroupKey subKey;
|
||||
|
||||
/**
|
||||
* Constructor for the GWT-Serialization. Don't use this!
|
||||
*/
|
||||
@Deprecated
|
||||
NestingCompoundGroupKey() { }
|
||||
|
||||
public NestingCompoundGroupKey(GroupKey mainKey) {
|
||||
this(mainKey, null);
|
||||
}
|
||||
|
||||
public NestingCompoundGroupKey(GroupKey mainKey, GroupKey subKey) {
|
||||
this.mainKey = mainKey;
|
||||
this.subKey = subKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return mainKey.asString() + " (" + subKey.asString() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubKey() {
|
||||
return subKey != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupKey getMainKey() {
|
||||
return mainKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupKey getSubKey() {
|
||||
return subKey;
|
||||
}
|
||||
|
||||
public void setSubKey(GroupKey subKey) {
|
||||
this.subKey = subKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GroupKey key) {
|
||||
int result = super.compareTo(key);
|
||||
if (key instanceof NestingCompoundGroupKey) {
|
||||
NestingCompoundGroupKey nestingCompoundGroupKey = (NestingCompoundGroupKey) key;
|
||||
result = mainKey.compareTo(nestingCompoundGroupKey.mainKey);
|
||||
if (result == 0) {
|
||||
result = subKey.compareTo(nestingCompoundGroupKey.subKey);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((mainKey == null) ? 0 : mainKey.hashCode());
|
||||
result = prime * result + ((subKey == null) ? 0 : subKey.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;
|
||||
NestingCompoundGroupKey other = (NestingCompoundGroupKey) obj;
|
||||
if (mainKey == null) {
|
||||
if (other.mainKey != null)
|
||||
return false;
|
||||
} else if (!mainKey.equals(other.mainKey))
|
||||
return false;
|
||||
if (subKey == null) {
|
||||
if (other.subKey != null)
|
||||
return false;
|
||||
} else if (!subKey.equals(other.subKey))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+4
-3
@@ -19,7 +19,7 @@ import com.sap.sse.datamining.impl.functions.MethodWrappingFunction;
|
||||
import com.sap.sse.datamining.impl.functions.SimpleParameterizedFunction;
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.GenericGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.NestingCompoundGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.CompoundGroupKey;
|
||||
import com.sap.sse.datamining.test.util.ComponentTestsUtil;
|
||||
import com.sap.sse.datamining.test.util.ConcurrencyTestsUtil;
|
||||
import com.sap.sse.datamining.test.util.FunctionTestsUtil;
|
||||
@@ -84,8 +84,9 @@ public class TestParallelMultiDimensionalGroupingProcessor {
|
||||
|
||||
private void verifyGroupedElement(Number originElement) {
|
||||
GroupKey mainKey = new GenericGroupKey<Object>(originElement.getLength());
|
||||
GroupKey subKey = new GenericGroupKey<Object>(originElement.getCrossSum());
|
||||
GroupKey expectedKey = new NestingCompoundGroupKey(mainKey, subKey);
|
||||
List<GroupKey> subKeys = new ArrayList<>();
|
||||
subKeys.add(new GenericGroupKey<Object>(originElement.getCrossSum()));
|
||||
GroupKey expectedKey = new CompoundGroupKey(mainKey, subKeys);
|
||||
assertThat(groupedElement.getKey(), is(expectedKey));
|
||||
}
|
||||
|
||||
|
||||
+13
-5
@@ -1,21 +1,29 @@
|
||||
package com.sap.sse.datamining.factories;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.CompoundGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.GenericGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.NestingCompoundGroupKey;
|
||||
|
||||
public class GroupKeyFactory {
|
||||
|
||||
public static <DataType> GroupKey createNestingCompoundKeyFor(DataType input, Iterator<Function<?>> dimensionsIterator) {
|
||||
public static <DataType> GroupKey createNestingCompoundKeyFor(DataType input, Iterable<Function<?>> dimensions) {
|
||||
Iterator<Function<?>> dimensionsIterator = dimensions.iterator();
|
||||
|
||||
Function<?> mainDimension = dimensionsIterator.next();
|
||||
GroupKey key = createDimensionValueGroupKeyFor(input, mainDimension);
|
||||
GroupKey mainKey = createDimensionValueGroupKeyFor(input, mainDimension);
|
||||
List<GroupKey> subKeys = new ArrayList<>();
|
||||
if (dimensionsIterator.hasNext()) {
|
||||
key = new NestingCompoundGroupKey(key, createNestingCompoundKeyFor(input, dimensionsIterator));
|
||||
while (dimensionsIterator.hasNext()) {
|
||||
Function<?> dimension = dimensionsIterator.next();
|
||||
subKeys.add(createDimensionValueGroupKeyFor(input, dimension));
|
||||
}
|
||||
}
|
||||
return key;
|
||||
return subKeys.isEmpty() ? mainKey : new CompoundGroupKey(mainKey, subKeys);
|
||||
}
|
||||
|
||||
public static <DataType> GroupKey createDimensionValueGroupKeyFor(DataType input, Function<?> mainDimension) {
|
||||
|
||||
+10
-4
@@ -1,7 +1,9 @@
|
||||
package com.sap.sse.datamining.impl.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import com.sap.sse.datamining.components.AdditionalResultDataBuilder;
|
||||
@@ -11,7 +13,7 @@ import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.functions.ParameterProvider;
|
||||
import com.sap.sse.datamining.functions.ParameterizedFunction;
|
||||
import com.sap.sse.datamining.shared.GroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.NestingCompoundGroupKey;
|
||||
import com.sap.sse.datamining.shared.impl.CompoundGroupKey;
|
||||
|
||||
public abstract class AbstractParallelMultiDimensionalNestingGroupingProcessor<DataType>
|
||||
extends AbstractParallelProcessor<DataType, GroupedDataEntry<DataType>> {
|
||||
@@ -62,11 +64,15 @@ public abstract class AbstractParallelMultiDimensionalNestingGroupingProcessor<D
|
||||
|
||||
private GroupKey createCompoundKeyFor(DataType input, Iterator<ParameterizedFunction<?>> dimensionsIterator) {
|
||||
ParameterizedFunction<?> mainDimension = dimensionsIterator.next();
|
||||
GroupKey key = createGroupKeyFor(input, mainDimension.getFunction(), mainDimension.getParameterProvider());
|
||||
GroupKey mainKey = createGroupKeyFor(input, mainDimension.getFunction(), mainDimension.getParameterProvider());
|
||||
List<GroupKey> subKeys = new ArrayList<>();
|
||||
if (dimensionsIterator.hasNext()) {
|
||||
key = new NestingCompoundGroupKey(key, createCompoundKeyFor(input, dimensionsIterator));
|
||||
while (dimensionsIterator.hasNext()) {
|
||||
ParameterizedFunction<?> dimension = dimensionsIterator.next();
|
||||
subKeys.add(createGroupKeyFor(input, dimension.getFunction(), dimension.getParameterProvider()));
|
||||
}
|
||||
}
|
||||
return key;
|
||||
return subKeys.isEmpty() ? mainKey : new CompoundGroupKey(mainKey, subKeys);
|
||||
}
|
||||
|
||||
protected abstract GroupKey createGroupKeyFor(DataType input, Function<?> dimension, ParameterProvider parameterProvider);
|
||||
|
||||
Reference in new issue
Block a user