source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/issuevalue/NumberValue.java@ 692

Last change on this file since 692 was 526, checked in by wouter, 17 months ago

small fixes in java to fit translation requirements

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 // 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 @JsonValue
24 public BigDecimal getValue() {
25 return value;
26 }
27
28 @Override
29 public String toString() {
30 return value.toString();
31 }
32
33 @Override
34 public int hashCode() {
35 // WORKAROUND FOR BigDecimal hashCode. NOT auto generated.
36 // Very large numbers and numbers that differ only in a fraction
37 // beyond reach of double may get the same hashcode,
38 // but this is not an issue as equal hashcode only indicates that
39 // numbers MAY be equal.
40 return Double.hashCode(value.doubleValue());
41 }
42
43 @Override
44 public boolean equals(Object obj) {
45 if (this == obj)
46 return true;
47 if (obj == null)
48 return false;
49 if (getClass() != obj.getClass())
50 return false;
51 NumberValue other = (NumberValue) obj;
52 if (value == null) {
53 if (other.value != null)
54 return false;
55 } else if (value.compareTo(other.value) != 0)
56 // MANUAL FIX, DO NOT USE value.equals
57 return false;
58 return true;
59 }
60
61}
Note: See TracBrowser for help on using the repository browser.