Finish the WeightView by using a JComboBox.
[Persons_Comparator.git] / src / Size.java
CommitLineData
1c118933 1public class Size implements Comparable<Size> {
97491195 2 private int max = 240;
476910ab 3 private int min = 40;
97491195
JB
4 private int size;
5
b974e749
JB
6 Size() {
7 }
8
97491195
JB
9 Size(int size) {
10 setSize(size);
11 }
12
476910ab
JB
13 public int getMin() {
14 return min;
15 }
16
17 public int getMax() {
18 return max;
19 }
20
97491195
JB
21 public int getSize() {
22 return size;
23 }
24
25 public void setSize(int size) {
26 if (validateSize(size)) {
27 this.size = size;
bcdec887 28 } else {
476910ab 29 throw new IllegalArgumentException("Size must be between " + this.getMin() + " and " + this.getMax());
bcdec887 30 }
97491195
JB
31 }
32
33 private boolean validateSize(int size) {
2bb2aa17 34 return (size >= getMin() && size <= getMax());
97491195 35 }
1c118933
JB
36
37 @Override
38 public int compareTo(Size size) {
62e26730 39 int distance = size.getSize() - this.getSize();
613054ac
JB
40 if (distance >= 0)
41 return distance;
42 else
43 return -distance;
44
1c118933 45 }
97491195 46}