TextAttributes (final @NotNull TextAttributes targetAttributes) { Iterator<EffectDescriptor> effectsIterator = myEffectsMap.values().iterator(); if (!effectsIterator.hasNext()) { targetAttributes.setEffectColor(null); targetAttributes.setEffectType(BOXED); targetAttributes.setAdditionalEffects(Collections.emptyMap()); } else { EffectDescriptor mainEffectDescriptor = effectsIterator.next(); targetAttributes.setEffectType(mainEffectDescriptor.effectType); targetAttributes.setEffectColor(mainEffectDescriptor.effectColor); int effectsLeft = myEffectsMap.size() - 1; if (effectsLeft == 0) { targetAttributes.setAdditionalEffects(Collections.emptyMap()); } else if (effectsLeft == 1) { EffectDescriptor additionalEffect = effectsIterator.next(); targetAttributes.setAdditionalEffects(Collections.singletonMap(additionalEffect.effectType, additionalEffect.effectColor)); } else { Map<EffectType, Color> effectsMap = new EnumMap<>(EffectType.class); effectsIterator.forEachRemaining(descriptor -> effectsMap.put(descriptor.effectType, descriptor.effectColor)); targetAttributes.setAdditionalEffects(effectsMap); } } return targetAttributes; }