Commit | Line | Data |
---|---|---|
1c118933 | 1 | public class Weight implements Comparable<Weight> { |
2bb2aa17 JB |
2 | private int min = 2; |
3 | private int max = 600; | |
4 | private int defaultWeight = 72; | |
97491195 JB |
5 | private int weight; |
6 | ||
b974e749 JB |
7 | Weight() { |
8 | } | |
9 | ||
97491195 JB |
10 | Weight(int weight) { |
11 | setWeight(weight); | |
12 | } | |
13 | ||
2bb2aa17 JB |
14 | public int getMin() { |
15 | return min; | |
16 | } | |
17 | ||
18 | public int getMax() { | |
19 | return max; | |
20 | } | |
21 | ||
22 | public int getDefaultWeight() { | |
23 | return defaultWeight; | |
24 | } | |
25 | ||
97491195 JB |
26 | public int getWeight() { |
27 | return weight; | |
28 | } | |
29 | ||
30 | public void setWeight(int weight) { | |
31 | if (validateWeight(weight)) { | |
32 | this.weight = weight; | |
bcdec887 | 33 | } else { |
2bb2aa17 | 34 | throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax()); |
bcdec887 | 35 | } |
97491195 JB |
36 | } |
37 | ||
38 | private boolean validateWeight(int weight) { | |
2bb2aa17 JB |
39 | return (weight >= getMin() && weight <= getMax()); |
40 | } | |
41 | ||
42 | public Integer[] getValuesArray() { | |
43 | int arrayLength = this.getMax() - this.getMin() + 1; | |
44 | Integer[] intArray = new Integer[arrayLength]; | |
45 | for (int i = 0; i < intArray.length; i++) { | |
46 | intArray[i] = this.getMin() + i; | |
47 | } | |
48 | return intArray; | |
97491195 | 49 | } |
1c118933 JB |
50 | |
51 | @Override | |
52 | public int compareTo(Weight weight) { | |
62e26730 | 53 | int distance = weight.getWeight() - this.getWeight(); |
613054ac JB |
54 | if (distance >= 0) |
55 | return distance; | |
56 | else | |
57 | return -distance; | |
1c118933 | 58 | } |
97491195 | 59 | } |