I apologize in advance for the intrusiveness.
But either I don’t understand something, or is there something wrong with the condition of the problem !? Immediately I say that I need to understand it correctly (condition). I will do the implementation myself.
Here is the condition:
Implement the interface mechanism for smart number assignment to list items.
public interface IElementNumberAssigner { /** * Метод выставляет номера {IElement#setupNumber(int)} * для элементов коллекции {elements} * в порядке следования элементов в коллекции. * * Изначально коллекция не содержит элементов, номера которых повторяются. * * При этом обеспечиваются слеюущие условия: * метод работает только с существующими элементами (не создает новых), * на протяжении всей работы метода обеспечивается уникальность номеров элементов: * вызов {element.setNumber(i)} разрешен ⇔ ∀ e ∊ {elements} (e.number ≠ i), * метод устойчив к передаче в него в качестве параметра {java.util.Collections#unmodifiableList(List)} и любой другой реализации immutable-list, * метод должен работать за «приемлемое» время ({IElement#setupNumber(int)} - трудоемкая операция и пользоваться ей надо рационально) * * elements элементы, которым нужно выставить номера */ void assignNumbers(List<IElement> elements);
}
I have a question: what's the catch?
Is it not possible just to run from the beginning to the end of the list and assign a number to each element in order? What is the difficulty I do not understand?