RollingTextBlock extends RawTextProcessor { public AnnotatedText getRawTextBlock() { AnnotatedText rawTextBlock = new AnnotatedText(this.block3 + this.block4, 0, this.block3.length()); rawTextBlock.addObserver(new AnnotationObserver() { @Override public <T extends Serializable> void beforeAddAnnotations(AnnotatedText subject, List<Annotation<T>> annotations) { if (annotations.size() > 0) { int offset = RollingTextBlock.this.block1.length() + RollingTextBlock.this.block2.length(); List<Annotation<T>> newAnnotations = new ArrayList<>(); for (Annotation<T> annotation : annotations) { Annotation<T> newAnnotation = annotation.getAnnotation(annotation.getStart() + offset, annotation.getEnd() + offset); newAnnotations.add(newAnnotation); } RollingTextBlock.this.addAnnotations(newAnnotations); if (LOG.isTraceEnabled()) { LOG.trace("RawTextBlock Annotations received: " + annotations); LOG.trace("RawTextBlock Annotations added: " + newAnnotations); } } } @Override public <T extends Serializable> void afterAddAnnotations(AnnotatedText subject) { } }); return rawTextBlock; } RollingTextBlock(boolean processByDefault, CurrentFileProvider currentFileProvider, String sessionId); private  RollingTextBlock(RollingTextBlock predecessor, String nextText, List<Annotation<?>> annotations); RollingTextBlock roll(String nextText); AnnotatedText getRawTextBlock(); @Override void onNextFile(File file);  }
@Test public void testGetRawTextBlock() throws Exception { System.setProperty("config.file", "src/test/resources/test.conf"); ConfigFactory.invalidateCaches(); final Config config = ConfigFactory.load(); final String sessionId = "test"; String[] labels = new String[0]; RollingTextBlock textBlock = new RollingTextBlock(true, null, sessionId); textBlock = textBlock.roll("1 "); textBlock = textBlock.roll("2 "); textBlock = textBlock.roll("3<skip>skip</skip> 4<sk"); textBlock = textBlock.roll("ip>skip</skip> 5"); AnnotatedText rawTextBlock = textBlock.getRawTextBlock(); List<Annotation<RawTextSkipMarker>> skips = new ArrayList<>(); skips.add(new Annotation<>("3".length(), "3<skip>skip</skip>".length(), new RawTextSkipMarker("me"), labels)); skips.add(new Annotation<>("3<skip>skip</skip> 4".length(), "3<skip>skip</skip> 4<skip>skip</skip>".length(), new RawTextSkipMarker("me"), labels)); rawTextBlock.addAnnotations(skips); List<Annotation<RawTextSkipMarker>> sourceSkips = textBlock.getAnnotations(RawTextSkipMarker.class); System.out.println(sourceSkips.toString()); assertEquals(2, sourceSkips.size()); int i = 0; for (Annotation<RawTextSkipMarker> skip : sourceSkips) { if (i == 0) { assertEquals("1 2 3".length(), skip.getStart()); assertEquals("1 2 3<skip>skip</skip>".length(), skip.getEnd()); } else if (i == 1) { assertEquals("1 2 3<skip>skip</skip> 4".length(), skip.getStart()); assertEquals("1 2 3<skip>skip</skip> 4<skip>skip</skip>".length(), skip.getEnd()); } i++; } }