List of usage examples for org.apache.commons.lang3 Range equals
@Override public boolean equals(final Object obj)
Compares this range to another object to test if they are equal.
.From source file:de.julielab.jcore.utility.JCoReAnnotationTools.java
@SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotationAtMatchingOffsets(JCas aJCas, Annotation focusAnnotation, Class<T> cls) {//from ww w .j av a 2 s . c om FSIterator<Annotation> cursor = aJCas.getAnnotationIndex().iterator(); cursor.moveTo(focusAnnotation); if (!cursor.isValid()) throw new IllegalArgumentException( "Given FocusAnnotation was not found in the JCas' annotation index: " + focusAnnotation); while (cursor.isValid() && cursor.get().getBegin() >= focusAnnotation.getBegin()) { cursor.moveToPrevious(); } if (!cursor.isValid()) cursor.moveToFirst(); else cursor.moveToNext(); // Now that we have our starting point, we go to the right until we find an annotation of the correct type and // the same offsets as focusAnnotation Annotation currentAnnotation = null; while (cursor.isValid() && (currentAnnotation = cursor.get()).getBegin() <= focusAnnotation.getEnd()) { if (!cls.isInstance(currentAnnotation)) { cursor.moveToNext(); continue; } Range<Integer> currentRange = Range.between(currentAnnotation.getBegin(), currentAnnotation.getEnd()); Range<Integer> focusRange = Range.between(focusAnnotation.getBegin(), focusAnnotation.getEnd()); if (cursor.isValid() && cls.isInstance(currentAnnotation) && focusRange.equals(currentRange)) return (T) currentAnnotation; cursor.moveToNext(); } return null; }