String (@NotNull Color color, String colorMethodName, String grayMethodName, IntFunction<String> formatter) { String methodName; StringJoiner args = new StringJoiner(",", "(", ")"); if (color.getRed() == color.getGreen() && color.getRed() == color.getBlue()) { methodName = grayMethodName; args.add(formatter.apply(color.getRed())); } else { methodName = colorMethodName; args.add(formatter.apply(color.getRed())); args.add(formatter.apply(color.getGreen())); args.add(formatter.apply(color.getBlue())); } if (color.getAlpha() != 255) { args.add(formatScaledComponent(color.getAlpha())); } return methodName + args; }