@Test public void several_matches() { Collection<MessageAnnotation> annotations = new RegexMessageAnnotator(REGEX, annotationFunction).annotate("#177 #178 matches."); assertNotNull(annotations); assertEquals( Arrays.asList( annotationFunction.apply("#177"), MessageAnnotation.t(" "), annotationFunction.apply("#178"), MessageAnnotation.t(" matches.") ), annotations); }
@Override public Collection<MessageAnnotation> annotate(String text) { Collection<MessageAnnotation> annotations = new ArrayList<>(); int start = 0; Matcher m = pattern.matcher(text); while (m.find()) { int mStart = m.start(); int mEnd = m.end(); if (mStart > start) { String previous = text.substring(start, mStart); annotations.add(MessageAnnotation.t(previous)); } String match = m.group(); MessageAnnotation annotation = annotationFactory.apply(match); annotations.add(annotation); start = mEnd; } if (start < text.length() - 1) { String reminder = text.substring(start); annotations.add(MessageAnnotation.t(reminder)); } return annotations; }
RegexMessageAnnotator extends AbstractMessageAnnotator { @Override public Collection<MessageAnnotation> annotate(String text) { Collection<MessageAnnotation> annotations = new ArrayList<>(); int start = 0; Matcher m = pattern.matcher(text); while (m.find()) { int mStart = m.start(); int mEnd = m.end(); if (mStart > start) { String previous = text.substring(start, mStart); annotations.add(MessageAnnotation.t(previous)); } String match = m.group(); MessageAnnotation annotation = annotationFactory.apply(match); annotations.add(annotation); start = mEnd; } if (start < text.length() - 1) { String reminder = text.substring(start); annotations.add(MessageAnnotation.t(reminder)); } return annotations; } }
RegexMessageAnnotator extends AbstractMessageAnnotator { @Override public Collection<MessageAnnotation> annotate(String text) { Collection<MessageAnnotation> annotations = new ArrayList<>(); int start = 0; Matcher m = pattern.matcher(text); while (m.find()) { int mStart = m.start(); int mEnd = m.end(); if (mStart > start) { String previous = text.substring(start, mStart); annotations.add(MessageAnnotation.t(previous)); } String match = m.group(); MessageAnnotation annotation = annotationFactory.apply(match); annotations.add(annotation); start = mEnd; } if (start < text.length() - 1) { String reminder = text.substring(start); annotations.add(MessageAnnotation.t(reminder)); } return annotations; } RegexMessageAnnotator(String pattern, Function<String, MessageAnnotation> annotationFactory);  RegexMessageAnnotator(Pattern pattern, Function<String, MessageAnnotation> annotationFactory); }
RegexMessageAnnotator extends AbstractMessageAnnotator { @Override public Collection<MessageAnnotation> annotate(String text) { Collection<MessageAnnotation> annotations = new ArrayList<>(); int start = 0; Matcher m = pattern.matcher(text); while (m.find()) { int mStart = m.start(); int mEnd = m.end(); if (mStart > start) { String previous = text.substring(start, mStart); annotations.add(MessageAnnotation.t(previous)); } String match = m.group(); MessageAnnotation annotation = annotationFactory.apply(match); annotations.add(annotation); start = mEnd; } if (start < text.length() - 1) { String reminder = text.substring(start); annotations.add(MessageAnnotation.t(reminder)); } return annotations; } RegexMessageAnnotator(String pattern, Function<String, MessageAnnotation> annotationFactory);  RegexMessageAnnotator(Pattern pattern, Function<String, MessageAnnotation> annotationFactory); @Override Collection<MessageAnnotation> annotate(String text); }
RegexMessageAnnotator extends AbstractMessageAnnotator { @Override public Collection<MessageAnnotation> annotate(String text) { Collection<MessageAnnotation> annotations = new ArrayList<>(); int start = 0; Matcher m = pattern.matcher(text); while (m.find()) { int mStart = m.start(); int mEnd = m.end(); if (mStart > start) { String previous = text.substring(start, mStart); annotations.add(MessageAnnotation.t(previous)); } String match = m.group(); MessageAnnotation annotation = annotationFactory.apply(match); annotations.add(annotation); start = mEnd; } if (start < text.length() - 1) { String reminder = text.substring(start); annotations.add(MessageAnnotation.t(reminder)); } return annotations; } RegexMessageAnnotator(String pattern, Function<String, MessageAnnotation> annotationFactory);  RegexMessageAnnotator(Pattern pattern, Function<String, MessageAnnotation> annotationFactory); @Override Collection<MessageAnnotation> annotate(String text);  }