Skip to content

Commit

Permalink
Use generic type to differentiate between RequestMetaData context
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Jun 24, 2024
1 parent b496823 commit 16a8792
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import de.cyface.deserializer.exceptions.InvalidLifecycleEvents;
import de.cyface.model.Measurement;
import de.cyface.model.MeasurementIdentifier;
import de.cyface.model.MetaData;
import de.cyface.model.RequestMetaData;

/**
* A {@link Deserializer} for a file in Cyface binary format. Constructs a new measurement from a ZLIB compressed
Expand Down Expand Up @@ -62,7 +62,7 @@ public class BinaryFormatDeserializer implements Deserializer {
* The meta information about the {@link Measurement}. This information is not part of the datafiles but is usually
* stored alongside the binary data. It is usually used to get a glimpse into what data to expect.
*/
private final MetaData metaData;
private final RequestMetaData metaData;
/**
* The stream of compressed data to load locations and measured data points from
*/
Expand All @@ -77,7 +77,7 @@ public class BinaryFormatDeserializer implements Deserializer {
* expect
* @param compressedData The stream of compressed data to load locations and measured data points from
*/
BinaryFormatDeserializer(final MetaData metaData, final InputStream compressedData) {
BinaryFormatDeserializer(final RequestMetaData metaData, final InputStream compressedData) {
this.metaData = Objects.requireNonNull(metaData);
this.compressedData = Objects.requireNonNull(compressedData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.UUID;

import de.cyface.model.MetaData;
import de.cyface.model.RequestMetaData;

/**
* A collection of static factory methods to hide the possible complexity of {@link Deserializer} creation.
Expand All @@ -45,7 +45,7 @@ private DeserializerFactory() {
/**
* Create a new {@link Deserializer} for a {@link de.cyface.model.Measurement} in Cyface Binary data with its
* accompanying events.
* Both are provided as compressed input streams, together with the {@link MetaData} about the
* Both are provided as compressed input streams, together with the {@link RequestMetaData} about the
* <code>Measurement</code>.
*
* @param metaData The meta information about the <code>Measurement</code> to load
Expand All @@ -54,7 +54,7 @@ private DeserializerFactory() {
* @return A <code>Deserializer</code> for the Cyface binary format
* @throws IOException When writing data failed
*/
public static BinaryFormatDeserializer create(final MetaData metaData, final InputStream compressedDataStream) throws IOException {
public static BinaryFormatDeserializer create(final RequestMetaData metaData, final InputStream compressedDataStream) throws IOException {
return new BinaryFormatDeserializer(metaData, compressedDataStream);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import de.cyface.model.Event;
import de.cyface.model.Measurement;
import de.cyface.model.MeasurementIdentifier;
import de.cyface.model.MetaData;
import de.cyface.model.RequestMetaData;
import de.cyface.model.Modality;
import de.cyface.model.Point3DImpl;
import de.cyface.model.RawRecord;
Expand Down Expand Up @@ -253,7 +253,7 @@ private List<Event> queryForEvents(final Connection connection, final Measuremen
* default values
* @throws SQLException If the query was not successful
*/
private MetaData queryForMetaData(final Connection connection, final long measurementNumber) throws SQLException {
private RequestMetaData queryForMetaData(final Connection connection, final long measurementNumber) throws SQLException {
final var deviceIdentifierQuery = connection.prepareStatement(DEVICE_IDENTIFIER_QUERY);

final var deviceIdentifierResultSet = deviceIdentifierQuery.executeQuery();
Expand All @@ -268,7 +268,7 @@ private MetaData queryForMetaData(final Connection connection, final long measur
final var lengthResultSet = lengthQuery.executeQuery();
lengthResultSet.next();
final var length = lengthResultSet.getDouble(1);
return new MetaData(measurementIdentifier, deviceType, osVersion, appVersion, length, userId, MetaData.CURRENT_VERSION);
return new RequestMetaData(measurementIdentifier, deviceType, osVersion, appVersion, length, userId, RequestMetaData.CURRENT_VERSION);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import de.cyface.deserializer.exceptions.InvalidLifecycleEvents;
import de.cyface.model.Event;
import de.cyface.model.MeasurementIdentifier;
import de.cyface.model.MetaData;
import de.cyface.model.RequestMetaData;
import de.cyface.model.Modality;
import de.cyface.model.Point3D;
import de.cyface.model.Point3DImpl;
Expand Down Expand Up @@ -112,9 +112,9 @@ void test() throws IOException, InvalidLifecycleEvents, UnsupportedFileVersion {
// Arrange
final var identifier = new MeasurementIdentifier("test", 1);
try (final var testData = testData(identifier)) {
final var metaData = new MetaData(identifier, "Pixel 3", "Android 9.0.0", "1.2.0-beta1", 500.5,
final var metaData = new RequestMetaData(identifier, "Pixel 3", "Android 9.0.0", "1.2.0-beta1", 500.5,
TEST_USER_ID,
MetaData.CURRENT_VERSION);
RequestMetaData.CURRENT_VERSION);
final var reader = new BinaryFormatDeserializer(metaData, testData);

// Act
Expand All @@ -128,7 +128,7 @@ void test() throws IOException, InvalidLifecycleEvents, UnsupportedFileVersion {
assertThat(result.getMetaData().getAppVersion(), is("1.2.0-beta1"));
assertThat(result.getMetaData().getLength(), is(500.5));
assertThat(result.getMetaData().getUserId(), is(TEST_USER_ID));
assertThat(result.getMetaData().getVersion(), is(MetaData.CURRENT_VERSION));
assertThat(result.getMetaData().getVersion(), is(RequestMetaData.CURRENT_VERSION));

final var resultTracks = result.getTracks();
assertThat(resultTracks, hasSize(3));
Expand Down Expand Up @@ -336,8 +336,8 @@ void testSerializeDeserialize() throws IOException, InvalidLifecycleEvents {
final var directions = Point3DDeserializer
.directions(parsedMeasurement.getDirectionsBinary().getDirectionsList());
final var trackBuilder = new TrackBuilder();
final var metaData = new MetaData(identifier, "Pixel 3", "Android 12.0.0", "3.0.2", 0.0,
TEST_USER_ID, MetaData.CURRENT_VERSION);
final var metaData = new RequestMetaData(identifier, "Pixel 3", "Android 12.0.0", "3.0.2", 0.0,
TEST_USER_ID, RequestMetaData.CURRENT_VERSION);
final var tracks = trackBuilder.build(deserializedLocations, deserializedEvents, accelerations, rotations,
directions, identifier);
final var deserializedMeasurement = new de.cyface.model.Measurement(metaData, tracks);
Expand Down
14 changes: 7 additions & 7 deletions libs/model/src/main/java/de/cyface/model/Measurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Measurement implements Serializable {
/**
* The context of this {@code Measurement}.
*/
private MetaData metaData;
private RequestMetaData metaData;
/**
* The data collected for this {@code Measurement} in {@code Track}-slices, ordered by timestamp.
*/
Expand All @@ -88,7 +88,7 @@ public Measurement() {
* @param metaData The context of this {@code Measurement}.
* @param tracks The data collected for this {@code Measurement} in {@code Track}-slices, ordered by timestamp.
*/
public Measurement(final MetaData metaData, final List<Track> tracks) {
public Measurement(final RequestMetaData metaData, final List<Track> tracks) {
Validate.notNull(metaData);

this.metaData = metaData;
Expand Down Expand Up @@ -156,7 +156,7 @@ private List<Track> tracks(final List<TrackBucket> trackBuckets) {
/**
* @return The context of this {@code Measurement}.
*/
public MetaData getMetaData() {
public RequestMetaData getMetaData() {
return metaData;
}

Expand All @@ -173,7 +173,7 @@ public List<Track> getTracks() {
* @param metaData The context of this {@code Measurement}.
*/
@SuppressWarnings("unused") // Required by Apache Flink.
public void setMetaData(final MetaData metaData) {
public void setMetaData(final RequestMetaData metaData) {
this.metaData = metaData;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ public void asJson(final String username, final Consumer<String> handler) {
handler.accept("}");
}

private Json.JsonObject asJson(final String username, final MetaData metaData) {
private Json.JsonObject asJson(final String username, final RequestMetaData metaData) {
return jsonObject(
jsonKeyValue("userId", metaData.getUserId().toString()),
jsonKeyValue("username", username),
Expand Down Expand Up @@ -511,7 +511,7 @@ public static void csvHeader(final ExportOptions options, final Consumer<String>
* @param totalTravelTime the time traveled so far
* @return the csv row as String
*/
private String csvRow(ExportOptions options, final String username, final MetaData metaData,
private String csvRow(ExportOptions options, final String username, final RequestMetaData metaData,
final RawRecord locationRecord,
final int trackId, final double modalityTypeDistance, final double totalDistance,
final long modalityTypeTravelTime, final long totalTravelTime) {
Expand Down Expand Up @@ -539,7 +539,7 @@ private String csvRow(ExportOptions options, final String username, final MetaDa
return String.join(",", elements);
}

private String csvSensorRow(ExportOptions options, final String username, final MetaData metaData,
private String csvSensorRow(ExportOptions options, final String username, final RequestMetaData metaData,
final Point3DImpl pointRecord,
final int trackId) {

Expand Down
4 changes: 2 additions & 2 deletions libs/model/src/main/java/de/cyface/model/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MetaData implements Serializable {
*/
public static final String CURRENT_VERSION = "3.0.0";
/**
* Regex of supported {@link MetaData} versions of this class.
* Regex of supported {@link RequestMetaData} versions of this class.
*/
public static final String SUPPORTED_VERSIONS = "3.0.0";
/**
Expand Down Expand Up @@ -244,7 +244,7 @@ public boolean equals(Object o) {
return true;
if (o == null || getClass() != o.getClass())
return false;
MetaData metaData = (MetaData)o;
RequestMetaData metaData = (RequestMetaData)o;
return Double.compare(metaData.length, length) == 0 &&
identifier.equals(metaData.identifier) &&
deviceType.equals(metaData.deviceType) &&
Expand Down
12 changes: 6 additions & 6 deletions libs/model/src/main/java/de/cyface/model/TrackBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public class TrackBucket {
*/
final Track track;
/**
* The {@link MetaData} of the track.
* The {@link RequestMetaData} of the track.
*/
final MetaData metaData;
final RequestMetaData metaData;

/**
* Initialized a fully constructed instance of this class.
*
* @param trackId The track's position within the measurement.
* @param bucket The time "slice" of the bucket.
* @param track The track slice of the bucket.
* @param metaData The {@link MetaData} of the track.
* @param metaData The {@link RequestMetaData} of the track.
*/
public TrackBucket(final int trackId, final Date bucket, final Track track, final MetaData metaData) {
public TrackBucket(final int trackId, final Date bucket, final Track track, final RequestMetaData metaData) {
this.trackId = trackId;
this.bucket = bucket;
this.track = track;
Expand Down Expand Up @@ -84,9 +84,9 @@ public Track getTrack() {
}

/**
* @return The {@link MetaData} of the track.
* @return The {@link RequestMetaData} of the track.
*/
public MetaData getMetaData() {
public RequestMetaData getMetaData() {
return metaData;
}
}
Loading

0 comments on commit 16a8792

Please sign in to comment.