WavePainter2D (Color color) { WavePainter2D painter = myPainters.get(color); if (painter == null) { painter = new WavePainter2D(color); // creating a new Color instance, as the one passed as parameter can be mutable (JBColor) and shouldn't be used as a map key //noinspection UseJBColor myPainters.put(new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()), painter); } return painter; }