A lib directory to the project with gson library.
[Persons_Comparator.git] / src / Eye.java
index c3b836d0046eccc52afc27217ef72b379df51ec9..ed2231b7aaa81da839726fea50b760f917f178f3 100644 (file)
@@ -1,21 +1,24 @@
 import java.awt.Color;
-import java.util.List;
-import java.util.Arrays;
 
 public class Eye implements Comparable<Eye> {
     private Color color;
-    private List<String> colorList = Arrays.asList("black", "green", "blue", "brown");
+    private String[] colorsList = {"black", "green", "blue", "brown"};
+
+    Eye() {
+    }
 
     /**
-     *
      * @param color
      */
     Eye(String color) {
         setColor(color);
     }
 
+    public String[] getColorsList() {
+        return colorsList;
+    }
+
     /**
-     *
      * @return
      */
     public Color getColor() {
@@ -23,7 +26,6 @@ public class Eye implements Comparable<Eye> {
     }
 
     /**
-     *
      * @param color
      */
     public void setColor(String color) {
@@ -34,21 +36,24 @@ public class Eye implements Comparable<Eye> {
                 this.color = Color.getColor(color);
 
         } else {
-            throw new IllegalArgumentException("Color must be " + colorList.toString());
+            throw new IllegalArgumentException("Color must be " + colorsList);
         }
     }
 
     /**
-     *
      * @param color
      * @return
      */
     private boolean validateColor(String color) {
-        return colorList.contains(color);
+        for (String c : colorsList) {
+            if (color.equals(c)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**
-     *
      * @param eye
      * @return
      */
@@ -57,7 +62,7 @@ public class Eye implements Comparable<Eye> {
         double r_diff = this.getColor().getRed() - eye.getColor().getRed();
         double g_diff = this.getColor().getGreen() - eye.getColor().getGreen();
         double b_diff = this.getColor().getBlue() - eye.getColor().getBlue();
-        // See https://en.wikipedia.org/wiki/Color_difference
+        //See https://en.wikipedia.org/wiki/Color_difference
         Double distance = Math.sqrt(2 * Math.pow(r_diff, 2) + 4 * Math.pow(g_diff, 2) + 3 * Math.pow(b_diff, 2));
         return distance.intValue();
     }