diff options
Diffstat (limited to 'main/src/cgeo/geocaching/geopoint')
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Geopoint.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/GeopointParser.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Units.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Viewport.java | 16 |
4 files changed, 23 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java index bb34114..aa7c929 100644 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java @@ -53,7 +53,7 @@ public final class Geopoint implements ICoordinates, Parcelable { * if the string cannot be parsed * @see GeopointParser#parse(String) */ - public Geopoint(final String text) { + public Geopoint(@NonNull final String text) { final Geopoint parsed = GeopointParser.parse(text); latitude = parsed.latitude; longitude = parsed.longitude; diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java index b486f01..62d43da 100644 --- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java +++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java @@ -1,9 +1,9 @@ package cgeo.geocaching.geopoint; - import cgeo.geocaching.utils.MatcherWrapper; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; import java.util.regex.Pattern; @@ -55,7 +55,7 @@ class GeopointParser { * @throws Geopoint.ParseException * if lat or lon could not be parsed */ - public static Geopoint parse(final String text) { + public static Geopoint parse(@NonNull final String text) { final ResultWrapper latitudeWrapper = parseHelper(text, LatLon.LAT); // cut away the latitude part when parsing the longitude final ResultWrapper longitudeWrapper = parseHelper(text.substring(latitudeWrapper.matcherPos + latitudeWrapper.matcherLength), LatLon.LON); @@ -92,7 +92,7 @@ class GeopointParser { try { return new ResultWrapper(Double.valueOf(replaceSpaceAfterComma), 0, text.length()); - } catch (NumberFormatException e1) { + } catch (NumberFormatException ignored) { // fall through to advanced parsing } @@ -126,7 +126,7 @@ class GeopointParser { final int pos = (latlon == LatLon.LON ? text.lastIndexOf(textPart) : text.indexOf(textPart)); return new ResultWrapper(Double.parseDouble(textPart), pos, textPart.length()); } - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { // The right exception will be raised below. } diff --git a/main/src/cgeo/geocaching/geopoint/Units.java b/main/src/cgeo/geocaching/geopoint/Units.java index 018216d..c657ede 100644 --- a/main/src/cgeo/geocaching/geopoint/Units.java +++ b/main/src/cgeo/geocaching/geopoint/Units.java @@ -11,7 +11,7 @@ public class Units { public static ImmutablePair<Double, String> scaleDistance(final double distanceKilometers) { double distance; String units; - if (Settings.isUseImperialUnits()) { + if (Settings.useImperialUnits()) { distance = distanceKilometers / IConversion.MILES_TO_KILOMETER; if (distance >= 0.1) { units = "mi"; @@ -54,7 +54,7 @@ public class Units { } public static String getSpeed(final float kilometersPerHour) { - if (Settings.isUseImperialUnits()) { + if (Settings.useImperialUnits()) { return String.format(Locale.US, "%.0f mph", kilometersPerHour / IConversion.MILES_TO_KILOMETER); } return String.format(Locale.US, "%.0f km/h", kilometersPerHour); diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java index ba0e040..a48b0a1 100644 --- a/main/src/cgeo/geocaching/geopoint/Viewport.java +++ b/main/src/cgeo/geocaching/geopoint/Viewport.java @@ -79,6 +79,22 @@ public final class Viewport { && coords.getLatitudeE6() <= topRight.getLatitudeE6(); } + /** + * Count the number of points present in the viewport. + * + * @param points a collection of (possibly null) points + * @return the number of non-null points in the viewport + */ + public int count(final @NonNull Collection<? extends ICoordinates> points) { + int total = 0; + for (ICoordinates point: points) { + if (point != null && contains(point)) { + total += 1; + } + } + return total; + } + @Override public String toString() { return "(" + bottomLeft.toString() + "," + topRight.toString() + ")"; |
