Example usage for org.apache.commons.lang3 Range equals

List of usage examples for org.apache.commons.lang3 Range equals

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Range equals.

Prototype

@Override
public boolean equals(final Object obj) 

Source Link

Document

Compares this range to another object to test if they are equal.

.

Usage

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;
}