X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FEye.java;h=ed2231b7aaa81da839726fea50b760f917f178f3;hb=f1e9d6d2fcc7253b117278c4439b656a1e532e68;hp=6edc8a563d99af95b373270e2936592551bcf2c7;hpb=089fcbfccd75b77daf843b22e128beeee1d1dc07;p=Persons_Comparator.git diff --git a/src/Eye.java b/src/Eye.java index 6edc8a5..ed2231b 100644 --- a/src/Eye.java +++ b/src/Eye.java @@ -1,10 +1,11 @@ import java.awt.Color; -import java.util.List; -import java.util.Arrays; public class Eye implements Comparable { private Color color; - private List colorList = Arrays.asList("black", "green", "blue", "brown"); + private String[] colorsList = {"black", "green", "blue", "brown"}; + + Eye() { + } /** * @param color @@ -13,6 +14,10 @@ public class Eye implements Comparable { setColor(color); } + public String[] getColorsList() { + return colorsList; + } + /** * @return */ @@ -31,7 +36,7 @@ public class Eye implements Comparable { this.color = Color.getColor(color); } else { - throw new IllegalArgumentException("Color must be " + colorList.toString()); + throw new IllegalArgumentException("Color must be " + colorsList); } } @@ -40,7 +45,12 @@ public class Eye implements Comparable { * @return */ private boolean validateColor(String color) { - return colorList.contains(color); + for (String c : colorsList) { + if (color.equals(c)) { + return true; + } + } + return false; } /** @@ -52,7 +62,7 @@ public class Eye implements Comparable { 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(); }