ContrastChecker { public static double getConstrastRatio5DigitRound(final Color fgColor, final Color bgColor) { double fgLuminosity = getLuminosity(fgColor); double bgLuminosity = getLuminosity(bgColor); if (fgLuminosity > bgLuminosity) { return (double) Math.round(computeContrast(fgLuminosity, bgLuminosity) * ROUND_VALUE) / ROUND_VALUE; } else { return (double) Math.round(computeContrast(bgLuminosity, fgLuminosity) * ROUND_VALUE) / ROUND_VALUE; } } private  ContrastChecker(); static double distanceColor(final Color fgColor, final Color bgColor); static boolean isContrastValid(final Color fgColor, final Color bgColor, Float coefficientLevel); static double getConstrastRatio(final Color fgColor, final Color bgColor); static double getConstrastRatio5DigitRound(final Color fgColor, final Color bgColor); static double getConstrastRatio2DigitRound(final Color fgColor, final Color bgColor); static double getLuminosity(Color color);  }
@Test public void testgetConstrastRatio5DigitRound() { Color colorA = new Color(70, 136, 71); Color colorB = new Color(223, 240, 216); Color colorC = new Color(138, 157, 138); Color colorD = new Color(156, 239, 123); double result = ContrastChecker.getConstrastRatio5DigitRound(colorA, colorB); System.out.println("getConstrastRatio5DigitRound : [#468847] and [#DFF0D8] = ["+ result +"] "); assertEquals(3.61029, result, 0.00000001); result = ContrastChecker.getConstrastRatio5DigitRound(colorB, colorA); System.out.println("getConstrastRatio5DigitRound : [#DFF0D8] and [#468847] = ["+ result +"] "); assertEquals(3.61029, result, 0.00000001); result = ContrastChecker.getConstrastRatio5DigitRound(colorC, colorD); System.out.println("getConstrastRatio5DigitRound : [#8A9D8A] and [#9CEF7B] = ["+ result +"] "); assertEquals(2.0695, result, 0.00000001); result = ContrastChecker.getConstrastRatio5DigitRound(colorD, colorC); System.out.println("getConstrastRatio5DigitRound : [#9CEF7B] and [#8A9D8A] = ["+ result +"] "); assertEquals(2.06950, result, 0.00000001); }