mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 19:12:23 +00:00
Implemented Dimension (as GroupKey) and a CompoundGroupKey
This commit is contained in:
1 parent
b12de1f7c4
commit
b39337bc6d
5 files changed
+174
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package com.sap.sailing.datamining;
|
||||
|
||||
import com.sap.sailing.datamining.shared.GroupKey;
|
||||
|
||||
public interface Dimension extends GroupKey {
|
||||
|
||||
public enum Type {
|
||||
|
||||
RegattaName, RaceName, LegNumber,
|
||||
CourseArea,
|
||||
Fleet,
|
||||
BoatClassName,
|
||||
Year,
|
||||
LegType,
|
||||
CompetitorName,
|
||||
SailID,
|
||||
Nationality,
|
||||
WindStrength
|
||||
|
||||
}
|
||||
|
||||
public Type getType();
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.sap.sailing.datamining.impl;
|
||||
|
||||
import com.sap.sailing.datamining.shared.GroupKey;
|
||||
|
||||
public abstract class AbstractGroupKey implements GroupKey {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
|
||||
//Enforce hash code and equals in all subclasses
|
||||
@Override
|
||||
public abstract boolean equals(Object other);
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.sap.sailing.datamining.impl;
|
||||
|
||||
import com.sap.sailing.datamining.shared.GroupKey;
|
||||
|
||||
public class CompoundGroupKey extends AbstractGroupKey implements GroupKey {
|
||||
|
||||
private GroupKey mainKey;
|
||||
private GroupKey subKey;
|
||||
|
||||
public CompoundGroupKey(GroupKey mainKey) {
|
||||
this(mainKey, null);
|
||||
}
|
||||
|
||||
public CompoundGroupKey(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 getSubKey() {
|
||||
return subKey;
|
||||
}
|
||||
|
||||
public void setSubKey(GroupKey subKey) {
|
||||
this.subKey = subKey;
|
||||
}
|
||||
|
||||
@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;
|
||||
CompoundGroupKey other = (CompoundGroupKey) 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.sap.sailing.datamining.impl;
|
||||
|
||||
import com.sap.sailing.datamining.Dimension;
|
||||
import com.sap.sailing.datamining.shared.GroupKey;
|
||||
|
||||
public class DimensionImpl extends AbstractGroupKey implements Dimension {
|
||||
|
||||
private Type type;
|
||||
|
||||
public DimensionImpl(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return getType().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupKey getSubKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return type.equals(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return type.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,22 @@
|
||||
package com.sap.sailing.datamining.shared;
|
||||
|
||||
|
||||
public interface GroupKey {
|
||||
|
||||
/**
|
||||
* @return a string representation of this group key.
|
||||
*/
|
||||
public String asString();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* @return the sub key or null, if there's none.
|
||||
*/
|
||||
public GroupKey getSubKey();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user