From c359918370555c2f800e5e7ec90746ced87ff781 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 26 Sep 2023 12:22:35 +0200 Subject: [PATCH 1/8] Convert to kotlin --- .../src/main/java/de/cyface/model/Track.java | 209 ------------------ .../de/cyface/model/Activation.kt | 0 .../de/cyface/model/Point3D.kt | 0 .../src/main/kotlin/de/cyface/model/Track.kt | 204 +++++++++++++++++ 4 files changed, 204 insertions(+), 209 deletions(-) delete mode 100644 libs/model/src/main/java/de/cyface/model/Track.java rename libs/model/src/main/{java => kotlin}/de/cyface/model/Activation.kt (100%) rename libs/model/src/main/{java => kotlin}/de/cyface/model/Point3D.kt (100%) create mode 100644 libs/model/src/main/kotlin/de/cyface/model/Track.kt diff --git a/libs/model/src/main/java/de/cyface/model/Track.java b/libs/model/src/main/java/de/cyface/model/Track.java deleted file mode 100644 index fe07d71..0000000 --- a/libs/model/src/main/java/de/cyface/model/Track.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright 2019-2021 Cyface GmbH - * - * This file is part of the Serialization. - * - * The Serialization is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Serialization is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Serialization. If not, see . - */ -package de.cyface.model; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * A part of a measurement for which continuous data is available and ordered by time. - *

