private void doEndAnnotation(String key) { if (Annotations.isLocal(key)) { throw new IllegalArgumentException("Cannot access local annotations"); } annotations.endAnnotation(key); }
@Override public void setAnnotation(int start, int end, String key, Object value) { Preconditions.checkPositionIndexes(start, end, fullAnnotationSet.size()); checkLocalKey(key); if (end - start > 0) { fullAnnotationSet.begin(); if (start > 0) { fullAnnotationSet.skip(start); } fullAnnotationSet.startAnnotation(key, value); if (end - start > 0) { fullAnnotationSet.skip(end - start); } fullAnnotationSet.endAnnotation(key); fullAnnotationSet.finish(); } }
void setAnnotation(RawAnnotationSet<Object> a, int start, int end, String key, Object value) throws OperationException { a.begin(); if (start > 0) { a.skip(start); } a.startAnnotation(key, value); if (end - start > 0) { a.skip(end - start); } a.endAnnotation(key); a.finish(); }
void setAnnotation(RawAnnotationSet<Object> a, int start, int end, String key, Object value) throws OperationException { a.begin(); if (start > 0) { a.skip(start); } a.startAnnotation(key, value); if (end - start > 0) { a.skip(end - start); } a.endAnnotation(key); a.finish(); }
void setAnnotation(RawAnnotationSet<Object> a, int start, int end, String key, Object value) throws OperationException { a.begin(); if (start > 0) { a.skip(start); } a.startAnnotation(key, value); if (end - start > 0) { a.skip(end - start); } a.endAnnotation(key); a.finish(); }
void setAnnotation(RawAnnotationSet<Object> a, int start, int end, String key, Object value) throws OperationException { a.begin(); if (start > 0) { a.skip(start); } a.startAnnotation(key, value); if (end - start > 0) { a.skip(end - start); } a.endAnnotation(key); a.finish(); }
public void testIntervalIterator2() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.insert(1); m.finish(); IntervalCallback c = mock(IntervalCallback.class); for (AnnotationInterval<Object> i : m.annotationIntervals(0, m.size(), null)) { c.apply(i.start(), i.end(), CollectionUtils.newJavaMap(i.annotations()), CollectionUtils.newJavaMap(i.diffFromLeft())); } verify(c).apply(0, 1, Collections.<String, Object>singletonMap("a", "1"), Collections.<String, Object>singletonMap("a", "1")); verify(c).apply(1, 2, Collections.<String, Object>singletonMap("a", null), Collections.<String, Object>singletonMap("a", null)); } //
@SuppressWarnings("unchecked") public void testListenerForInsertion() throws OperationException { final AnnotationSetListener<Object> listener = mock(AnnotationSetListener.class); RawAnnotationSet<Object> m = getNewSet(listener); m.begin(); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); verify(listener).onAnnotationChange(0, 1, "a", "1"); m.begin(); m.skip(1); m.insert(1); m.finish(); }
@SuppressWarnings("unchecked") public void testListenerForInsertion() throws OperationException { final AnnotationSetListener<Object> listener = mock(AnnotationSetListener.class); RawAnnotationSet<Object> m = getNewSet(listener); m.begin(); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); verify(listener).onAnnotationChange(0, 1, "a", "1"); m.begin(); m.skip(1); m.insert(1); m.finish(); }
public void testIntervalIterator() { // IndexedDocumentImplTest contains some more tests that also exercise the // iterator methods of AnnotationTree. RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); IntervalCallback c = mock(IntervalCallback.class); for (AnnotationInterval<Object> i : m.annotationIntervals(0, m.size(), null)) { c.apply(i.start(), i.end(), CollectionUtils.newJavaMap(i.annotations()), CollectionUtils.newJavaMap(i.diffFromLeft())); } verify(c).apply(0, 1, Collections.<String, Object>singletonMap("a", "1"), Collections.<String, Object>singletonMap("a", "1")); }
public void testIntervalIterator() { // IndexedDocumentImplTest contains some more tests that also exercise the // iterator methods of AnnotationTree. RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); IntervalCallback c = mock(IntervalCallback.class); for (AnnotationInterval<Object> i : m.annotationIntervals(0, m.size(), null)) { c.apply(i.start(), i.end(), CollectionUtils.newJavaMap(i.annotations()), CollectionUtils.newJavaMap(i.diffFromLeft())); } verify(c).apply(0, 1, Collections.<String, Object>singletonMap("a", "1"), Collections.<String, Object>singletonMap("a", "1")); }
public void testEmptySet() { RawAnnotationSet<Object> m = getNewSet(); m.begin(); m.insert(1); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); expectFinished(m.annotationCursor(0, m.size(), strs())); } }
public void testEmptySet() { RawAnnotationSet<Object> m = getNewSet(); m.begin(); m.insert(1); m.startAnnotation("a", "1"); m.insert(1); m.endAnnotation("a"); m.finish(); expectFinished(m.annotationCursor(0, m.size(), strs())); } }
public void testCreateWithSpanningAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.finish(); assertEquals(0, m.firstAnnotationChange(0, 10, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 10, "a", null)); assertEquals(-1, m.firstAnnotationChange(0, 10, "a", "1")); assertEquals(-1, m.lastAnnotationChange(0, 10, "a", "1")); }
public void testCreateWithSpanningAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.finish(); assertEquals(0, m.firstAnnotationChange(0, 10, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 10, "a", null)); assertEquals(-1, m.firstAnnotationChange(0, 10, "a", "1")); assertEquals(-1, m.lastAnnotationChange(0, 10, "a", "1")); }
public void testCreateWithFinalAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.insert(5); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.finish(); assertEquals(5, m.firstAnnotationChange(5, 15, "a", null)); assertEquals(15, m.lastAnnotationChange(5, 15, "a", null)); assertEquals(5, m.firstAnnotationChange(0, 15, "a", null)); assertEquals(15, m.lastAnnotationChange(0, 15, "a", null)); assertEquals(-1, m.firstAnnotationChange(5, 15, "a", "1")); assertEquals(-1, m.lastAnnotationChange(5, 15, "a", "1")); }
public void testCreateWithInitialAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.insert(5); m.finish(); assertEquals(0, m.firstAnnotationChange(0, 10, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 10, "a", null)); assertEquals(0, m.firstAnnotationChange(0, 15, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 15, "a", null)); assertEquals(-1, m.firstAnnotationChange(0, 10, "a", "1")); assertEquals(-1, m.lastAnnotationChange(0, 10, "a", "1")); }
public void testCreateWithFinalAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.insert(5); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.finish(); assertEquals(5, m.firstAnnotationChange(5, 15, "a", null)); assertEquals(15, m.lastAnnotationChange(5, 15, "a", null)); assertEquals(5, m.firstAnnotationChange(0, 15, "a", null)); assertEquals(15, m.lastAnnotationChange(0, 15, "a", null)); assertEquals(-1, m.firstAnnotationChange(5, 15, "a", "1")); assertEquals(-1, m.lastAnnotationChange(5, 15, "a", "1")); }
public void testCreateWithInitialAnnotation() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.startAnnotation("a", "1"); m.insert(10); m.endAnnotation("a"); m.insert(5); m.finish(); assertEquals(0, m.firstAnnotationChange(0, 10, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 10, "a", null)); assertEquals(0, m.firstAnnotationChange(0, 15, "a", null)); assertEquals(10, m.lastAnnotationChange(0, 15, "a", null)); assertEquals(-1, m.firstAnnotationChange(0, 10, "a", "1")); assertEquals(-1, m.lastAnnotationChange(0, 10, "a", "1")); }
public void testInitialStartLocation() { RawAnnotationSet<Object> m = getNewSet(); m.begin(); m.insert(100); m.finish(); // -1 if no hasNext() AnnotationCursor c = m.annotationCursor(40, 80, strs("a")); assertEquals(-1, c.currentLocation()); m.begin(); m.skip(50); m.startAnnotation("a", "1"); m.skip(10); m.endAnnotation("a"); m.finish(); // start value, if hasNext(); c = m.annotationCursor(40, 80, strs("a")); assertEquals(40, c.currentLocation()); }