/** * 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); }
public void testShift() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.shift(2, 3); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); assertEquals(new Range(6, 8), annotations.get("name2").get(0).getRange()); assertEquals(new Range(13, 18), annotations.get("name2").get(1).getRange()); annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name", "value", 5, 8); annotations.shift(5, -2); assertEquals(1, annotations.get("name").size()); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); } }
public void testShift() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.shift(2, 3); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); assertEquals(new Range(6, 8), annotations.get("name2").get(0).getRange()); assertEquals(new Range(13, 18), annotations.get("name2").get(1).getRange()); annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name", "value", 5, 8); annotations.shift(5, -2); assertEquals(1, annotations.get("name").size()); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); } }