- * A {@code Track} begins with the first {@code GeoLocation} collected after start or resume was triggered during data - * collection. It stops with the last collected {@code GeoLocation} before the next resume command was triggered or - * when the very last locations is reached. - * - * @author Armin Schnabel - * @version 2.0.0 - * @since 1.0.0 - */ -public class Track implements Serializable { - - /** - * Used to serialize objects of this class. Only change this value if this classes attribute set changes. - */ - private static final long serialVersionUID = 5614152745515907995L; - /** - * The list of {@code GeoLocationRecord}s collected for this {@code Track} ordered by timestamp. - */ - private List locationRecords; - /** - * The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - */ - private List accelerations; - /** - * The list of rotations for this {@code Track} ordered by timestamp. Unit: rad/s. - */ - private List rotations; - /** - * The list of directions for this {@code Track} ordered by timestamp. Unit. micro-Tesla (uT). - */ - private List directions; - - /** - * Creates a new completely initialized {@code Track}. - * - * @param locationRecords The list of {@code RawRecord}s collected for this {@code Track} ordered by - * timestamp. - * @param accelerations The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - * @param rotations The list of rotations for this {@code Track} ordered by timestamp. Unit: rad/s. - * @param directions The list of directions for this {@code Track} ordered by timestamp. Unit. micro-Tesla (uT). - */ - public Track(final List locationRecords, final List accelerations, - final List rotations, final List directions) { - Objects.requireNonNull(locationRecords); - Objects.requireNonNull(accelerations); - Objects.requireNonNull(rotations); - Objects.requireNonNull(directions); - - this.locationRecords = new ArrayList<>(locationRecords); - this.accelerations = new ArrayList<>(accelerations); - this.rotations = new ArrayList<>(rotations); - this.directions = new ArrayList<>(directions); - } - - /** - * No argument constructor as required by Apache Flink. Do not use this in your own code. - */ - public Track() { - // Nothing to do - } - - /** - * @return The list of {@code GeoLocationRecord}s collected for this {@code Track} ordered by timestamp. - */ - public List getLocationRecords() { - return Collections.unmodifiableList(locationRecords); - } - - /** - * @return The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - */ - public List getAccelerations() { - return Collections.unmodifiableList(accelerations); - } - - /** - * @return The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - */ - public List getRotations() { - return Collections.unmodifiableList(rotations); - } - - /** - * @return The list of directions for this {@code Track} ordered by timestamp. Unit. micro-Tesla (uT). - */ - public List getDirections() { - return Collections.unmodifiableList(directions); - } - - /** - * Required by Apache Flink. - * - * @param locationRecords The list of {@code GeoLocationRecord}s collected for this {@code Track} ordered by - * timestamp. - */ - public void setLocationRecords(final List locationRecords) { - Objects.requireNonNull(locationRecords); - - this.locationRecords = new ArrayList<>(locationRecords); - } - - /** - * Required by Apache Flink. - * - * @param accelerations The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - */ - public void setAccelerations(final List accelerations) { - Objects.requireNonNull(locationRecords); - - this.accelerations = new ArrayList<>(accelerations); - } - - /** - * Required by Apache Flink. - * - * @param rotations The list of accelerations for this {@code Track} ordered by timestamp. Unit: m/s². - */ - public void setRotations(final List rotations) { - Objects.requireNonNull(locationRecords); - - this.rotations = new ArrayList<>(rotations); - } - - /** - * Required by Apache Flink. - * - * @param directions The list of directions for this {@code Track} ordered by timestamp. Unit. micro-Tesla (uT). - */ - public void setDirections(final List directions) { - Objects.requireNonNull(locationRecords); - - this.directions = new ArrayList<>(directions); - } - - /** - * Removes all data after the provided timestamp from this Track. - * - * @param timestamp A UNIX timestamp in milliseconds since the first of January 1970 - * @return This track for method chaining - */ - public Track clearAfter(final long timestamp) { - locationRecords = locationRecords.stream().filter(record -> record.getTimestamp() >= timestamp) - .collect(Collectors.toList()); - accelerations = accelerations.stream().filter(acceleration -> acceleration.getTimestamp() > timestamp) - .collect(Collectors.toList()); - rotations = rotations.stream().filter(rotation -> rotation.getTimestamp() > timestamp) - .collect(Collectors.toList()); - directions = directions.stream().filter(direction -> direction.getTimestamp() > timestamp) - .collect(Collectors.toList()); - return this; - } - - @Override - public String toString() { - return "Track{" + - "geoLocations=" + locationRecords + - ", accelerations=" + accelerations + - ", rotations=" + rotations + - ", directions=" + directions + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Track track = (Track)o; - return locationRecords.equals(track.locationRecords) && - accelerations.equals(track.accelerations) && - rotations.equals(track.rotations) && - directions.equals(track.directions); - } - - @Override - public int hashCode() { - return Objects.hash(locationRecords, accelerations, rotations, directions); - } -} diff --git a/libs/model/src/main/java/de/cyface/model/Activation.kt b/libs/model/src/main/kotlin/de/cyface/model/Activation.kt similarity index 100% rename from libs/model/src/main/java/de/cyface/model/Activation.kt rename to libs/model/src/main/kotlin/de/cyface/model/Activation.kt diff --git a/libs/model/src/main/java/de/cyface/model/Point3D.kt b/libs/model/src/main/kotlin/de/cyface/model/Point3D.kt similarity index 100% rename from libs/model/src/main/java/de/cyface/model/Point3D.kt rename to libs/model/src/main/kotlin/de/cyface/model/Point3D.kt diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt new file mode 100644 index 0000000..550c9d9 --- /dev/null +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -0,0 +1,204 @@ +/* + * Copyright 2019-2021 Cyface GmbH + * + * This file is part of the Serialization. + * + * The Serialization is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Serialization is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the Serialization. If not, see . + */ +package de.cyface.model + +import java.io.Serializable +import java.util.Collections +import java.util.Objects +import java.util.stream.Collectors + +/** + * A part of a measurement for which continuous data is available and ordered by time. + * + * A `Track` begins with the first `GeoLocation` collected after start or resume was triggered during data + * collection. It stops with the last collected `GeoLocation` before the next resume command was triggered or + * when the very last locations is reached. + * + * @author Armin Schnabel + * @version 2.0.1 + * @since 1.0.0 + */ +class Track : Serializable { + /** + * The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. + */ + private lateinit var locationRecords: List + + /** + * The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + */ + private lateinit var accelerations: List + + /** + * The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. + */ + private lateinit var rotations: List + + /** + * The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). + */ + private lateinit var directions: List + + /** + * Creates a new completely initialized `Track`. + * + * @param locationRecords The list of `RawRecord`s collected for this `Track` ordered by + * timestamp. + * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + * @param rotations The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. + * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). + */ + constructor( + locationRecords: List, accelerations: List, + rotations: List, directions: List + ) { + Objects.requireNonNull(locationRecords) + Objects.requireNonNull(accelerations) + Objects.requireNonNull(rotations) + Objects.requireNonNull(directions) + this.locationRecords = ArrayList(locationRecords) + this.accelerations = ArrayList(accelerations) + this.rotations = ArrayList(rotations) + this.directions = ArrayList(directions) + } + + /** + * No argument constructor as required by Apache Flink. Do not use this in your own code. + */ + constructor() { + // Nothing to do + } + + /** + * @return The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. + */ + fun getLocationRecords(): List { + return Collections.unmodifiableList(locationRecords) + } + + /** + * @return The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + */ + fun getAccelerations(): List { + return Collections.unmodifiableList(accelerations) + } + + /** + * @return The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + */ + fun getRotations(): List { + return Collections.unmodifiableList(rotations) + } + + /** + * @return The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). + */ + fun getDirections(): List { + return Collections.unmodifiableList(directions) + } + + /** + * Required by Apache Flink. + * + * @param locationRecords The list of `GeoLocationRecord`s collected for this `Track` ordered by + * timestamp. + */ + fun setLocationRecords(locationRecords: List) { + Objects.requireNonNull(locationRecords) + this.locationRecords = ArrayList(locationRecords) + } + + /** + * Required by Apache Flink. + * + * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + */ + fun setAccelerations(accelerations: List) { + Objects.requireNonNull(locationRecords) + this.accelerations = ArrayList(accelerations) + } + + /** + * Required by Apache Flink. + * + * @param rotations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + */ + fun setRotations(rotations: List) { + Objects.requireNonNull(locationRecords) + this.rotations = ArrayList(rotations) + } + + /** + * Required by Apache Flink. + * + * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). + */ + fun setDirections(directions: List) { + Objects.requireNonNull(locationRecords) + this.directions = ArrayList(directions) + } + + /** + * Removes all data after the provided `timestamp` from this `Track`. + * + * @param timestamp A UNIX timestamp in milliseconds since the first of January 1970 + * @return This track for method chaining + */ + fun clearAfter(timestamp: Long): Track { + locationRecords = locationRecords.stream().filter { record: RawRecord -> record.timestamp >= timestamp } + .collect(Collectors.toList()) + accelerations = accelerations.stream() + .filter { acceleration: Point3DImpl -> acceleration.timestamp > timestamp } + .collect(Collectors.toList()) + rotations = rotations.stream() + .filter { rotation: Point3DImpl -> rotation.timestamp > timestamp } + .collect(Collectors.toList()) + directions = directions.stream() + .filter { direction: Point3DImpl -> direction.timestamp > timestamp } + .collect(Collectors.toList()) + return this + } + + override fun toString(): String { + return "Track{" + + "geoLocations=" + locationRecords + + ", accelerations=" + accelerations + + ", rotations=" + rotations + + ", directions=" + directions + + '}' + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || javaClass != other.javaClass) return false + val track = other as Track + return locationRecords == track.locationRecords && accelerations == track.accelerations && rotations == track.rotations && directions == track.directions + } + + override fun hashCode(): Int { + return Objects.hash(locationRecords, accelerations, rotations, directions) + } + + companion object { + /** + * Used to serialize objects of this class. Only change this value if this classes attribute set changes. + */ + private const val serialVersionUID = 5614152745515907995L + } +} \ No newline at end of file From e409173e3cade6825c77347e1d7da527f331d610 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 26 Sep 2023 12:31:24 +0200 Subject: [PATCH 2/8] [RFR-733] Add clearFor method and refactor clearAfter method --- .../src/main/kotlin/de/cyface/model/Track.kt | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt index 550c9d9..df38bff 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/Track.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -21,7 +21,6 @@ package de.cyface.model import java.io.Serializable import java.util.Collections import java.util.Objects -import java.util.stream.Collectors /** * A part of a measurement for which continuous data is available and ordered by time. @@ -31,29 +30,29 @@ import java.util.stream.Collectors * when the very last locations is reached. * * @author Armin Schnabel - * @version 2.0.1 + * @version 2.1.0 * @since 1.0.0 */ class Track : Serializable { /** * The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. */ - private lateinit var locationRecords: List + private lateinit var locationRecords: MutableList /** * The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². */ - private lateinit var accelerations: List + private lateinit var accelerations: MutableList /** * The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. */ - private lateinit var rotations: List + private lateinit var rotations: MutableList /** * The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). */ - private lateinit var directions: List + private lateinit var directions: MutableList /** * Creates a new completely initialized `Track`. @@ -161,20 +160,40 @@ class Track : Serializable { * @return This track for method chaining */ fun clearAfter(timestamp: Long): Track { - locationRecords = locationRecords.stream().filter { record: RawRecord -> record.timestamp >= timestamp } - .collect(Collectors.toList()) - accelerations = accelerations.stream() - .filter { acceleration: Point3DImpl -> acceleration.timestamp > timestamp } - .collect(Collectors.toList()) - rotations = rotations.stream() - .filter { rotation: Point3DImpl -> rotation.timestamp > timestamp } - .collect(Collectors.toList()) - directions = directions.stream() - .filter { direction: Point3DImpl -> direction.timestamp > timestamp } - .collect(Collectors.toList()) + locationRecords.removeIf { it.timestamp < timestamp } + accelerations.removeIf { it.timestamp <= timestamp } + rotations.removeIf { it.timestamp <= timestamp } + directions.removeIf { it.timestamp <= timestamp } return this } + /** + * Removes a specific location and all sensor data that fall between this location and the previous valid location. + * + * @param location The location to remove. + * @return This track for method chaining. + */ + fun clearFor(location: RawRecord): Track { + // Find the index of the location to remove + val locationIndex = locationRecords.indexOf(location) + if (locationIndex == -1) throw IllegalStateException("Location not found: $location") //return this + + // Determine the timestamp range for which sensor data should be removed + val startTimestamp = if (locationIndex > 0) locationRecords[locationIndex - 1].timestamp else 0L + val endTimestamp = location.timestamp + + // Remove the location + locationRecords.remove(location) + + // Remove sensor data that falls within the determined timestamp range + accelerations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + rotations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + directions.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + + return this + } + + override fun toString(): String { return "Track{" + "geoLocations=" + locationRecords + From 5c622e977c757cc4c464b61f0a07c325ce576984 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 26 Sep 2023 13:02:21 +0200 Subject: [PATCH 3/8] Convert to kotlin --- .../java/de/cyface/model/CalibrationJob.java | 136 ------------------ .../kotlin/de/cyface/model/CalibrationJob.kt | 110 ++++++++++++++ .../src/main/kotlin/de/cyface/model/Track.kt | 1 + 3 files changed, 111 insertions(+), 136 deletions(-) delete mode 100644 libs/model/src/main/java/de/cyface/model/CalibrationJob.java create mode 100644 libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt diff --git a/libs/model/src/main/java/de/cyface/model/CalibrationJob.java b/libs/model/src/main/java/de/cyface/model/CalibrationJob.java deleted file mode 100644 index 1c7f95c..0000000 --- a/libs/model/src/main/java/de/cyface/model/CalibrationJob.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2022-2023 Cyface GmbH - * - * This file is part of the Serialization. - * - * The Serialization is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Serialization is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Serialization. If not, see . - */ -package de.cyface.model; - -import java.util.UUID; - -/** - * A {@link Job} which contains details about filtered data during calibration. - * - * @author Armin Schnabel - * @version 2.0.0 - * @since 2.3.1 - */ -@SuppressWarnings("unused") // Part of the API -public class CalibrationJob extends Job { - - /** - * {@code true} when the measurement contains processable tracks. - */ - private boolean processable; - /** - * The number of locations to be processed for this job. - */ - private final int totalLocations; - /** - * The number of locations which were filtered due to a rotated device. - */ - private int rotatedLocations = 0; - /** - * The number of locations which were filtered during interpolation. - */ - private int nonInterpolatableLocations = 0; - - /** - * Constructs a fully initialized instance of this class. - * - * @param id The id of the job to update about the status and progress of the processing. - * @param startedBy The id of the user who triggered the pipeline and will own the result data. - * @param processable {@code true} when the measurement contains processable tracks. - * @param totalLocations The number of locations to be processed for this job. - */ - public CalibrationJob(final String id, final UUID startedBy, final boolean processable, - final int totalLocations) { - super(id, startedBy); - this.processable = processable; - this.totalLocations = totalLocations; - } - - /** - * Constructs a fully initialized instance of this class. - * - * @param job The job which is processed. - * @param processable {@code true} when the measurement contains processable tracks. - * @param totalLocations The number of locations to be processed for this job. - */ - public CalibrationJob(final Job job, final boolean processable, final int totalLocations) { - super(job.getId(), job.getStartedBy()); - this.processable = processable; - this.totalLocations = totalLocations; - } - - /** - * @return {@code true} when the measurement contains processable tracks. - */ - @SuppressWarnings("unused") // Part of the API - public boolean isProcessable() { - return processable; - } - - /** - * @return The number of tracks which were filtered due to a rotated device. - */ - @SuppressWarnings("unused") // Part of the API - public int getRotatedLocations() { - return rotatedLocations; - } - - /** - * @return The number of locations which were filtered during interpolation. - */ - public int getNonInterpolatableLocations() { - return nonInterpolatableLocations; - } - - /** - * @return The number of locations to be processed for this job. - */ - public int getTotalLocations() { - return totalLocations; - } - - /** - * @param rotatedLocations The number of tracks which were filtered due to a rotated device. - * @return This for chaining. - */ - @SuppressWarnings("unused") // Part of the API - public CalibrationJob setRotatedLocations(final int rotatedLocations) { - this.rotatedLocations = rotatedLocations; - return this; - } - - /** - * @param nonInterpolatableLocations The number of locations which were filtered during interpolation. - * @return This for chaining. - */ - public CalibrationJob setNonInterpolatableLocations(int nonInterpolatableLocations) { - this.nonInterpolatableLocations = nonInterpolatableLocations; - return this; - } - - /** - * @param processable {@code true} when the measurement contains processable tracks. - * @return This for chaining. - */ - @SuppressWarnings("unused") // Part of the API - public CalibrationJob setProcessable(boolean processable) { - this.processable = processable; - return this; - } -} diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt new file mode 100644 index 0000000..46efbe1 --- /dev/null +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -0,0 +1,110 @@ +/* + * Copyright 2022-2023 Cyface GmbH + * + * This file is part of the Serialization. + * + * The Serialization is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Serialization is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the Serialization. If not, see . + */ +package de.cyface.model + +import java.util.UUID + +/** + * A [Job] which contains details about filtered data during calibration. + * + * @author Armin Schnabel + * @version 2.0.1 + * @since 2.3.1 + */ +@Suppress("unused") // Part of the API +class CalibrationJob : Job { + /** + * `true` when the measurement contains processable tracks. + */ + var isProcessable: Boolean + private set + + /** + * The number of locations to be processed for this job. + */ + @Suppress("MemberVisibilityCanBePrivate") // Part of the API + val totalLocations: Int + + /** + * The number of locations which were filtered due to a rotated device. + */ + var rotatedLocations = 0 + private set + + /** + * The number of locations which were filtered during interpolation. + */ + var nonInterpolatableLocations = 0 + private set + + /** + * Constructs a fully initialized instance of this class. + * + * @param id The id of the job to update about the status and progress of the processing. + * @param startedBy The id of the user who triggered the pipeline and will own the result data. + * @param processable `true` when the measurement contains processable tracks. + * @param totalLocations The number of locations to be processed for this job. + */ + constructor( + id: String?, startedBy: UUID?, processable: Boolean, + totalLocations: Int + ) : super(id, startedBy) { + isProcessable = processable + this.totalLocations = totalLocations + } + + /** + * Constructs a fully initialized instance of this class. + * + * @param job The job which is processed. + * @param processable `true` when the measurement contains processable tracks. + * @param totalLocations The number of locations to be processed for this job. + */ + constructor(job: Job, processable: Boolean, totalLocations: Int) : super(job.id, job.startedBy) { + isProcessable = processable + this.totalLocations = totalLocations + } + + /** + * @param rotatedLocations The number of tracks which were filtered due to a rotated device. + * @return This for chaining. + */ + fun setRotatedLocations(rotatedLocations: Int): CalibrationJob { + this.rotatedLocations = rotatedLocations + return this + } + + /** + * @param nonInterpolatableLocations The number of locations which were filtered during interpolation. + * @return This for chaining. + */ + fun setNonInterpolatableLocations(nonInterpolatableLocations: Int): CalibrationJob { + this.nonInterpolatableLocations = nonInterpolatableLocations + return this + } + + /** + * @param processable `true` when the measurement contains processable tracks. + * @return This for chaining. + */ + fun setProcessable(processable: Boolean): CalibrationJob { + isProcessable = processable + return this + } +} \ No newline at end of file diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt index df38bff..be61ef8 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/Track.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -173,6 +173,7 @@ class Track : Serializable { * @param location The location to remove. * @return This track for method chaining. */ + @Suppress("unused") // Part of the API fun clearFor(location: RawRecord): Track { // Find the index of the location to remove val locationIndex = locationRecords.indexOf(location) From bcb970eda63429744b6902011448bfa5eb183de5 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 26 Sep 2023 13:06:04 +0200 Subject: [PATCH 4/8] Add invalidLocations propertiy to CalibrationJob --- .../kotlin/de/cyface/model/CalibrationJob.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt index 46efbe1..fd2c679 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -24,7 +24,7 @@ import java.util.UUID * A [Job] which contains details about filtered data during calibration. * * @author Armin Schnabel - * @version 2.0.1 + * @version 2.1.0 * @since 2.3.1 */ @Suppress("unused") // Part of the API @@ -32,6 +32,7 @@ class CalibrationJob : Job { /** * `true` when the measurement contains processable tracks. */ + @Suppress("MemberVisibilityCanBePrivate") // Part of the API var isProcessable: Boolean private set @@ -44,12 +45,21 @@ class CalibrationJob : Job { /** * The number of locations which were filtered due to a rotated device. */ + @Suppress("MemberVisibilityCanBePrivate") // Part of the API var rotatedLocations = 0 private set + /** + * The number of locations which where filtered due to invalid speed, accuracy or time gaps. + */ + @Suppress("MemberVisibilityCanBePrivate") // Part of the API + var invalidLocations = 0 + private set + /** * The number of locations which were filtered during interpolation. */ + @Suppress("MemberVisibilityCanBePrivate") // Part of the API var nonInterpolatableLocations = 0 private set @@ -99,6 +109,15 @@ class CalibrationJob : Job { return this } + /** + * @param invalidLocations The number of locations which where filtered due to invalid speed, accuracy or time gaps. + * @return This for chaining. + */ + fun setInvalidLocations(invalidLocations: Int): CalibrationJob { + this.invalidLocations = invalidLocations + return this + } + /** * @param processable `true` when the measurement contains processable tracks. * @return This for chaining. From d4ec6c6d58d6e5159504bf3b81ec44a5dde66fd3 Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 27 Sep 2023 12:20:41 +0200 Subject: [PATCH 5/8] Add equals to RawRecord --- libs/model/src/main/java/de/cyface/model/RawRecord.java | 9 +++++++++ .../src/main/kotlin/de/cyface/model/CalibrationJob.kt | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/model/src/main/java/de/cyface/model/RawRecord.java b/libs/model/src/main/java/de/cyface/model/RawRecord.java index e39a57f..29c8830 100644 --- a/libs/model/src/main/java/de/cyface/model/RawRecord.java +++ b/libs/model/src/main/java/de/cyface/model/RawRecord.java @@ -142,4 +142,13 @@ public void setSpeed(double speed) { public void setModality(Modality modality) { this.modality = modality; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + RawRecord rawRecord = (RawRecord) o; + return Double.compare(rawRecord.accuracy, accuracy) == 0 && Double.compare(rawRecord.speed, speed) == 0 && modality == rawRecord.modality; + } } diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt index fd2c679..97e0e5d 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -34,7 +34,6 @@ class CalibrationJob : Job { */ @Suppress("MemberVisibilityCanBePrivate") // Part of the API var isProcessable: Boolean - private set /** * The number of locations to be processed for this job. @@ -47,21 +46,18 @@ class CalibrationJob : Job { */ @Suppress("MemberVisibilityCanBePrivate") // Part of the API var rotatedLocations = 0 - private set /** * The number of locations which where filtered due to invalid speed, accuracy or time gaps. */ @Suppress("MemberVisibilityCanBePrivate") // Part of the API var invalidLocations = 0 - private set /** * The number of locations which were filtered during interpolation. */ @Suppress("MemberVisibilityCanBePrivate") // Part of the API var nonInterpolatableLocations = 0 - private set /** * Constructs a fully initialized instance of this class. From e10e1af632fd24e7e1acff1ad42d81b655fcfcd7 Mon Sep 17 00:00:00 2001 From: Armin Date: Thu, 28 Sep 2023 09:52:09 +0200 Subject: [PATCH 6/8] Refactor code to a Kotlin idomatic format --- .../kotlin/de/cyface/model/CalibrationJob.kt | 51 ++------ .../src/main/kotlin/de/cyface/model/Track.kt | 117 ++++++------------ 2 files changed, 44 insertions(+), 124 deletions(-) diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt index 97e0e5d..f61b215 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -68,10 +68,12 @@ class CalibrationJob : Job { * @param totalLocations The number of locations to be processed for this job. */ constructor( - id: String?, startedBy: UUID?, processable: Boolean, + id: String?, + startedBy: UUID?, + processable: Boolean, totalLocations: Int ) : super(id, startedBy) { - isProcessable = processable + this.isProcessable = processable this.totalLocations = totalLocations } @@ -82,44 +84,9 @@ class CalibrationJob : Job { * @param processable `true` when the measurement contains processable tracks. * @param totalLocations The number of locations to be processed for this job. */ - constructor(job: Job, processable: Boolean, totalLocations: Int) : super(job.id, job.startedBy) { - isProcessable = processable - this.totalLocations = totalLocations - } - - /** - * @param rotatedLocations The number of tracks which were filtered due to a rotated device. - * @return This for chaining. - */ - fun setRotatedLocations(rotatedLocations: Int): CalibrationJob { - this.rotatedLocations = rotatedLocations - return this - } - - /** - * @param nonInterpolatableLocations The number of locations which were filtered during interpolation. - * @return This for chaining. - */ - fun setNonInterpolatableLocations(nonInterpolatableLocations: Int): CalibrationJob { - this.nonInterpolatableLocations = nonInterpolatableLocations - return this - } - - /** - * @param invalidLocations The number of locations which where filtered due to invalid speed, accuracy or time gaps. - * @return This for chaining. - */ - fun setInvalidLocations(invalidLocations: Int): CalibrationJob { - this.invalidLocations = invalidLocations - return this - } - - /** - * @param processable `true` when the measurement contains processable tracks. - * @return This for chaining. - */ - fun setProcessable(processable: Boolean): CalibrationJob { - isProcessable = processable - return this - } + constructor( + job: Job, + processable: Boolean, + totalLocations: Int + ) : this(job.id, job.startedBy, processable, totalLocations) } \ No newline at end of file diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt index be61ef8..6ce0bb3 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/Track.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -19,7 +19,6 @@ package de.cyface.model import java.io.Serializable -import java.util.Collections import java.util.Objects /** @@ -32,85 +31,43 @@ import java.util.Objects * @author Armin Schnabel * @version 2.1.0 * @since 1.0.0 + * @param locationRecords The list of `RawRecord`s collected for this `Track` ordered by + * timestamp. + * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². + * @param rotations The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. + * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). */ -class Track : Serializable { +class Track( + locationRecords: List = emptyList(), + accelerations: List = emptyList(), + rotations: List = emptyList(), + directions: List = emptyList() +) : Serializable { + + private var _locationRecords = locationRecords.toMutableList() + private var _accelerations = accelerations.toMutableList() + private var _rotations = rotations.toMutableList() + private var _directions = directions.toMutableList() + /** * The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. */ - private lateinit var locationRecords: MutableList + val locationRecords: List get() = _locationRecords /** * The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². */ - private lateinit var accelerations: MutableList + val accelerations: List get() = _accelerations /** * The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. */ - private lateinit var rotations: MutableList + val rotations: List get() = _rotations /** * The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). */ - private lateinit var directions: MutableList - - /** - * Creates a new completely initialized `Track`. - * - * @param locationRecords The list of `RawRecord`s collected for this `Track` ordered by - * timestamp. - * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - * @param rotations The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. - * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). - */ - constructor( - locationRecords: List, accelerations: List, - rotations: List, directions: List - ) { - Objects.requireNonNull(locationRecords) - Objects.requireNonNull(accelerations) - Objects.requireNonNull(rotations) - Objects.requireNonNull(directions) - this.locationRecords = ArrayList(locationRecords) - this.accelerations = ArrayList(accelerations) - this.rotations = ArrayList(rotations) - this.directions = ArrayList(directions) - } - - /** - * No argument constructor as required by Apache Flink. Do not use this in your own code. - */ - constructor() { - // Nothing to do - } - - /** - * @return The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. - */ - fun getLocationRecords(): List { - return Collections.unmodifiableList(locationRecords) - } - - /** - * @return The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - */ - fun getAccelerations(): List { - return Collections.unmodifiableList(accelerations) - } - - /** - * @return The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - */ - fun getRotations(): List { - return Collections.unmodifiableList(rotations) - } - - /** - * @return The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). - */ - fun getDirections(): List { - return Collections.unmodifiableList(directions) - } + val directions: List get() = _directions /** * Required by Apache Flink. @@ -119,8 +76,7 @@ class Track : Serializable { * timestamp. */ fun setLocationRecords(locationRecords: List) { - Objects.requireNonNull(locationRecords) - this.locationRecords = ArrayList(locationRecords) + _locationRecords = locationRecords.toMutableList() } /** @@ -129,8 +85,7 @@ class Track : Serializable { * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². */ fun setAccelerations(accelerations: List) { - Objects.requireNonNull(locationRecords) - this.accelerations = ArrayList(accelerations) + _accelerations = accelerations.toMutableList() } /** @@ -139,8 +94,7 @@ class Track : Serializable { * @param rotations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². */ fun setRotations(rotations: List) { - Objects.requireNonNull(locationRecords) - this.rotations = ArrayList(rotations) + _rotations = rotations.toMutableList() } /** @@ -149,8 +103,7 @@ class Track : Serializable { * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). */ fun setDirections(directions: List) { - Objects.requireNonNull(locationRecords) - this.directions = ArrayList(directions) + _directions = directions.toMutableList() } /** @@ -160,10 +113,10 @@ class Track : Serializable { * @return This track for method chaining */ fun clearAfter(timestamp: Long): Track { - locationRecords.removeIf { it.timestamp < timestamp } - accelerations.removeIf { it.timestamp <= timestamp } - rotations.removeIf { it.timestamp <= timestamp } - directions.removeIf { it.timestamp <= timestamp } + _locationRecords.removeIf { it.timestamp < timestamp } + _accelerations.removeIf { it.timestamp <= timestamp } + _rotations.removeIf { it.timestamp <= timestamp } + _directions.removeIf { it.timestamp <= timestamp } return this } @@ -176,20 +129,20 @@ class Track : Serializable { @Suppress("unused") // Part of the API fun clearFor(location: RawRecord): Track { // Find the index of the location to remove - val locationIndex = locationRecords.indexOf(location) + val locationIndex = _locationRecords.indexOf(location) if (locationIndex == -1) throw IllegalStateException("Location not found: $location") //return this // Determine the timestamp range for which sensor data should be removed - val startTimestamp = if (locationIndex > 0) locationRecords[locationIndex - 1].timestamp else 0L + val startTimestamp = if (locationIndex > 0) _locationRecords[locationIndex - 1].timestamp else 0L val endTimestamp = location.timestamp // Remove the location - locationRecords.remove(location) + _locationRecords.remove(location) // Remove sensor data that falls within the determined timestamp range - accelerations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } - rotations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } - directions.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + _accelerations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + _rotations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + _directions.removeIf { it.timestamp in (startTimestamp until endTimestamp) } return this } From abdce41ec4704fe97120c2231f5157bde310ad06 Mon Sep 17 00:00:00 2001 From: Armin Date: Thu, 28 Sep 2023 09:57:29 +0200 Subject: [PATCH 7/8] Update licence header and cleannup --- .../main/java/de/cyface/model/RawRecord.java | 18 ++++++++++++------ .../kotlin/de/cyface/model/CalibrationJob.kt | 2 +- .../src/main/kotlin/de/cyface/model/Track.kt | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libs/model/src/main/java/de/cyface/model/RawRecord.java b/libs/model/src/main/java/de/cyface/model/RawRecord.java index 29c8830..dc38c54 100644 --- a/libs/model/src/main/java/de/cyface/model/RawRecord.java +++ b/libs/model/src/main/java/de/cyface/model/RawRecord.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Cyface GmbH + * Copyright 2021-2023 Cyface GmbH * * This file is part of the Serialization. * @@ -20,6 +20,12 @@ import org.apache.commons.lang3.Validate; +/** + * {@link GeoLocationRecord} annotated with accuracy, speed and modality. + * + * @author Armin Schnabel + * @version 1.0.0 + */ public class RawRecord extends GeoLocationRecord { /** @@ -32,7 +38,7 @@ public class RawRecord extends GeoLocationRecord { */ private double accuracy; /** - * The traveled speed in meters per second as reported by the geo location system (e.g. GPS, GLONASS, GALILEO) during this recording. + * The traveled speed in meters per second as reported by the geographical location system (e.g. GPS, GLONASS, GALILEO) during this recording. */ private double speed; /** @@ -59,7 +65,7 @@ public RawRecord(final MeasurementIdentifier measurementIdentifier, final long t /** * Creates a new completely initialized RawRecord. * - * @param measurementIdentifier The world wide unique identifier of the {@link Measurement} this record belongs to + * @param measurementIdentifier The worldwide unique identifier of the {@link Measurement} this record belongs to * @param timestamp The timestamp this location was captured on in milliseconds since 1st January 1970 (epoch) * @param latitude Geographical latitude in coordinates (decimal fraction) raging from -90° (south) to 90° (north) * @param longitude Geographical longitude in coordinates (decimal fraction) ranging from -180° (west) to 180° @@ -67,7 +73,7 @@ public RawRecord(final MeasurementIdentifier measurementIdentifier, final long t * @param elevation The elevation above sea level in meters or null if it could not be calculated * @param accuracy The measurement accuracy of this location in meters. This accuracy is usually the result of * imperfect measurement hardware - * @param speed The traveled speed as reported by the geo location system (e.g. GPS, GLONASS, GALILEO) during this + * @param speed The traveled speed as reported by the geographical location system (e.g. GPS, GLONASS, GALILEO) during this * recording * @param modality The modality type used while collecting the location or {@code null} if the information is not * available @@ -100,7 +106,7 @@ public final void setAccuracy(double accuracy) { } /** - * @return The traveled speed as reported by the geo location system (e.g. GPS, GLONASS, GALILEO) during this + * @return The traveled speed as reported by the geographical location system (e.g. GPS, GLONASS, GALILEO) during this * recording */ public double getSpeed() { @@ -126,7 +132,7 @@ public void setAccuracy(int accuracy) { } /** - * @param speed The traveled speed as reported by the geo location system (e.g. GPS, GLONASS, GALILEO) during this + * @param speed The traveled speed as reported by the geographical location system (e.g. GPS, GLONASS, GALILEO) during this * recording */ public void setSpeed(double speed) { diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt index f61b215..e2ac76b 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -24,7 +24,7 @@ import java.util.UUID * A [Job] which contains details about filtered data during calibration. * * @author Armin Schnabel - * @version 2.1.0 + * @version 3.0.0 * @since 2.3.1 */ @Suppress("unused") // Part of the API diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt index 6ce0bb3..f6d56ae 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/Track.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Cyface GmbH + * Copyright 2019-2023 Cyface GmbH * * This file is part of the Serialization. * @@ -29,7 +29,7 @@ import java.util.Objects * when the very last locations is reached. * * @author Armin Schnabel - * @version 2.1.0 + * @version 3.0.0 * @since 1.0.0 * @param locationRecords The list of `RawRecord`s collected for this `Track` ordered by * timestamp. From 0a38b43db1aa856092266e4230358eee366b2c21 Mon Sep 17 00:00:00 2001 From: Klemens Muthmann Date: Thu, 28 Sep 2023 13:09:05 +0200 Subject: [PATCH 8/8] Update Track and CalibrationJob to use Kotlin Properties --- .../kotlin/de/cyface/model/CalibrationJob.kt | 60 ++++-------- .../src/main/kotlin/de/cyface/model/Track.kt | 91 +++---------------- 2 files changed, 32 insertions(+), 119 deletions(-) diff --git a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt index e2ac76b..348aaff 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/CalibrationJob.kt @@ -24,58 +24,32 @@ import java.util.UUID * A [Job] which contains details about filtered data during calibration. * * @author Armin Schnabel + * @author Klemens Muthmann * @version 3.0.0 * @since 2.3.1 + * @param id The id of the job to update about the status and progress of the processing. + * @param startedBy The id of the user who triggered the pipeline and will own the result data. + * @property isProcessable `true` when the measurement contains processable tracks. + * @property totalLocations The number of locations to be processed for this job. + * @property rotatedLocations The number of locations which were filtered due to a rotated device. + * @property invalidLocations The number of locations which where filtered due to invalid speed, accuracy or time gaps. + * @property nonInterpolatableLocations The number of locations which were filtered during interpolation. */ @Suppress("unused") // Part of the API -class CalibrationJob : Job { - /** - * `true` when the measurement contains processable tracks. - */ +class CalibrationJob( + id: String?, + startedBy: UUID?, @Suppress("MemberVisibilityCanBePrivate") // Part of the API - var isProcessable: Boolean - - /** - * The number of locations to be processed for this job. - */ + var isProcessable: Boolean, @Suppress("MemberVisibilityCanBePrivate") // Part of the API - val totalLocations: Int - - /** - * The number of locations which were filtered due to a rotated device. - */ + val totalLocations: Int, @Suppress("MemberVisibilityCanBePrivate") // Part of the API - var rotatedLocations = 0 - - /** - * The number of locations which where filtered due to invalid speed, accuracy or time gaps. - */ + var rotatedLocations: Int = 0, @Suppress("MemberVisibilityCanBePrivate") // Part of the API - var invalidLocations = 0 - - /** - * The number of locations which were filtered during interpolation. - */ + var invalidLocations: Int = 0, @Suppress("MemberVisibilityCanBePrivate") // Part of the API - var nonInterpolatableLocations = 0 - - /** - * Constructs a fully initialized instance of this class. - * - * @param id The id of the job to update about the status and progress of the processing. - * @param startedBy The id of the user who triggered the pipeline and will own the result data. - * @param processable `true` when the measurement contains processable tracks. - * @param totalLocations The number of locations to be processed for this job. - */ - constructor( - id: String?, - startedBy: UUID?, - processable: Boolean, - totalLocations: Int - ) : super(id, startedBy) { - this.isProcessable = processable - this.totalLocations = totalLocations - } + var nonInterpolatableLocations: Int = 0, +) : Job(id, startedBy) { /** * Constructs a fully initialized instance of this class. diff --git a/libs/model/src/main/kotlin/de/cyface/model/Track.kt b/libs/model/src/main/kotlin/de/cyface/model/Track.kt index f6d56ae..8957f2a 100644 --- a/libs/model/src/main/kotlin/de/cyface/model/Track.kt +++ b/libs/model/src/main/kotlin/de/cyface/model/Track.kt @@ -29,6 +29,7 @@ import java.util.Objects * when the very last locations is reached. * * @author Armin Schnabel + * @author Klemens Muthmann * @version 3.0.0 * @since 1.0.0 * @param locationRecords The list of `RawRecord`s collected for this `Track` ordered by @@ -38,74 +39,12 @@ import java.util.Objects * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). */ class Track( - locationRecords: List = emptyList(), - accelerations: List = emptyList(), - rotations: List = emptyList(), - directions: List = emptyList() + var locationRecords: MutableList = mutableListOf(), + var accelerations: MutableList = mutableListOf(), + var rotations: MutableList = mutableListOf(), + var directions: MutableList = mutableListOf(), ) : Serializable { - private var _locationRecords = locationRecords.toMutableList() - private var _accelerations = accelerations.toMutableList() - private var _rotations = rotations.toMutableList() - private var _directions = directions.toMutableList() - - /** - * The list of `GeoLocationRecord`s collected for this `Track` ordered by timestamp. - */ - val locationRecords: List get() = _locationRecords - - /** - * The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - */ - val accelerations: List get() = _accelerations - - /** - * The list of rotations for this `Track` ordered by timestamp. Unit: rad/s. - */ - val rotations: List get() = _rotations - - /** - * The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). - */ - val directions: List get() = _directions - - /** - * Required by Apache Flink. - * - * @param locationRecords The list of `GeoLocationRecord`s collected for this `Track` ordered by - * timestamp. - */ - fun setLocationRecords(locationRecords: List) { - _locationRecords = locationRecords.toMutableList() - } - - /** - * Required by Apache Flink. - * - * @param accelerations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - */ - fun setAccelerations(accelerations: List) { - _accelerations = accelerations.toMutableList() - } - - /** - * Required by Apache Flink. - * - * @param rotations The list of accelerations for this `Track` ordered by timestamp. Unit: m/s². - */ - fun setRotations(rotations: List) { - _rotations = rotations.toMutableList() - } - - /** - * Required by Apache Flink. - * - * @param directions The list of directions for this `Track` ordered by timestamp. Unit. micro-Tesla (uT). - */ - fun setDirections(directions: List) { - _directions = directions.toMutableList() - } - /** * Removes all data after the provided `timestamp` from this `Track`. * @@ -113,10 +52,10 @@ class Track( * @return This track for method chaining */ fun clearAfter(timestamp: Long): Track { - _locationRecords.removeIf { it.timestamp < timestamp } - _accelerations.removeIf { it.timestamp <= timestamp } - _rotations.removeIf { it.timestamp <= timestamp } - _directions.removeIf { it.timestamp <= timestamp } + locationRecords.removeIf { it.timestamp < timestamp } + accelerations.removeIf { it.timestamp <= timestamp } + rotations.removeIf { it.timestamp <= timestamp } + directions.removeIf { it.timestamp <= timestamp } return this } @@ -129,20 +68,20 @@ class Track( @Suppress("unused") // Part of the API fun clearFor(location: RawRecord): Track { // Find the index of the location to remove - val locationIndex = _locationRecords.indexOf(location) + val locationIndex = locationRecords.indexOf(location) if (locationIndex == -1) throw IllegalStateException("Location not found: $location") //return this // Determine the timestamp range for which sensor data should be removed - val startTimestamp = if (locationIndex > 0) _locationRecords[locationIndex - 1].timestamp else 0L + val startTimestamp = if (locationIndex > 0) locationRecords[locationIndex - 1].timestamp else 0L val endTimestamp = location.timestamp // Remove the location - _locationRecords.remove(location) + locationRecords.remove(location) // Remove sensor data that falls within the determined timestamp range - _accelerations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } - _rotations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } - _directions.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + accelerations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + rotations.removeIf { it.timestamp in (startTimestamp until endTimestamp) } + directions.removeIf { it.timestamp in (startTimestamp until endTimestamp) } return this }