Skip to content

Commit

Permalink
Refactor after PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Sep 30, 2019
1 parent 6e8bd9d commit bb569d7
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 17.0.1
* @version 17.0.2
* @since 2.0.0
*/
public class PersistenceLayer<B extends PersistenceBehaviour> {
Expand Down Expand Up @@ -720,7 +720,9 @@ private List<Track> loadTracks(@NonNull final Cursor geoLocationCursor, @NonNull
final Track track = new Track();
do {
final GeoLocation location = loadGeoLocation(geoLocationCursor);
track.add(location);
if (location != null) {
track.add(location);
}

} while (geoLocationCursor.moveToNext());
Validate.isTrue(track.getGeoLocations().size() > 0);
Expand All @@ -742,16 +744,12 @@ private Track collectNextSubTrack(@NonNull final Cursor geoLocationCursor, @NonN
final Track track = new Track();

GeoLocation location = loadGeoLocation(geoLocationCursor);
while (location.getTimestamp() <= pauseEventTime) {
while (location != null && location.getTimestamp() <= pauseEventTime) {

track.add(location);

// Stop if this is the last GeoLocation
if (!geoLocationCursor.moveToNext()) {
break;
}

// Load next GeoLocation to check it's timestamp in next iteration
geoLocationCursor.moveToNext();
location = loadGeoLocation(geoLocationCursor);
}

Expand All @@ -768,13 +766,9 @@ private Track collectNextSubTrack(@NonNull final Cursor geoLocationCursor, @NonN
*/
private void moveCursorToFirstAfter(@NonNull final Cursor geoLocationCursor, final long resumeEventTime) {

// Stop if we already reached the last element
if (geoLocationCursor.isAfterLast()) {
return;
}

@Nullable
GeoLocation location = loadGeoLocation(geoLocationCursor);
while (location.getTimestamp() < resumeEventTime && geoLocationCursor.moveToNext()) {
while (location != null && location.getTimestamp() < resumeEventTime && geoLocationCursor.moveToNext()) {

// Load next location to check it's timestamp
location = loadGeoLocation(geoLocationCursor);
Expand All @@ -785,9 +779,13 @@ private void moveCursorToFirstAfter(@NonNull final Cursor geoLocationCursor, fin
* Loads the {@link GeoLocation} at the {@code Cursor}'s current position.
*
* @param geoLocationCursor the {@code Cursor} pointing to a {@code GeoLocation} in the database.
* @return the {@code GeoLocation} loaded.
* @return the {@code GeoLocation} loaded or {@code Null} if the cursor points to the entry after the last one.
*/
@Nullable
private GeoLocation loadGeoLocation(@NonNull final Cursor geoLocationCursor) {
if (geoLocationCursor.isAfterLast()) {
return null;
}

final double lat = geoLocationCursor.getDouble(geoLocationCursor.getColumnIndex(GeoLocationsTable.COLUMN_LAT));
final double lon = geoLocationCursor.getDouble(geoLocationCursor.getColumnIndex(GeoLocationsTable.COLUMN_LON));
Expand Down

0 comments on commit bb569d7

Please sign in to comment.