@Override public int hashCode() { int result = getFrom(); result = 31 * result + getTo(); return result; }
private void calculateFrom() { int smallestFrom = Integer.MAX_VALUE; for (SpanNode n : children()) { final int thisFrom = n.getFrom(); if (thisFrom != -1) { smallestFrom = Math.min(thisFrom, smallestFrom); } } if (smallestFrom == Integer.MAX_VALUE) { //all children were empty SpanLists which returned -1 smallestFrom = -1; } cachedFrom = smallestFrom; }
/** * Checks if the text covered by another span is within the text covered by this span. * * @param o the other SpanNode to check. * @return true if the text covered by another span is within the text covered by this span, false otherwise. */ public boolean contains(SpanNode o) { int from = getFrom(); int otherFrom = o.getFrom(); int to = getTo(); int otherTo = o.getTo(); if (otherFrom >= from && otherTo <= to) { //other span node is within our range: return true; } return false; }
/** * Checks if the text covered by this span overlaps with the text covered by another span. * * @param o the other SpanNode to check * @return true if spans are overlapping, false otherwise */ public boolean overlaps(SpanNode o) { int from = getFrom(); int otherFrom = o.getFrom(); int to = getTo(); int otherTo = o.getTo(); //is other from within our range, or vice versa? if ((otherFrom >= from && otherFrom < to) || (from >= otherFrom && from < otherTo)) { return true; } //is other to within our range, or vice versa? if ((otherTo > from && otherTo <= to) || (to > otherFrom && to <= otherTo)) { return true; } return false; }
str = ((StringFieldValue)val).getString(); } else { str = input.getString().substring(span.getFrom(), span.getTo());