Skip to content

Commit

Permalink
Merge pull request #6 from omnimodal/tc_issue_122_2
Browse files Browse the repository at this point in the history
overload Geo::distanceFormat to handle Double
  • Loading branch information
vsperez authored Jun 7, 2019
2 parents 680378c + 5746053 commit aa9f739
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.transitclock.core.SpatialMatch;
import org.transitclock.core.TemporalDifference;
import org.transitclock.core.VehicleState;
import org.transitclock.db.structs.HoldingTime;
import org.transitclock.db.structs.Trip;
import org.transitclock.utils.Geo;
import org.transitclock.utils.Time;
Expand Down
21 changes: 21 additions & 0 deletions transitclock/src/main/java/org/transitclock/utils/Geo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ public static String distanceFormat(double arg) {
return twoDigitFormat.format(arg) + "m";
}

/**
* For formatting distances in meters to consistent 2 decimal places.
* Appends "m" to indicate units.
*
* @param arg
* @return
*/
public static String distanceFormat(Double arg) {
// Handle NaN and other special cases
if (arg == null)
return "null";
if (arg.isNaN())
return "NaN";
if (arg == Double.MAX_VALUE)
return "Double.MAX_VALUE";

// Not a special case so output the value with just two digits
// past decimal place and append "m" to indicate meters.
return twoDigitFormat.format(arg) + "m";
}

/**
* Outputs arg with just a single digit. No other formatting is done.
* Useful when want to output speed or heading but don't want to
Expand Down

0 comments on commit aa9f739

Please sign in to comment.