Cleanup: mainly code formatting and made LocationIterator implement autoclosable.

This commit is contained in:
Dennis Guse
2019-09-07 12:23:56 +02:00
parent 025dee6821
commit 87d92d25f9
104 changed files with 1076 additions and 1526 deletions
@@ -35,6 +35,11 @@ import de.dennisguse.opentracks.content.Waypoint.WaypointType;
*/
public interface ContentProviderUtils {
/**
* Maximum number of waypoints that will be loaded at one time.
*/
int MAX_LOADED_WAYPOINTS_POINTS = 10000;
/**
* The authority (the first part of the URI) for the app's content provider.
*/
@@ -56,7 +61,8 @@ public interface ContentProviderUtils {
};
/**
* Clears a track. Removes waypoints and trackpoints. Only keeps the track id.
* Clears a track: removes waypoints and trackpoints.
* Only keeps the track id.
*
* @param trackId the track id
*/
@@ -82,20 +88,19 @@ public interface ContentProviderUtils {
void deleteTrack(Context context, long trackId);
/**
* Gets all the tracks. If no track exists, an empty list is returned.
* <p>
* Note that the returned tracks do not have any track points attached.
* Gets all the tracks.
* If no track exists, an empty list is returned.
* NOTE: the returned tracks do not have any track points attached.
*/
List<Track> getAllTracks();
/**
* Gets the last track. Returns null if doesn't exist.
* Gets the last track or null.
*/
Track getLastTrack();
/**
* Gets a track by a track id. Returns null if not found.
* <p>
* Gets a track by a track id or null
* Note that the returned track doesn't have any track points attached.
*
* @param trackId the track id.
@@ -103,8 +108,8 @@ public interface ContentProviderUtils {
Track getTrack(long trackId);
/**
* Gets a track cursor. The caller owns the returned cursor and is responsible
* for closing it.
* Gets a track cursor.
* The caller owns the returned cursor and is responsible for closing it.
*
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
@@ -114,8 +119,7 @@ public interface ContentProviderUtils {
/**
* Inserts a track.
* <p>
* Note: This doesn't insert any track points.
* NOTE: This doesn't insert any track points.
*
* @param track the track
* @return the content provider URI of the inserted track.
@@ -124,8 +128,7 @@ public interface ContentProviderUtils {
/**
* Updates a track.
* <p>
* Note: This doesn't update any track points.
* NOTE: This doesn't update any track points.
*
* @param track the track
*/
@@ -139,19 +142,19 @@ public interface ContentProviderUtils {
Waypoint createWaypoint(Cursor cursor);
/**
* Deletes a waypoint. If deleting a statistics waypoint, this will also
* correct the next statistics waypoint after the deleted one to reflect the
* deletion. The generator is used to update the next statistics waypoint.
* Deletes a waypoint.
* If deleting a statistics waypoint, this will also correct the next statistics waypoint after the deleted one to reflect the deletion.
* The generator is used to update the next statistics waypoint.
*
* @param waypointId the waypoint id
* @param descriptionGenerator the description generator. Can be null for
* waypoint marker
* @param descriptionGenerator the description generator. Can be null for waypoint marker
*/
void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator);
/**
* Gets the first waypoint id for a track. The first waypoint is special as it
* contains the stats for the track. Returns -1L if it doesn't exist.
* Gets the first waypoint id for a track.
* The first waypoint is special as it contains the stats for the track.
* Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
@@ -166,8 +169,8 @@ public interface ContentProviderUtils {
Waypoint getLastWaypoint(long trackId, WaypointType waypointType);
/**
* Gets the next waypoint number for a type. Returns -1 if not able to get the
* next waypoint number.
* Gets the next waypoint number for a type.
* Returns -1 if not able to get the next waypoint number.
*
* @param trackId the track id
* @param waypointType the waypoint type
@@ -175,15 +178,16 @@ public interface ContentProviderUtils {
int getNextWaypointNumber(long trackId, WaypointType waypointType);
/**
* Gets a waypoint from a waypoint id. Returns null if not found.
* Gets a waypoint from a waypoint id.
* Returns null if not found.
*
* @param waypointId the waypoint id
*/
Waypoint getWaypoint(long waypointId);
/**
* Gets a waypoint cursor. The caller owns the returned cursor and is
* responsible for closing it.
* Gets a waypoint cursor.
* he caller owns the returned cursor and is responsible for closing it.
*
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
@@ -194,13 +198,12 @@ public interface ContentProviderUtils {
Cursor getWaypointCursor(String selection, String[] selectionArgs, String sortOrder, int maxWaypoints);
/**
* Gets a waypoint cursor for a track. The caller owns the returned cursor and
* is responsible for closing it.
* Gets a waypoint cursor for a track.
* The caller owns the returned cursor and is responsible for closing it.
*
* @param trackId the track id
* @param minWaypointId the minimum waypoint id. -1L to ignore
* @param maxWaypoints the maximum number of waypoints to return. -1 for no
* limit
* @param maxWaypoints the maximum number of waypoints to return. -1 for no limit
*/
Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
@@ -220,7 +223,8 @@ public interface ContentProviderUtils {
Uri insertWaypoint(Waypoint waypoint);
/**
* Updates a waypoint. Returns true if successful.
* Updates a waypoint.
* Returns true if successful.
*
* @param waypoint the waypoint
*/
@@ -245,14 +249,16 @@ public interface ContentProviderUtils {
Location createTrackPoint(Cursor cursor);
/**
* Gets the first location id for a track. Returns -1L if it doesn't exist.
* Gets the first location id for a track.
* Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
long getFirstTrackPointId(long trackId);
/**
* Gets the last location id for a track. Returns -1L if it doesn't exist.
* Gets the last location id for a track.
* Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
@@ -268,28 +274,23 @@ public interface ContentProviderUtils {
long getTrackPointId(long trackId, Location location);
/**
* Gets the first valid location for a track. Returns null if it doesn't
* exist.
* Gets the first valid location for a track.
* Returns null if it doesn't exist.
*
* @param trackId the track id
*/
Location getFirstValidTrackPoint(long trackId);
/**
* Gets the last valid location for a track. Returns null if it doesn't exist.
* Gets the last valid location for a track.
* Returns null if it doesn't exist.
*
* @param trackId the track id
*/
Location getLastValidTrackPoint(long trackId);
/**
* Gets the last valid location.
*/
Location getLastValidTrackPoint();
/**
* Creates a location cursor. The caller owns the returned cursor and is
* responsible for closing it.
* Creates a location cursor. The caller owns the returned cursor and is responsible for closing it.
*
* @param trackId the track id
* @param startTrackPointId the starting track point id. -1L to ignore
@@ -299,20 +300,15 @@ public interface ContentProviderUtils {
Cursor getTrackPointCursor(long trackId, long startTrackPointId, int maxLocations, boolean descending);
/**
* Creates a new read-only iterator over a given track's points. It provides a
* lightweight way of iterating over long tracks without failing due to the
* underlying cursor limitations. Since it's a read-only iterator,
* {@link Iterator#remove()} always throws
* {@link UnsupportedOperationException}. Each call to
* {@link LocationIterator#next()} may advance to the next DB record, and if
* so, the iterator calls {@link LocationFactory#createLocation()} and
* populates it with information retrieved from the record. When done with
* iteration, {@link LocationIterator#close()} must be called.
* Creates a new read-only iterator over a given track's points.
* It provides a lightweight way of iterating over long tracks without failing due to the underlying cursor limitations.
* Since it's a read-only iterator, {@link Iterator#remove()} always throws {@link UnsupportedOperationException}.
* Each call to {@link LocationIterator#next()} may advance to the next DB record, and if so, the iterator calls {@link LocationFactory#createLocation()} and populates it with information retrieved from the record.
* When done with iteration, {@link LocationIterator#close()} must be called.
*
* @param trackId the track id
* @param startTrackPointId the starting track point id. -1L to ignore
* @param descending true to sort the result in descending order (latest
* location first)
* @param descending true to sort the result in descending order (latest location first)
* @param locationFactory the location factory
*/
LocationIterator getTrackPointLocationIterator(long trackId, long startTrackPointId, boolean descending, LocationFactory locationFactory);
@@ -327,10 +323,9 @@ public interface ContentProviderUtils {
Uri insertTrackPoint(Location location, long trackId);
/**
* A lightweight wrapper around the original {@link Cursor} with a method to
* clean up.
* A lightweight wrapper around the original {@link Cursor} with a method to clean up.
*/
interface LocationIterator extends Iterator<Location> {
interface LocationIterator extends Iterator<Location>, AutoCloseable {
/**
* Gets the most recently retrieved track point id by {@link #next()}.
@@ -349,8 +344,8 @@ public interface ContentProviderUtils {
interface LocationFactory {
/**
* Creates a new {@link Location}. An implementation can create new
* instances or reuse existing instances for optimization.
* Creates a new {@link Location}.
* An implementation can create new instances or reuse existing instances for optimization.
*/
Location createLocation();
}
@@ -358,6 +353,8 @@ public interface ContentProviderUtils {
/**
* A factory which can produce instances of {@link ContentProviderUtils}, and can be overridden for testing.
*/
//TODO Is this still used? From a quick glance, it doesn't looks like it; probably a left over from testing.
@Deprecated
class Factory {
private static Factory instance = new Factory();
@@ -379,8 +376,8 @@ public interface ContentProviderUtils {
}
/**
* Overrides the factory instance for testing. Don't forget to set it back
* to the original value after testing.
* Overrides the factory instance for testing.
* Don't forget to set it back to the original value after testing.
*
* @param factory the factory
*/
@@ -394,7 +391,7 @@ public interface ContentProviderUtils {
*
* @param context the context
*/
protected ContentProviderUtils newForContext(Context context) {
private ContentProviderUtils newForContext(Context context) {
return new ContentProviderUtilsImpl(context.getContentResolver());
}
}