@Override public int size() { return fullAnnotationSet.size(); }
private void checkSizeConsistency(String msgPrefix) { // TODO(danilatos/ohler): Make this an assert once we are more confident if (annotations != null && offsetList != null && offsetList.size() != annotations.size()) { throw new RuntimeException(msgPrefix + ": Document and annotations have inconsistent size: " + offsetList.size() + " vs " + annotations.size() + ", respectively"); } }
void applyRandomDelete(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, Random random) throws OperationException { int pos = random.nextInt(b.size()); int length = random.nextInt(Math.min(DELETE_LENGTH_LIMIT, b.size() - pos)); if (a != null) { delete(a, pos, length); } delete(b, pos, length); }
void applyRandomDelete(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, Random random) throws OperationException { int pos = random.nextInt(b.size()); int length = random.nextInt(Math.min(DELETE_LENGTH_LIMIT, b.size() - pos)); if (a != null) { delete(a, pos, length); } delete(b, pos, length); }
void applyRandomSet(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, String[] keys, String[] values, Random random) throws OperationException { int start = random.nextInt(b.size()); int end = 1 + random.nextInt(b.size()); if (start > end) { int swap = start; start = end; end = swap; } String key = keys[random.nextInt(keys.length)]; Object value = values[random.nextInt(values.length)]; if (a != null) { setAnnotation(a, start, end, key, value); } setAnnotation(b, start, end, key, value); }
void applyRandomSet(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, String[] keys, String[] values, Random random) throws OperationException { int start = random.nextInt(b.size()); int end = 1 + random.nextInt(b.size()); if (start > end) { int swap = start; start = end; end = swap; } String key = keys[random.nextInt(keys.length)]; Object value = values[random.nextInt(values.length)]; if (a != null) { setAnnotation(a, start, end, key, value); } setAnnotation(b, start, end, key, value); }
void applyRandomInsert(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, Random random) throws OperationException { int pos = random.nextInt(b.size() + 1); int length = random.nextInt(INSERT_LENGTH_LIMIT); if (a != null) { insert(a, pos, length); } insert(b, pos, length); }
void applyRandomInsert(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, Random random) throws OperationException { int pos = random.nextInt(b.size() + 1); int length = random.nextInt(INSERT_LENGTH_LIMIT); if (a != null) { insert(a, pos, length); } insert(b, pos, length); }
void testPerformance1(Random random) { RawAnnotationSet<Object> a = new SimpleAnnotationSet(null); RawAnnotationSet<Object> b = new AnnotationTree<Object>(new Object(), new Object(), null); String[] keys = new String[NUM_KEYS]; for (int i = 0; i < keys.length; i++) { keys[i] = "k" + i; } String[] values = new String[NUM_KEYS]; for (int i = 0; i < values.length; i++) { values[i] = "v" + i; } int maxLength = 0; RawAnnotationSet<Object> c = b; for (int i = 0; i < NUM_UPDATES; i++) { applyRandomOperation(null, c, keys, values, random); maxLength = Math.max(maxLength, c.size()); for (int j = 0; j < QUERIES_PER_UPDATE; j++) { performRandomQuery(c, keys, random); } } System.err.println("final length=" + c.size() + ", max length=" + maxLength); }
void testPerformance1(Random random) { RawAnnotationSet<Object> a = new SimpleAnnotationSet(null); RawAnnotationSet<Object> b = new AnnotationTree<Object>(new Object(), new Object(), null); String[] keys = new String[NUM_KEYS]; for (int i = 0; i < keys.length; i++) { keys[i] = "k" + i; } String[] values = new String[NUM_KEYS]; for (int i = 0; i < values.length; i++) { values[i] = "v" + i; } int maxLength = 0; RawAnnotationSet<Object> c = b; for (int i = 0; i < NUM_UPDATES; i++) { applyRandomOperation(null, c, keys, values, random); maxLength = Math.max(maxLength, c.size()); for (int j = 0; j < QUERIES_PER_UPDATE; j++) { performRandomQuery(c, keys, random); } } System.err.println("final length=" + c.size() + ", max length=" + maxLength); }
void applyRandomOperation(RawAnnotationSet<Object> a, RawAnnotationSet<Object> b, String[] keys, String[] values, Random random) { if (a != null) { assert a.size() == b.size(); if (b.size() == 0) { applyRandomInsert(a, b, random); } else if (b.size() >= MAX_LENGTH) { switch (random.nextInt(2)) { case 0:
@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 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)); } //
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)); } //
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")); }
@Override public void resetAnnotation(int start, int end, String key, Object value) { Preconditions.checkPositionIndexes(start, end, fullAnnotationSet.size()); checkLocalKey(key); if (end - start > 0) { fullAnnotationSet.begin(); fullAnnotationSet.startAnnotation(key, null); if (start > 0) { fullAnnotationSet.skip(start); } fullAnnotationSet.startAnnotation(key, value); fullAnnotationSet.skip(end - start); fullAnnotationSet.startAnnotation(key, null); if (size() - end > 0) { fullAnnotationSet.skip(size() - end); } fullAnnotationSet.endAnnotation(key); fullAnnotationSet.finish(); } } @Override
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())); } }