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

Last change on this file since 805 was 804, checked in by wouter, 7 months ago

#278 added NonNull annotation in many places in the geniusweb code

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