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())); } }
@Override public Iterable<AnnotationInterval<Object>> annotationIntervals(int start, int end, ReadableStringSet keys) { return fullAnnotationSet.annotationIntervals(start, end, keys); }
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")); }
@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(); } }
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 testTwoInserts() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.insert(1); m.insert(1); m.finish(); assertEquals(-1, m.firstAnnotationChange(0, 2, "hi", null)); }
public void testQueryExceptions() { RawAnnotationSet<Object> m = getNew(); m.begin(); m.insert(1); m.finish(); m.getAnnotation(0, "a"); m.getAnnotation(-1, "a"); fail(); } catch (IndexOutOfBoundsException e) { m.getAnnotation(1, "a"); fail(); } catch (IndexOutOfBoundsException e) { m.getAnnotation(0, null); fail(); } catch (NullPointerException e) { m.firstAnnotationChange(0, 1, "a", null); m.firstAnnotationChange(-1, 1, "a", null); fail(); } catch (IndexOutOfBoundsException e) { m.firstAnnotationChange(0, 2, "a", null); fail(); } catch (IndexOutOfBoundsException e) {
public void testBug1961653() { RawAnnotationSet<Object> a = getNewSet(); a.begin(); a.insert(10); a.startAnnotation("a", "1"); a.insert(5); a.endAnnotation("a"); a.insert(21); a.finish(); assertEquals(36, a.size()); expectRanges(a.rangedAnnotations(0, a.size(), strs("a")), ranges( range("a", null, 0, 10), range("a", "1", 10, 15), range("a", null, 15, 36) )); expectRanges(a.rangedAnnotations(10, 26, strs("a")), ranges( range("a", "1", 10, 15), range("a", null, 15, 36) )); expectRanges(a.rangedAnnotations(9, 14, strs("a")), ranges( range("a", null, 0, 10), range("a", "1", 10, 15) )); expectRanges(a.rangedAnnotations(9, 15, strs("a")), ranges( range("a", null, 0, 10), range("a", "1", 10, 15) )); expectRanges(a.rangedAnnotations(9, 16, strs("a")), ranges(
/** * @param substrate raw dom document to use * @param rawAnnotations raw annotations to use */ public IndexedDocumentImpl(RawDocument<N, E, T> substrate, RawAnnotationSet<Object> rawAnnotations, DocumentSchema constraints) { Preconditions.checkNotNull(constraints, "Null schema not allowed, use DocumentSchema.NO_SCHEMA_CONSTRAINTS"); this.schemaConstraints = constraints; annotations = rawAnnotations != null ? rawAnnotations : new StubModifiableAnnotations<Object>(); this.substrate = substrate; offsetList = new EvaluableOffsetList<N, V>(null); assert size() == 0; indexChildren(substrate.getDocumentElement()); resetLocation(); if (offsetList.size() > 0) { annotations.begin(); annotations.insert(offsetList.size()); annotations.finish(); } assert substrate.getFirstChild(substrate.getDocumentElement()) != null || size() == 0; }
private void doElementEnd() { onElementEnd(); annotations.insert(1); ++currentLocation; currentContainer = currentContainer.getNextContainer(); currentParent = substrate.getParentElement(currentParent); }
private void beginChange() { beforeBegin(); inconsistent = true; resetLocation(); annotations.begin(); }
/** * {@inheritDoc} */ public AnnotationCursor annotationCursor(int start, int end, ReadableStringSet keys) { if (keys == null) { keys = knownKeys(); } else { checkValidPersistentKeys(keys); } return annotations.annotationCursor(start, end, keys); }
@Override public Iterable<RangedAnnotation<Object>> rangedAnnotations(int start, int end, ReadableStringSet keys) { return fullAnnotationSet.rangedAnnotations(start, end, keys); }
@Override public int lastAnnotationChange(int start, int end, String key, Object fromValue) { return fullAnnotationSet.lastAnnotationChange(start, end, key, fromValue); }
@Override public int firstAnnotationChange(int start, int end, String key, Object fromValue) { return fullAnnotationSet.firstAnnotationChange(start, end, key, fromValue); }
@Override public Object getAnnotation(int start, String key) { return fullAnnotationSet.getAnnotation(start, key); }
private void doEndAnnotation(String key) { if (Annotations.isLocal(key)) { throw new IllegalArgumentException("Cannot access local annotations"); } annotations.endAnnotation(key); }