public void testDelete() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 2); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.delete("name", 2, 3); assertEquals(1, annotations.get("name").size()); annotations.delete("name", 1, 2); assertNull(annotations.get("name")); annotations.delete("name2", 1, 6); assertEquals(1, annotations.get("name2").size()); annotations.delete("name2", 10, 12); assertEquals(1, annotations.get("name2").size()); assertEquals(new Range(12, 15), annotations.get("name2").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()); } }
public void testAdd() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 3, 5); assertEquals(1, annotations.get("name").size()); annotations.add("name", "value", 1, 2); annotations.add("name", "value", 10, 15); assertEquals(3, annotations.get("name").size()); annotations.add("name", "value", 4, 7); assertEquals(3, annotations.get("name").size()); assertEquals(new Range(3, 7), annotations.get("name").get(2).getRange()); annotations.add("name", "value2", 6, 7); assertEquals(4, annotations.get("name").size()); assertEquals(new Range(3, 6), annotations.get("name").get(2).getRange()); assertEquals("value", annotations.get("name").get(2).getValue()); assertEquals(new Range(6, 7), annotations.get("name").get(3).getRange()); assertEquals("value2", annotations.get("name").get(3).getValue()); }
assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 6), blip.getAnnotations().get(key).get(0)); assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 8), blip.getAnnotations().get(key).get(0)); assertEquals(1, blip.getAnnotations().size()); assertEquals(2, blip.getAnnotations().get(key).size()); assertEquals(new Annotation(key, "bold", 3, 4), blip.getAnnotations().get(key).get(0)); assertEquals(new Annotation(key, "italic", 4, 12), blip.getAnnotations().get(key).get(1)); assertEquals(3, blip.getAnnotations().get(key).size()); assertEquals(new Annotation(key, "bold", 3, 4), blip.getAnnotations().get(key).get(0)); assertEquals(new Annotation(key, "italic", 4, 6), blip.getAnnotations().get(key).get(1)); assertEquals(new Annotation(key, "italic", 7, 12), blip.getAnnotations().get(key).get(2)); assertEquals(1, blip.getAnnotations().namesSet().size()); assertEquals(2, blip.getAnnotations().namesSet().size()); assertEquals(3, blip.getAnnotations().get(key).size()); assertEquals(1, blip.getAnnotations().get("foo").size()); blip.range(3, 5).clearAnnotation("foo"); assertNull(blip.getAnnotations().get(key));
/** * Return true if the given blip is a blip in which Echoey has written. */ private boolean isShadowBlip(Blip blip) { List<Annotation> annotations = blip.getAnnotations().get(ECHOEY_ANNOTATION); return annotations != null && !annotations.isEmpty(); } }
public void testBundledAnnotations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().insert(BundledAnnotation.listOf("style", "bold"), "\nhello"); assertEquals(2, blip.getAnnotations().size()); assertEquals(new Annotation("style", "bold", 0, 6), blip.getAnnotations().get("style").get(0)); }
this.thread = wavelet.getThread(threadId); this.annotations = new Annotations(); for (Annotation annotation : annotations) { this.annotations.add(annotation.getName(), annotation.getValue(), annotation.getRange().getStart(), annotation.getRange().getEnd());
case ANNOTATE: Annotation annotation = Annotation.class.cast(next); blip.getAnnotations().add(annotation.getName(), annotation.getValue(), start, end); break; case CLEAR_ANNOTATION: String annotationName = arguments[0].toString(); blip.getAnnotations().delete(annotationName, start, end); break; case UPDATE_ELEMENT: } else if (bundledAnnotations != null) { for (BundledAnnotation bundled : bundledAnnotations) { blip.getAnnotations().add(bundled.key, bundled.value, start, start + text.length());
/** * 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 testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, null, Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }
public void testAdd() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 3, 5); assertEquals(1, annotations.get("name").size()); annotations.add("name", "value", 1, 2); annotations.add("name", "value", 10, 15); assertEquals(3, annotations.get("name").size()); annotations.add("name", "value", 4, 7); assertEquals(3, annotations.get("name").size()); assertEquals(new Range(3, 7), annotations.get("name").get(2).getRange()); annotations.add("name", "value2", 6, 7); assertEquals(4, annotations.get("name").size()); assertEquals(new Range(3, 6), annotations.get("name").get(2).getRange()); assertEquals("value", annotations.get("name").get(2).getValue()); assertEquals(new Range(6, 7), annotations.get("name").get(3).getRange()); assertEquals("value2", annotations.get("name").get(3).getValue()); }
assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 6), blip.getAnnotations().get(key).get(0)); assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 8), blip.getAnnotations().get(key).get(0)); assertEquals(1, blip.getAnnotations().size()); assertEquals(2, blip.getAnnotations().get(key).size()); assertEquals(new Annotation(key, "bold", 3, 4), blip.getAnnotations().get(key).get(0)); assertEquals(new Annotation(key, "italic", 4, 12), blip.getAnnotations().get(key).get(1)); assertEquals(3, blip.getAnnotations().get(key).size()); assertEquals(new Annotation(key, "bold", 3, 4), blip.getAnnotations().get(key).get(0)); assertEquals(new Annotation(key, "italic", 4, 6), blip.getAnnotations().get(key).get(1)); assertEquals(new Annotation(key, "italic", 7, 12), blip.getAnnotations().get(key).get(2)); assertEquals(1, blip.getAnnotations().namesSet().size()); assertEquals(2, blip.getAnnotations().namesSet().size()); assertEquals(3, blip.getAnnotations().get(key).size()); assertEquals(1, blip.getAnnotations().get("foo").size()); blip.range(3, 5).clearAnnotation("foo"); assertNull(blip.getAnnotations().get(key));
/** * Updates the shadow map for a given wavelet. */ private void updateShadowMap(Wavelet wavelet) { for (Blip blip : wavelet.getBlips().values()) { if (isShadowBlip(blip)) { String shadowBlipId = blip.getBlipId(); if (!shadowBlipMap.containsValue(shadowBlipId)) { String originalBlipId = blip.getAnnotations().get(ECHOEY_ANNOTATION).get(0).getValue(); shadowBlipMap.put(originalBlipId, shadowBlipId); } } } }
public void testBundledAnnotations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().insert(BundledAnnotation.listOf("style", "bold"), "\nhello"); assertEquals(2, blip.getAnnotations().size()); assertEquals(new Annotation("style", "bold", 0, 6), blip.getAnnotations().get("style").get(0)); }
public void testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, "<some string>", Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }
public void testDelete() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 2); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.delete("name", 2, 3); assertEquals(1, annotations.get("name").size()); annotations.delete("name", 1, 2); assertNull(annotations.get("name")); annotations.delete("name2", 1, 6); assertEquals(1, annotations.get("name2").size()); annotations.delete("name2", 10, 12); assertEquals(1, annotations.get("name2").size()); assertEquals(new Range(12, 15), annotations.get("name2").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()); } }
public void testInsertBeforeAnnotationStartPoint() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 4, 9))); blip.at(4).insert("d and"); assertEquals(new Range(9, 14), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testInsertBeforeAnnotationStartPoint() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 4, 9))); blip.at(4).insert("d and"); assertEquals(new Range(9, 14), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }