3 import java
.util
.Arrays
;
5 public class Eye
implements Comparable
<Eye
> {
7 private List
<String
> colorList
= Arrays
.asList("black", "green", "blue", "brown");
19 public Color
getColor() {
26 public void setColor(String color
) {
27 if (validateColor(color
)) {
28 if (color
.equals("brown"))
29 this.color
= new Color(88, 41, 0);
31 this.color
= Color
.getColor(color
);
34 throw new IllegalArgumentException("Color must be " + colorList
.toString());
42 private boolean validateColor(String color
) {
43 return colorList
.contains(color
);
51 public int compareTo(Eye eye
) {
52 double r_diff
= this.getColor().getRed() - eye
.getColor().getRed();
53 double g_diff
= this.getColor().getGreen() - eye
.getColor().getGreen();
54 double b_diff
= this.getColor().getBlue() - eye
.getColor().getBlue();
55 // See https://en.wikipedia.org/wiki/Color_difference
56 Double distance
= Math
.sqrt(2 * Math
.pow(r_diff
, 2) + 4 * Math
.pow(g_diff
, 2) + 3 * Math
.pow(b_diff
, 2));
57 return distance
.intValue();