/** * Convert a value into meters * * @param distance distance in this unit * @return value in meters */ public double toMeters(double distance) { return convert(distance, this, DistanceUnit.METERS); }
/** * Convert a value given in meters to a value of this unit * * @param distance distance in meters * @return value in this unit */ public double fromMeters(double distance) { return convert(distance, DistanceUnit.METERS, this); }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } else if (obj instanceof Distance) { Distance other = (Distance) obj; return DistanceUnit.convert(value, unit, other.unit) == other.value; } else { return false; } }
/** * Convert a given value into another unit * * @param distance value in this unit * @param unit source unit * @return value in this unit */ public double convert(double distance, DistanceUnit unit) { return convert(distance, unit, this); }
/** * Parses a given distance and converts it to the specified unit. * * @param distance String defining a distance (value and unit) * @param defaultUnit unit assumed if none is defined * @param to unit of result * @return parsed distance */ public static double parse(String distance, DistanceUnit defaultUnit, DistanceUnit to) { Distance dist = Distance.parseDistance(distance, defaultUnit); return convert(dist.value, dist.unit, to); }
@Override public int compareTo(Distance o) { return Double.compare(value, DistanceUnit.convert(o.value, o.unit, unit)); }
/** compute the distance between two points using the selected algorithm (PLANE, ARC) */ public double calculate(double srcLat, double srcLon, double dstLat, double dstLon, DistanceUnit unit) { if (this == PLANE) { return DistanceUnit.convert(GeoUtils.planeDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } return DistanceUnit.convert(GeoUtils.arcDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } }
/** * Converts a {@link Distance} value given in a specific {@link DistanceUnit} into * a value equal to the specified value but in a other {@link DistanceUnit}. * * @param unit unit of the result * @return converted distance */ public Distance convert(DistanceUnit unit) { if(this.unit == unit) { return this; } else { return new Distance(DistanceUnit.convert(value, this.unit, unit), unit); } }
/** * Convert a value into meters * * @param distance distance in this unit * @return value in meters */ public double toMeters(double distance) { return convert(distance, this, DistanceUnit.METERS); }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } else if (obj instanceof Distance) { Distance other = (Distance) obj; return DistanceUnit.convert(value, unit, other.unit) == other.value; } else { return false; } }
/** * Convert a value given in meters to a value of this unit * * @param distance distance in meters * @return value in this unit */ public double fromMeters(double distance) { return convert(distance, DistanceUnit.METERS, this); }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } else if (obj instanceof Distance) { Distance other = (Distance) obj; return DistanceUnit.convert(value, unit, other.unit) == other.value; } else { return false; } }
/** * Convert a value given in meters to a value of this unit * * @param distance distance in meters * @return value in this unit */ public double fromMeters(double distance) { return convert(distance, DistanceUnit.METERS, this); }
/** * Parses a given distance and converts it to the specified unit. * * @param distance String defining a distance (value and unit) * @param defaultUnit unit assumed if none is defined * @param to unit of result * @return parsed distance */ public static double parse(String distance, DistanceUnit defaultUnit, DistanceUnit to) { Distance dist = Distance.parseDistance(distance, defaultUnit); return convert(dist.value, dist.unit, to); }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } else if (obj instanceof Distance) { Distance other = (Distance) obj; return DistanceUnit.convert(value, unit, other.unit) == other.value; } else { return false; } }
/** * Convert a value into meters * * @param distance distance in this unit * @return value in meters */ public double toMeters(double distance) { return convert(distance, this, DistanceUnit.METERS); }
/** * Convert a value given in meters to a value of this unit * * @param distance distance in meters * @return value in this unit */ public double fromMeters(double distance) { return convert(distance, DistanceUnit.METERS, this); }
/** * Parses a given distance and converts it to the specified unit. * * @param distance String defining a distance (value and unit) * @param defaultUnit unit assumed if none is defined * @param to unit of result * @return parsed distance */ public static double parse(String distance, DistanceUnit defaultUnit, DistanceUnit to) { Distance dist = Distance.parseDistance(distance, defaultUnit); return convert(dist.value, dist.unit, to); }
/** compute the distance between two points using the selected algorithm (PLANE, ARC) */ public double calculate(double srcLat, double srcLon, double dstLat, double dstLon, DistanceUnit unit) { if (this == PLANE) { return DistanceUnit.convert(GeoUtils.planeDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } return DistanceUnit.convert(GeoUtils.arcDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } }
/** compute the distance between two points using the selected algorithm (PLANE, ARC) */ public double calculate(double srcLat, double srcLon, double dstLat, double dstLon, DistanceUnit unit) { if (this == PLANE) { return DistanceUnit.convert(GeoUtils.planeDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } return DistanceUnit.convert(GeoUtils.arcDistance(srcLat, srcLon, dstLat, dstLon), DistanceUnit.METERS, unit); } }