summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java
diff options
context:
space:
mode:
authorErich Schubert <erich@debian.org>2012-12-14 20:45:15 +0100
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:35 +0000
commit357b2761a2c0ded8cad5e4d3c1e667b7639ff7a6 (patch)
tree3dd8947bb70a67c221adc3cd4359ba1d385e2f3c /src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java
parent4343785ebed9d4145f417d86d581f18a0d31e4ac (diff)
parentb7b404fd7a726774d442562d11659d7b5368cdb9 (diff)
Import Debian changes 0.5.5-1
elki (0.5.5-1) unstable; urgency=low * New upstream release: 0.5.5 interim release.
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java85
1 files changed, 51 insertions, 34 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java b/src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java
index ca84fbfd..acf72c8d 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancevalue/DoubleDistance.java
@@ -28,6 +28,8 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.regex.Pattern;
+import de.lmu.ifi.dbs.elki.utilities.FormatUtil;
+
/**
* Provides a Distance for a double-valued distance.
*
@@ -35,9 +37,24 @@ import java.util.regex.Pattern;
*/
public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
/**
+ * Zero distance constant
+ */
+ public static final DoubleDistance ZERO_DISTANCE = new DoubleDistance(0.0);
+
+ /**
+ * Infinite distance constant
+ */
+ public static final DoubleDistance INFINITE_DISTANCE = new DoubleDistance(Double.POSITIVE_INFINITY);
+
+ /**
+ * Undefined distance constant
+ */
+ public static final DoubleDistance UNDEFINED_DISTANCE = new DoubleDistance(Double.NaN);
+
+ /**
* The static factory instance
*/
- public final static DoubleDistance FACTORY = new DoubleDistance();
+ public static final DoubleDistance FACTORY = UNDEFINED_DISTANCE;
/**
* The actual value.
@@ -118,7 +135,7 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
*/
@Override
public void readExternal(ObjectInput in) throws IOException {
- setValue(in.readDouble());
+ this.value = in.readDouble();
}
/**
@@ -133,16 +150,6 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
}
@Override
- public Double getValue() {
- return this.value;
- }
-
- @Override
- void setValue(Double value) {
- this.value = value;
- }
-
- @Override
public double doubleValue() {
return value;
}
@@ -157,25 +164,13 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
return Double.compare(this.value, other.value);
}
- @Override
- public boolean equals(Object o) {
- if(this == o) {
- return true;
- }
- if(o == null || getClass() != o.getClass()) {
- return false;
- }
- double delta = Math.abs(value - ((DoubleDistance) o).value);
- return delta < Double.MIN_NORMAL;
- }
-
/**
* An infinite DoubleDistance is based on {@link Double#POSITIVE_INFINITY
* Double.POSITIVE_INFINITY}.
*/
@Override
public DoubleDistance infiniteDistance() {
- return new DoubleDistance(Double.POSITIVE_INFINITY);
+ return INFINITE_DISTANCE;
}
/**
@@ -183,7 +178,7 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
*/
@Override
public DoubleDistance nullDistance() {
- return new DoubleDistance(0.0);
+ return ZERO_DISTANCE;
}
/**
@@ -191,7 +186,7 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
*/
@Override
public DoubleDistance undefinedDistance() {
- return new DoubleDistance(Double.NaN);
+ return UNDEFINED_DISTANCE;
}
/**
@@ -199,13 +194,12 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
*/
@Override
public DoubleDistance parseString(String val) throws IllegalArgumentException {
- if(val.equals(INFINITY_PATTERN)) {
+ if (val.equals(INFINITY_PATTERN)) {
return infiniteDistance();
}
- if(testInputPattern(val)) {
+ if (testInputPattern(val)) {
return new DoubleDistance(Double.parseDouble(val));
- }
- else {
+ } else {
throw new IllegalArgumentException("Given pattern \"" + val + "\" does not match required pattern \"" + requiredInputPattern() + "\"");
}
}
@@ -217,7 +211,7 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
@Override
public boolean isNullDistance() {
- return (value == 0.0);
+ return (value <= 0.0);
}
@Override
@@ -231,8 +225,31 @@ public class DoubleDistance extends NumberDistance<DoubleDistance, Double> {
}
@Override
+ public String toString() {
+ return FormatUtil.NF8.format(value);
+ }
+
+ @Override
public int hashCode() {
- long bits = Double.doubleToLongBits(value);
+ final long bits = Double.doubleToLongBits(value);
return (int) (bits ^ (bits >>> 32));
}
-} \ No newline at end of file
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DoubleDistance other = (DoubleDistance) obj;
+ if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value)) {
+ return false;
+ }
+ return true;
+ }
+}