Commit | Line | Data |
---|---|---|
1c118933 | 1 | public class Size implements Comparable<Size> { |
97491195 JB |
2 | private int max = 240; |
3 | private int min = 20; | |
4 | private int size; | |
5 | ||
6 | Size(int size) { | |
7 | setSize(size); | |
8 | } | |
9 | ||
10 | public int getSize() { | |
11 | return size; | |
12 | } | |
13 | ||
14 | public void setSize(int size) { | |
15 | if (validateSize(size)) { | |
16 | this.size = size; | |
bcdec887 JB |
17 | } else { |
18 | throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max); | |
19 | } | |
97491195 JB |
20 | } |
21 | ||
22 | private boolean validateSize(int size) { | |
23 | return (size > max || size < min); | |
24 | } | |
1c118933 JB |
25 | |
26 | @Override | |
27 | public int compareTo(Size size) { | |
613054ac JB |
28 | int distance = size.size - this.getSize(); |
29 | if (distance >= 0) | |
30 | return distance; | |
31 | else | |
32 | return -distance; | |
33 | ||
1c118933 | 34 | } |
97491195 | 35 | } |