Commit | Line | Data |
---|---|---|
5687dc10 | 1 | public class Size { |
97491195 | 2 | private int max = 240; |
476910ab | 3 | private int min = 40; |
5687dc10 | 4 | private int defaultSize = 160; |
97491195 JB |
5 | private int size; |
6 | ||
b974e749 JB |
7 | Size() { |
8 | } | |
9 | ||
97491195 JB |
10 | Size(int size) { |
11 | setSize(size); | |
12 | } | |
13 | ||
476910ab JB |
14 | public int getMin() { |
15 | return min; | |
16 | } | |
17 | ||
18 | public int getMax() { | |
19 | return max; | |
20 | } | |
21 | ||
5687dc10 JB |
22 | public int getDefaultSize() { |
23 | return defaultSize; | |
24 | } | |
25 | ||
97491195 JB |
26 | public int getSize() { |
27 | return size; | |
28 | } | |
29 | ||
30 | public void setSize(int size) { | |
31 | if (validateSize(size)) { | |
32 | this.size = size; | |
bcdec887 | 33 | } else { |
476910ab | 34 | throw new IllegalArgumentException("Size must be between " + this.getMin() + " and " + this.getMax()); |
bcdec887 | 35 | } |
97491195 JB |
36 | } |
37 | ||
38 | private boolean validateSize(int size) { | |
2bb2aa17 | 39 | return (size >= getMin() && size <= getMax()); |
97491195 | 40 | } |
1c118933 | 41 | |
5687dc10 | 42 | public int distanceTo(Size size) { |
62e26730 | 43 | int distance = size.getSize() - this.getSize(); |
5687dc10 | 44 | return Math.abs(distance); |
1c118933 | 45 | } |
97491195 | 46 | } |