Implement the person comparator :
[Persons_Comparator.git] / src / Size.java
index c2392073b34662affdc474f619a1ab27519e2a98..eb8003f542104a9249658a2b118a8f758c0f8814 100644 (file)
@@ -1,12 +1,28 @@
-public class Size implements Comparable<Size> {
+public class Size {
     private int max = 240;
-    private int min = 20;
+    private int min = 40;
+    private int defaultSize = 160;
     private int size;
 
+    Size() {
+    }
+
     Size(int size) {
         setSize(size);
     }
 
+    public int getMin() {
+        return min;
+    }
+
+    public int getMax() {
+        return max;
+    }
+
+    public int getDefaultSize() {
+        return defaultSize;
+    }
+
     public int getSize() {
         return size;
     }
@@ -15,21 +31,16 @@ public class Size implements Comparable<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.size - this.getSize();
-        if (distance >= 0)
-            return distance;
-        else
-            return -distance;
-
+    public int distanceTo(Size size) {
+        int distance = size.getSize() - this.getSize();
+        return Math.abs(distance);
     }
 }