List<Color> (@NotNull List<? extends Color> anchorColors, int colorsBetweenAnchors) { assert colorsBetweenAnchors >= 0; if (anchorColors.isEmpty()) return Collections.singletonList(JBColor.GRAY); if (anchorColors.size() == 1) return Collections.singletonList(anchorColors.get(0)); int segmentCount = anchorColors.size() - 1; List<Color> result = new ArrayList<>(anchorColors.size() + segmentCount * colorsBetweenAnchors); result.add(anchorColors.get(0)); for (int i = 0; i < segmentCount; i++) { Color color1 = anchorColors.get(i); Color color2 = anchorColors.get(i + 1); List<Color> linearColors = generateLinearColorSequence(color1, color2, colorsBetweenAnchors); // skip first element from sequence to avoid duplication from connected segments result.addAll(linearColors.subList(1, linearColors.size())); } return result; }