mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-22 12:03:58 +00:00
Implemented generic field access for BravoExtendedFixImpl by refactoring
most of the logic to a newly created SensorFixImpl
This commit is contained in:
1 parent
4f4d9a8792
commit
ff84262672
6 files changed
+73
-18
No files matched your search
+1
-1
@@ -13,7 +13,7 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* The first columns need to be consistent with {@link BravoSensorDataMetadata}.
|
* The first columns need to be consistent with {@link BravoSensorDataMetadata}.
|
||||||
*/
|
*/
|
||||||
public enum BravoExtendedSensorDataMetadata {
|
public enum BravoExtendedSensorDataMetadata implements ColumnMetadata {
|
||||||
RIDE_HEIGHT_PORT_HULL("RideHeightPort"), //
|
RIDE_HEIGHT_PORT_HULL("RideHeightPort"), //
|
||||||
RIDE_HEIGHT_STBD_HULL("RideHeightStbd"), //
|
RIDE_HEIGHT_STBD_HULL("RideHeightStbd"), //
|
||||||
HEEL("Heel"), //
|
HEEL("Heel"), //
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* The current implementation only stores a subset of the information available during the import.
|
* The current implementation only stores a subset of the information available during the import.
|
||||||
*/
|
*/
|
||||||
public enum BravoSensorDataMetadata {
|
public enum BravoSensorDataMetadata implements ColumnMetadata {
|
||||||
|
|
||||||
RIDE_HEIGHT_PORT_HULL("RideHeightPortHull"), //
|
RIDE_HEIGHT_PORT_HULL("RideHeightPortHull"), //
|
||||||
RIDE_HEIGHT_STBD_HULL("RideHeightStbdHull"), //
|
RIDE_HEIGHT_STBD_HULL("RideHeightStbdHull"), //
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.sap.sailing.domain.common.sensordata;
|
||||||
|
|
||||||
|
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
||||||
|
import com.sap.sailing.domain.common.tracking.SensorFix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition of column metadata used by {@link SensorFix} implementations to resolve columns in underlying
|
||||||
|
* {@link DoubleVectorFix DoubleVectorFixes}.
|
||||||
|
*/
|
||||||
|
public interface ColumnMetadata {
|
||||||
|
int getColumnIndex();
|
||||||
|
}
|
||||||
+10
@@ -3,9 +3,14 @@ package com.sap.sailing.domain.common.tracking.impl;
|
|||||||
import com.sap.sailing.domain.common.Bearing;
|
import com.sap.sailing.domain.common.Bearing;
|
||||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||||
import com.sap.sailing.domain.common.sensordata.BravoExtendedSensorDataMetadata;
|
import com.sap.sailing.domain.common.sensordata.BravoExtendedSensorDataMetadata;
|
||||||
|
import com.sap.sailing.domain.common.sensordata.ColumnMetadata;
|
||||||
import com.sap.sailing.domain.common.tracking.BravoExtendedFix;
|
import com.sap.sailing.domain.common.tracking.BravoExtendedFix;
|
||||||
|
import com.sap.sailing.domain.common.tracking.BravoFix;
|
||||||
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of {@link BravoExtendedFix}. {@link BravoExtendedFix} adds more measures compared to {@link BravoFix}.
|
||||||
|
*/
|
||||||
public class BravoExtendedFixImpl extends BravoFixImpl implements BravoExtendedFix {
|
public class BravoExtendedFixImpl extends BravoFixImpl implements BravoExtendedFix {
|
||||||
private static final long serialVersionUID = 5622321493028301922L;
|
private static final long serialVersionUID = 5622321493028301922L;
|
||||||
|
|
||||||
@@ -13,6 +18,11 @@ public class BravoExtendedFixImpl extends BravoFixImpl implements BravoExtendedF
|
|||||||
super(fix);
|
super(fix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ColumnMetadata resolveMetadataFromValueName(String valueName) {
|
||||||
|
return BravoExtendedSensorDataMetadata.byColumnName(valueName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getPortDaggerboardRake() {
|
public double getPortDaggerboardRake() {
|
||||||
return fix.get(BravoExtendedSensorDataMetadata.DB_RAKE_PORT.getColumnIndex());
|
return fix.get(BravoExtendedSensorDataMetadata.DB_RAKE_PORT.getColumnIndex());
|
||||||
|
|||||||
+5
-16
@@ -5,35 +5,24 @@ import com.sap.sailing.domain.common.Distance;
|
|||||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||||
import com.sap.sailing.domain.common.impl.MeterDistance;
|
import com.sap.sailing.domain.common.impl.MeterDistance;
|
||||||
import com.sap.sailing.domain.common.sensordata.BravoSensorDataMetadata;
|
import com.sap.sailing.domain.common.sensordata.BravoSensorDataMetadata;
|
||||||
|
import com.sap.sailing.domain.common.sensordata.ColumnMetadata;
|
||||||
import com.sap.sailing.domain.common.tracking.BravoFix;
|
import com.sap.sailing.domain.common.tracking.BravoFix;
|
||||||
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
||||||
import com.sap.sse.common.TimePoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link BravoFix} that wraps a {@link DoubleVectorFix} which holds the actual sensor data. The
|
* Implementation of {@link BravoFix} that wraps a {@link DoubleVectorFix} which holds the actual sensor data. The
|
||||||
* mapping metadata is stored in the {@link BravoSensorDataMetadata} enum.
|
* mapping metadata is stored in the {@link BravoSensorDataMetadata} enum.
|
||||||
*/
|
*/
|
||||||
public class BravoFixImpl implements BravoFix {
|
public class BravoFixImpl extends SensorFixImpl implements BravoFix {
|
||||||
private static final long serialVersionUID = 2033254212013221160L;
|
private static final long serialVersionUID = 2033254212013221160L;
|
||||||
protected final DoubleVectorFix fix;
|
|
||||||
|
|
||||||
public BravoFixImpl(DoubleVectorFix fix) {
|
public BravoFixImpl(DoubleVectorFix fix) {
|
||||||
this.fix = fix;
|
super(fix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double get(String valueName) {
|
protected ColumnMetadata resolveMetadataFromValueName(String valueName) {
|
||||||
BravoSensorDataMetadata colDefEnum = BravoSensorDataMetadata.byColumnName(valueName);
|
return BravoSensorDataMetadata.byColumnName(valueName);
|
||||||
if (colDefEnum == null) {
|
|
||||||
throw new IllegalArgumentException("Unknown value \"" + valueName + "\" for " + getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
int index = colDefEnum.getColumnIndex();
|
|
||||||
return fix.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TimePoint getTimePoint() {
|
|
||||||
return fix.getTimePoint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package com.sap.sailing.domain.common.tracking.impl;
|
||||||
|
|
||||||
|
import com.sap.sailing.domain.common.sensordata.ColumnMetadata;
|
||||||
|
import com.sap.sailing.domain.common.tracking.DoubleVectorFix;
|
||||||
|
import com.sap.sailing.domain.common.tracking.SensorFix;
|
||||||
|
import com.sap.sse.common.TimePoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract implementation of {@link SensorFix} that implements the generic value access through
|
||||||
|
* {@link SensorFixImpl#get(String)} by resolving a {@link ColumnMetadata} instance for a given valueName. The data is
|
||||||
|
* taken from the underlying {@link DoubleVectorFix} by using the column index taken from the resolved
|
||||||
|
* {@link ColumnMetadata} instance.
|
||||||
|
*/
|
||||||
|
public abstract class SensorFixImpl implements SensorFix {
|
||||||
|
private static final long serialVersionUID = -5815764620564953478L;
|
||||||
|
protected final DoubleVectorFix fix;
|
||||||
|
|
||||||
|
public SensorFixImpl(DoubleVectorFix fix) {
|
||||||
|
super();
|
||||||
|
assert fix != null;
|
||||||
|
this.fix = fix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimePoint getTimePoint() {
|
||||||
|
return fix.getTimePoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double get(String valueName) {
|
||||||
|
final ColumnMetadata columnMetadata = resolveMetadataFromValueName(valueName);
|
||||||
|
if (columnMetadata == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown value \"" + valueName + "\" for " + getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
int index = columnMetadata.getColumnIndex();
|
||||||
|
return fix.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be implemented by subclasses to resolve the associated {@link ColumnMetadata} for a given valueName. The
|
||||||
|
* result may be null if the given valueName is unknown for the fix implementation.
|
||||||
|
*/
|
||||||
|
protected abstract ColumnMetadata resolveMetadataFromValueName(String valueName);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user