private void initializeColors() { double min = getLowValue(); double max = getHighValue(); Color[] colorGradient = getColorGradient(); doubleToColor = new Function<Double, Color>() { @Override public Color apply(Double t) { if (isNaN(t)) { return nanColor; } else { double normalized = normalize(checkRange(t), max, min); int colorIndex = (int) ((normalized * (DEFAULT_STEPS - 1))); return colorGradient[colorIndex]; } } private double checkRange(Double t) { if (t > max) { return max; } else if (t < min) { return min; } else { return t; } } private double normalize(double d, double max, double min) { return (d - min) / (max - min); } }; this.updateUI(); }