for (List<Annotation> annotations : store.values()) { for (Annotation annotation : annotations) { annotation.shift(position, shiftAmount); String name = annotation.getName(); String value = annotation.getValue(); int start = annotation.getRange().getStart(); int end = annotation.getRange().getEnd(); if (end < existingList.get(j).getRange().getStart()) { break; if (end == existingList.get(j).getRange().getStart() && value.equals(existingList.get(j).getValue())) { end = existingList.get(j).getRange().getEnd(); existingList.remove(j--); newList.add(new Annotation(name, value, start, end));
public void testShift() throws Exception { Annotation annotation = new Annotation("key", "value", 5 , 10); annotation.shift(4, 2); assertEquals(7, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(5, 3); assertEquals(8, annotation.getRange().getStart()); assertEquals(13, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(9, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(10, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); } }
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()); }
@Override public Annotation createInstance(Type type) { return new Annotation("", "", -1, -1); } }
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()); }
case ANNOTATE: Annotation annotation = Annotation.class.cast(next); blip.getAnnotations().add(annotation.getName(), annotation.getValue(), start, end); break; case CLEAR_ANNOTATION: values = new ArrayList<String>(arguments.length); for (Object item : arguments) { values.add(Annotation.class.cast(item).getValue()); annotationName = Annotation.class.cast(arguments[0]).getName(); break; case CLEAR_ANNOTATION:
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()); } }
/** * 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); } } } }
/** * Updates an existing shadow blip. * * @param shadowBlip the blip that is shadowing. * @param blipToShadow the blip being shadowed. */ private void updateShadowBlip(Blip shadowBlip, Blip blipToShadow) { Preconditions.checkNotNull(shadowBlip, "Shadow blip can't be null"); Preconditions.checkNotNull(blipToShadow, "Blip to shadow can't be null"); shadowBlip.all().replace(blipToShadow.getContent()); for (Annotation annotation : blipToShadow.getAnnotations()) { if (annotation.getName().equals(ECHOEY_ANNOTATION)) { continue; } shadowBlip.range(annotation.getRange().getStart(), annotation.getRange().getEnd()).annotate( annotation.getName(), annotation.getValue()); } shadowBlip.all().annotate(ECHOEY_ANNOTATION, blipToShadow.getBlipId()); shadowBlipMap.put(blipToShadow.getBlipId(), shadowBlip.getBlipId()); }
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 testShift() throws Exception { Annotation annotation = new Annotation("key", "value", 5 , 10); annotation.shift(4, 2); assertEquals(7, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(5, 3); assertEquals(8, annotation.getRange().getStart()); assertEquals(13, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(9, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(10, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); } }
/** * Annotates the contents at the matched positions. * * @param key the annotation key. * @param values the annotation values. * @return an instance of this blip references, for chaining. */ public BlipContentRefs annotate(String key, String... values) { if (values.length == 0) { values = new String[]{key}; } Annotation[] annotations = new Annotation[values.length]; for (int i = 0; i < values.length; ++i) { annotations[i] = new Annotation(key, values[i], 0, 1); } return execute(ModifyHow.ANNOTATE, null, (Object[]) annotations); }
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()); }
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()); } }
List<Annotation> newList = new ArrayList<Annotation>(); for (Annotation existing : store.get(name)) { if (start > existing.getRange().getEnd() || end < existing.getRange().getStart()) { newList.add(existing); } else if (start < existing.getRange().getStart() && end > existing.getRange().getEnd()) { continue; } else { if (existing.getRange().getStart() < start) { newList.add(new Annotation(existing.getName(), existing.getValue(), existing.getRange().getStart(), start)); if (existing.getRange().getEnd() > end) { newList.add(new Annotation(existing.getName(), existing.getValue(), end, existing.getRange().getEnd()));
public void testDeleteRangeThatSpansAcrossAnnotationEndPoint() throws Exception { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 3))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
private Blip newBlip(String blipId, List<String> childBlipIds, String parentBlipId) { return newBlip(blipId, childBlipIds, parentBlipId, Arrays.asList(new Annotation("key", "val", 2, 3))); }
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()); }