Finish the WeightView by using a JComboBox.
[Persons_Comparator.git] / src / Size.java
index dfea96cdd8226c8dba12b50fa86423ceb2635658..a61f24cb79769b34c3a8e8b502542621232a81ed 100644 (file)
@@ -1,13 +1,23 @@
-
-public class Size {
+public class Size implements Comparable<Size> {
     private int max = 240;
-    private int min = 20;
+    private int min = 40;
     private int size;
 
+    Size() {
+    }
+
     Size(int size) {
         setSize(size);
     }
 
+    public int getMin() {
+        return min;
+    }
+
+    public int getMax() {
+        return max;
+    }
+
     public int getSize() {
         return size;
     }
@@ -16,11 +26,21 @@ public class Size {
         if (validateSize(size)) {
             this.size = size;
         } else {
-            throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max);
+            throw new IllegalArgumentException("Size must be between " + this.getMin() + " and " + this.getMax());
         }
     }
 
     private boolean validateSize(int size) {
-        return (size > max || size < min);
+        return (size >= getMin() && size <= getMax());
+    }
+
+    @Override
+    public int compareTo(Size size) {
+        int distance = size.getSize() - this.getSize();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
+
     }
 }