/** * Moves all elements and annotations after the given position by * {@code shiftAmount}. * * @param position the anchor position. * @param shiftAmount the amount to shift the annotations range and elements * position. */ protected void shift(int position, int shiftAmount) { SortedMap<Integer, Element> newElements = new TreeMap<Integer, Element>(elements.headMap(position)); for (Entry<Integer, Element> element : elements.tailMap(position).entrySet()) { newElements.put(element.getKey() + shiftAmount, element.getValue()); } this.elements = newElements; SortedMap<Integer, BlipThread> newInlineReplyThreads = new TreeMap<Integer, BlipThread>(inlineReplyThreads.headMap(position)); for (Entry<Integer, BlipThread> entry : inlineReplyThreads.tailMap(position).entrySet()) { BlipThread thread = entry.getValue(); thread.setLocation(thread.getLocation() + shiftAmount); newInlineReplyThreads.put(thread.getLocation(), thread); } this.inlineReplyThreads = newInlineReplyThreads; this.annotations.shift(position, shiftAmount); }