~ubuntu-branches/ubuntu/vivid/elki/vivid

« back to all changes in this revision

Viewing changes to src/de/lmu/ifi/dbs/elki/distance/distancevalue/NumberDistance.java

  • Committer: Package Import Robot
  • Author(s): Erich Schubert
  • Date: 2012-12-14 20:45:15 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20121214204515-4m0d0er9ivtu5w9d
Tags: 0.5.5-1
New upstream release: 0.5.5 interim release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
24
 */
25
25
 
26
 
 
27
26
/**
28
27
 * Provides a Distance for a number-valued distance.
29
28
 * 
42
41
  public NumberDistance() {
43
42
    super();
44
43
  }
45
 
  
 
44
 
46
45
  /**
47
46
   * Build a new instance from a double value.
48
47
   * 
52
51
  public abstract D fromDouble(double val);
53
52
 
54
53
  /**
55
 
   * Returns the hash code for this NumberDistance, which is the hash code of
56
 
   * its value.
57
 
   * 
58
 
   * @return the hash code of the value
59
 
   */
60
 
  @Override
61
 
  public int hashCode() {
62
 
    return getValue().hashCode();
63
 
  }
64
 
 
65
 
  /**
66
 
   * Compares this NumberDistance with the given NumberDistance wrt the
67
 
   * represented value.
68
 
   * <p/>
69
 
   * <code>d1.compareTo(d2)</code> is the same as
70
 
   * {@link Double#compare(double,double) Double.compare(d1.value.doubleValue(),
71
 
   * d2.value.doubleValue())}. Subclasses may need to overwrite this method if
72
 
   * necessary.
73
 
   * 
74
 
   * @param other Other object
75
 
   * @return a negative integer, zero, or a positive integer as the value of
76
 
   *         this NumberDistance is less than, equal to, or greater than the
77
 
   *         value of the specified NumberDistance.
78
 
   */
79
 
  @Override
80
 
  public int compareTo(D other) {
81
 
    return Double.compare(this.doubleValue(), other.doubleValue());
82
 
  }
83
 
 
84
 
  /**
85
 
   * Returns a string representation of this NumberDistance.
86
 
   * 
87
 
   * @return the value of this NumberDistance.
88
 
   */
89
 
  @Override
90
 
  public final String toString() {
91
 
    return getValue().toString();
92
 
  }
93
 
 
94
 
  /**
95
 
   * Returns the value of this NumberDistance.
96
 
   * 
97
 
   * @return the value of this NumberDistance
98
 
   */
99
 
  public abstract N getValue();
100
 
 
101
 
  /**
102
 
   * Sets the value of this NumberDistance.
103
 
   * 
104
 
   * @param value the value to be set
105
 
   */
106
 
  abstract void setValue(N value);
107
 
  
108
 
  /**
109
54
   * Get the value as double.
110
55
   * 
111
56
   * @return same result as getValue().doubleValue() but may be more efficient.
112
57
   */
113
58
  public abstract double doubleValue();
114
 
  
 
59
 
115
60
  /**
116
61
   * Get the value as float.
117
62
   * 
120
65
  public float floatValue() {
121
66
    return (float) doubleValue();
122
67
  }
123
 
  
 
68
 
124
69
  /**
125
70
   * Get the value as int.
126
71
   * 
129
74
  public int intValue() {
130
75
    return (int) longValue();
131
76
  }
132
 
  
 
77
 
133
78
  /**
134
79
   * Get the value as long.
135
80
   * 
136
81
   * @return same result as getValue().longValue() but may be more efficient.
137
82
   */
138
83
  public abstract long longValue();
139
 
  
 
84
 
140
85
  /**
141
86
   * Get the value as short.
142
87
   * 
145
90
  public short shortValue() {
146
91
    return (short) longValue();
147
92
  }
148
 
  
 
93
 
149
94
  /**
150
95
   * Get the value as byte.
151
96
   *