source: issuevalue/src/main/java/geniusweb/issuevalue/NumberValue.java

Last change on this file was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.4 KB
Line 
1package geniusweb.issuevalue;
2
3import java.math.BigDecimal;
4
5import com.fasterxml.jackson.annotation.JsonValue;
6
7/**
8 * A value containing a number, that should be in some {@link NumberValueSet}.
9 * immutable
10 */
11public class NumberValue implements Value {
12 @JsonValue // deserializes nicely but needs custom deserializer.
13 private final BigDecimal value;
14
15 public NumberValue(String vnew) {
16 this.value = new BigDecimal(vnew);
17 }
18
19 public NumberValue(BigDecimal vnew) {
20 this.value = vnew;
21 }
22
23 public BigDecimal getValue() {
24 return value;
25 }
26
27 @Override
28 public String toString() {
29 return value.toString();
30 }
31
32 @Override
33 public int hashCode() {
34 // WORKAROUND FOR BigDecimal hashCode. NOT auto generated.
35 // Very large numbers and numbers that differ only in a fraction
36 // beyond reach of double may get the same hashcode,
37 // but this is not an issue as equal hashcode only indicates that
38 // numbers MAY be equal.
39 return Double.hashCode(value.doubleValue());
40 }
41
42 @Override
43 public boolean equals(Object obj) {
44 if (this == obj)
45 return true;
46 if (obj == null)
47 return false;
48 if (getClass() != obj.getClass())
49 return false;
50 NumberValue other = (NumberValue) obj;
51 if (value == null) {
52 if (other.value != null)
53 return false;
54 } else if (value.compareTo(other.value) != 0)
55 // MANUAL FIX, DO NOT USE value.equals
56 return false;
57 return true;
58 }
59
60}
Note: See TracBrowser for help on using the repository browser.