Color { @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof Color)) { return false; } Color otherColor = (Color) other; return (Math.abs(otherColor.cyan - cyan) < 0.000001 && Math.abs(otherColor.magenta - magenta) < 0.000001 && Math.abs(otherColor.yellow - yellow) < 0.000001); } Color(double cyan, double magenta, double yellow);  Color(int rgb); final double getCyan(); final double getMagenta(); final double getYellow(); final double getR(); final double getG(); final double getB(); int getRGB(); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testEquals() { Color color1 = new Color(0.5, 0.5, 0.5); Color color2 = new Color(0.5, 0.5, 0.5); assertTrue(color1.equals(color2)); assertTrue(color2.equals(color1)); assertFalse(color1.equals(null)); assertFalse(color1.equals("test")); color2 = new Color(0.5, 0.5, 0.6); assertFalse(color1.equals(color2)); assertFalse(color2.equals(color1)); }