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