From 991ec9301656fbf354d90ac0ee886c6a5677fe6c Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Mon, 24 Jun 2013 19:50:47 +0200 Subject: findbugs: don't compare float for equality --- main/src/cgeo/geocaching/speech/TextFactory.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'main') diff --git a/main/src/cgeo/geocaching/speech/TextFactory.java b/main/src/cgeo/geocaching/speech/TextFactory.java index d4f3a48..e367bb1 100644 --- a/main/src/cgeo/geocaching/speech/TextFactory.java +++ b/main/src/cgeo/geocaching/speech/TextFactory.java @@ -22,7 +22,7 @@ public class TextFactory { } private static String getDistance(Geopoint position, Geopoint target) { - float kilometers = position.distanceTo(target); + final float kilometers = position.distanceTo(target); if (Settings.isUseMetricUnits()) { return getDistance(kilometers, (int) (kilometers * 1000.0), @@ -42,7 +42,7 @@ public class TextFactory { int farId, int farOneId, int nearId, int nearOneId) { if (farDistance >= farFarAway) { // example: "5 kilometers" - always without decimal digits - int quantity = Math.round(farDistance); + final int quantity = Math.round(farDistance); if (quantity == 1) { return getString(farOneId, quantity, String.valueOf(quantity)); } @@ -50,18 +50,18 @@ public class TextFactory { } if (farDistance >= farNearAway) { // example: "2.2 kilometers" - decimals if necessary - float precision1 = Math.round(farDistance * 10.0f) / 10.0f; - float precision0 = Math.round(farDistance); - if (precision1 == precision0) { + final float precision1 = Math.round(farDistance * 10.0f) / 10.0f; + final float precision0 = Math.round(farDistance); + if (Math.abs(precision1 - precision0) < 0.0001) { // this is an int - e.g. 2 kilometers - int quantity = (int) precision0; + final int quantity = (int) precision0; if (quantity == 1) { return getString(farOneId, quantity, String.valueOf(quantity)); } return getQuantityString(farId, quantity, String.valueOf(quantity)); } // this is no int - e.g. 1.7 kilometers - String digits = String.format(Locale.getDefault(), "%.1f", farDistance); + final String digits = String.format(Locale.getDefault(), "%.1f", farDistance); // always use the plural (9 leads to plural) return getQuantityString(farId, 9, digits); } @@ -87,7 +87,7 @@ public class TextFactory { private static String getDirection(Geopoint position, Geopoint target, float direction) { final int bearing = (int) position.bearingTo(target); - int degrees = (int) AngleUtils.normalize(bearing - direction); + final int degrees = (int) AngleUtils.normalize(bearing - direction); int hours = (degrees + 15) / 30; if (hours == 0) { -- cgit v1.1