Object (@NotNull List<@NotNull TextChunk> chunks) { AttributesFlyweight defaultFlyweight = defaultAttributes().getFlyweight(); if (ContainerUtil.and(chunks, chunk -> !chunk.myAttributes.equals(defaultFlyweight))) { return chunks.size() == 1 ? chunks.get(0) // TextChunk : chunks.toArray(EMPTY_ARRAY); // TextChunk[] with non-default attributes } List<Object> result = ContainerUtil.map(chunks, chunk -> chunk.myAttributes.equals(defaultFlyweight) ? chunk.myText : chunk); return result.size() == 1 ? result.get(0) // String : ArrayUtil.toObjectArray(result); // Object[] with String or TextChunk elements }