public AnnotationIntervalImpl(AnnotationInterval<V> other) { this(other.start(), other.end(), CollectionUtils.copyStringMap(other.annotations()), CollectionUtils.copyStringMap(other.diffFromLeft())); }
protected Map<ParticipantId, Set<Range<Integer>>> getAndPrintAnnotations(PluggableMutableDocument document, SimpleAnnotationSet annotationSet) { Map<ParticipantId, Set<Range<Integer>>> rangesPerParticipant = new HashMap<ParticipantId, Set<Range<Integer>>>(); Iterable<AnnotationInterval<Object>> intervals = annotationSet.annotationIntervals(0, document.size(), CollectionUtils.newStringSet(WaveletContributions.ANNOTATION_KEY)); intervals.forEach(interval -> { System.out.println("Interval ("+interval.start()+","+interval.end()+") "); final Range<Integer> r = Range.closed(interval.start(), interval.end()); interval.annotations().each(new ProcV<Object>() { @Override public void apply(String key, Object value) { if (value != null) { ParticipantId p = (ParticipantId) value; if (!rangesPerParticipant.containsKey(p)) { rangesPerParticipant.put(p, new HashSet<Range<Integer>>()); } Set<Range<Integer>> rangeSet = rangesPerParticipant.get(p); rangeSet.add(r); System.out.println("\t "+key+"="+value.toString()); } } }); }); return rangesPerParticipant; }
i.diffFromLeft().each(new ProcV<Object>() { @Override public void apply(String key, Object value) { b.retain(i.length()); last = i; last.annotations().each(new ProcV<Object>() { @Override public void apply(String key, Object value) {
for (AnnotationInterval<String> interval : // update along the way doc.annotationIntervals(removeStart, removeEnd, null)) { interval.diffFromLeft().each(new ProcV<Object>() { @Override public void apply(String key, Object value) { assert value == null || value instanceof String; annotOp.retain(interval.length()); last = interval;
protected static <V> void expectIntervals(Iterable<AnnotationInterval<V>> iterable, List<AnnotationInterval<V>> expectedIntervals) { List<AnnotationInterval<V>> actualIntervals = new ArrayList<AnnotationInterval<V>>(); for (AnnotationInterval<V> i : iterable) { actualIntervals.add(new AnnotationIntervalImpl<V>(i)); } assertEquals("Number of intervals", expectedIntervals.size(), actualIntervals.size()); for (int i = 0; i < expectedIntervals.size(); i++) { AnnotationInterval<V> expected = expectedIntervals.get(i); AnnotationInterval<V> actual = actualIntervals.get(i); assertEquals("Start of interval " + i, expected.start(), actual.start()); assertEquals("End of interval " + i, expected.end(), actual.end()); assertMapsEqual(expected.annotations(), actual.annotations()); assertMapsEqual(expected.diffFromLeft(), actual.diffFromLeft()); } }
protected static <V> void expectIntervals(Iterable<AnnotationInterval<V>> iterable, List<AnnotationInterval<V>> expectedIntervals) { List<AnnotationInterval<V>> actualIntervals = new ArrayList<AnnotationInterval<V>>(); for (AnnotationInterval<V> i : iterable) { actualIntervals.add(new AnnotationIntervalImpl<V>(i)); } assertEquals("Number of intervals", expectedIntervals.size(), actualIntervals.size()); for (int i = 0; i < expectedIntervals.size(); i++) { AnnotationInterval<V> expected = expectedIntervals.get(i); AnnotationInterval<V> actual = actualIntervals.get(i); assertEquals("Start of interval " + i, expected.start(), actual.start()); assertEquals("End of interval " + i, expected.end(), actual.end()); assertMapsEqual(expected.annotations(), actual.annotations()); assertMapsEqual(expected.diffFromLeft(), actual.diffFromLeft()); } }
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 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)); } //
assertEquals(2, i.start()); assertEquals(5, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("1", i.annotations().get("a", "x")); assertEquals(0, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("x", i.diffFromLeft().get("a", "x")); assertEquals(5, i.start()); assertEquals(6, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("2", i.annotations().get("a", "x")); assertEquals(1, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("2", i.diffFromLeft().get("a", "x")); assertEquals(6, i.start()); assertEquals(10, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals(null, i.annotations().get("a", "x")); assertEquals(1, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals(null, i.diffFromLeft().get("a", "x")); assertEquals(2, i.start()); assertEquals(3, i.end()); assertEquals(3, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("1", i.annotations().get("a", "x")); assertEquals(null, i.annotations().get("b", "x")); assertEquals("1", i.annotations().get("c", "x")); assertEquals(0, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("x", i.diffFromLeft().get("a", "x"));
assertEquals(2, i.start()); assertEquals(5, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("1", i.annotations().get("a", "x")); assertEquals(0, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("x", i.diffFromLeft().get("a", "x")); assertEquals(5, i.start()); assertEquals(6, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("2", i.annotations().get("a", "x")); assertEquals(1, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("2", i.diffFromLeft().get("a", "x")); assertEquals(6, i.start()); assertEquals(10, i.end()); assertEquals(1, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals(null, i.annotations().get("a", "x")); assertEquals(1, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals(null, i.diffFromLeft().get("a", "x")); assertEquals(2, i.start()); assertEquals(3, i.end()); assertEquals(3, CollectionUtils.newJavaMap(i.annotations()).size()); assertEquals("1", i.annotations().get("a", "x")); assertEquals(null, i.annotations().get("b", "x")); assertEquals("1", i.annotations().get("c", "x")); assertEquals(0, CollectionUtils.newJavaMap(i.diffFromLeft()).size()); assertEquals("x", i.diffFromLeft().get("a", "x"));