1 package de.fhdw.wtf.context.model;
2
3 import java.math.BigInteger;
4
5 import de.fhdw.wtf.persistence.meta.IntegerValue;
6
7
8
9
10 public final class Int extends AnyValue {
11
12
13
14
15 private final BigInteger value;
16
17
18
19
20
21
22
23 public Int(final BigInteger value) {
24 this.value = value;
25 }
26
27
28
29
30
31
32
33 public Int(final IntegerValue value) {
34 this(value.getValue());
35 }
36
37
38
39
40
41
42
43 public Int(final String value) {
44 this(new BigInteger(value));
45 }
46
47
48
49
50
51
52
53 public Int(final long value) {
54 this(BigInteger.valueOf(value));
55 }
56
57
58
59
60
61
62
63
64 public Int add(final Int summand) {
65 return new Int(this.value.add(summand.value));
66 }
67
68
69
70
71
72
73
74
75 public Int sub(final Int subtrahend) {
76 return new Int(this.value.subtract(subtrahend.value));
77 }
78
79
80
81
82
83
84
85
86 public Int mul(final Int factor) {
87 return new Int(this.value.multiply(factor.value));
88 }
89
90
91
92
93
94
95
96
97 public Int div(final Int divisor) {
98 return new Int(this.value.divide(divisor.value));
99 }
100
101
102
103
104
105
106
107
108 public boolean lessEq(final Int compareTo) {
109 return this.value.compareTo(compareTo.value) <= 0;
110 }
111
112 @Override
113 public boolean equals(final Object obj) {
114 if (obj instanceof Int) {
115 final Int other = (Int) obj;
116 return this.value.equals(other.value);
117 }
118 return false;
119 }
120
121
122
123
124
125
126 public BigInteger getVal() {
127 return this.value;
128 }
129
130 @Override
131 public int hashCode() {
132 return this.value.hashCode();
133 }
134
135 @Override
136 public String toString() {
137 return this.value.toString();
138 }
139
140 }