code: public static double calculateContrastRatio(double lum1, double lum2) {
          if ((lum1 < 0.0d) || (lum2 < 0.0d)) {
              throw new IllegalArgumentException("Luminance values may not be negative.");
          }
  
          return (Math.max(lum1, lum2) + 0.05d) / (Math.min(lum1, lum2) + 0.05d);
      }
docs: Calculates the contrast ratio of two order-independent luminance values.
  <p>
  Derived from formula at http://gmazzocato.altervista.org/colorwheel/algo.php
  
  @param lum1 The first luminance value
  @param lum2 The second luminance value
  @return The contrast ratio of the luminance values
  @throws IllegalArgumentException if luminance values are < 0