/** * Constructor. * * @param name the name of this annotation. * @param value the value of this annotation. * @param range the range of this annotation. */ public Annotation(String name, String value, Range range) { this.name = name; this.value = value; this.range = new Range(range.getStart(), range.getEnd()); }
public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }
public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }
/** * Copies the content of the source blip into the target blip. * * @param fromBlip the source blip. * @param toBlip the target blip. */ public static void copyBlipContents(Blip fromBlip, Blip toBlip) { for (BlipContent blipContent: fromBlip.all().values()) { toBlip.append(blipContent); } for (Annotation annotation : fromBlip.getAnnotations()) { Range range = annotation.getRange(); toBlip.range(range.getStart() + 1, range.getEnd() + 1).annotate(annotation.getName(), annotation.getValue()); } }
public void testTextIteratorDeletingMatches() { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "1", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(i + 1, range.getStart()); blip.setContent(blip.getContent().substring(0, range.getStart()) + blip.getContent().substring(range.getEnd())); iterator.shift(-1); } assertFalse(iterator.hasNext()); assertEquals("\n ", blip.getContent()); }
public void testTextIteratorDeletingMatches() { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "1", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(i + 1, range.getStart()); blip.setContent(blip.getContent().substring(0, range.getStart()) + blip.getContent().substring(range.getEnd())); iterator.shift(-1); } assertFalse(iterator.hasNext()); assertEquals("\n ", blip.getContent()); }
public void testTextIteratorShiftInsertAfter() { Blip blip = new Blip("blip1", "\nfoofoofoo", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "foo", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(i * 6 + 1, range.getStart()); blip.setContent(blip.getContent().substring(0, range.getEnd()) + "foo" + blip.getContent().substring(range.getEnd())); iterator.shift(range.getEnd() - range.getStart() + 2); } assertFalse(iterator.hasNext()); assertEquals("\nfoofoofoofoofoofoo", blip.getContent()); }
public void testTextIteratorShiftInsertAfter() { Blip blip = new Blip("blip1", "\nfoofoofoo", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "foo", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(i * 6 + 1, range.getStart()); blip.setContent(blip.getContent().substring(0, range.getEnd()) + "foo" + blip.getContent().substring(range.getEnd())); iterator.shift(range.getEnd() - range.getStart() + 2); } assertFalse(iterator.hasNext()); assertEquals("\nfoofoofoofoofoofoo", blip.getContent()); }
public void testTextMatcherDeletingTheFirstChar() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i + 1, r.getStart()); apiView.delete(1, 2); it.shift(1, -1); } assertNull(it.next()); }
public void testTextMatcherWithoutShift() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 2 + 1, r.getStart()); assertEquals(i * 2 + 2, r.getEnd()); } assertNull(it.next()); }
public void testTextMatcherWithoutShift() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 2 + 1, r.getStart()); assertEquals(i * 2 + 2, r.getEnd()); } assertNull(it.next()); }
public void testTextMatcherDeletingTheFirstChar() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i + 1, r.getStart()); apiView.delete(1, 2); it.shift(1, -1); } assertNull(it.next()); }
public void testSingleshotIterator() throws Exception { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); SingleshotIterator iterator = new BlipIterator.SingleshotIterator(blip, 0, 1); assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(0, range.getStart()); assertEquals(1, range.getEnd()); assertFalse(iterator.hasNext()); }
public void testSingleshotIterator() throws Exception { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); SingleshotIterator iterator = new BlipIterator.SingleshotIterator(blip, 0, 1); assertTrue(iterator.hasNext()); Range range = iterator.next(); assertEquals(0, range.getStart()); assertEquals(1, range.getEnd()); assertFalse(iterator.hasNext()); }
public void testTextIteratorWithoutShift() { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "1", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertNotNull(range); assertEquals(i * 2 + 1, range.getStart()); assertEquals(i * 2 + 2, range.getEnd()); } assertFalse(iterator.hasNext()); }
/** * Pretend we're shifting in the manner of INSERT_AFTER */ public void testTextMatcherShiftInsertAfter() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 3 + 1, r.getStart()); apiView.insert(r.getEnd(), "1"); it.shift(r.getEnd(), 1); } assertNull(it.next()); }
/** * Pretend we're shifting in the manner of INSERT_AFTER */ public void testTextMatcherShiftInsertAfter() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 3 + 1, r.getStart()); apiView.insert(r.getEnd(), "1"); it.shift(r.getEnd(), 1); } assertNull(it.next()); }
public void testTextIteratorWithoutShift() { Blip blip = new Blip("blip1", "\n1 1 1", null, null, wavelet); TextIterator iterator = new BlipIterator.TextIterator(blip, "1", -1); for (int i = 0; i < 3; ++i) { assertTrue(iterator.hasNext()); Range range = iterator.next(); assertNotNull(range); assertEquals(i * 2 + 1, range.getStart()); assertEquals(i * 2 + 2, range.getEnd()); } assertFalse(iterator.hasNext()); }