/** Compares the specified span to the current span. */ public int compareTo(Span s) { if (getStart() < s.getStart()) { return -1; } else if (getStart() == s.getStart()) { if (getEnd() > s.getEnd()) { return -1; } else if (getEnd() < s.getEnd()) { return 1; } else { return 0; } } else { return 1; } }
/** * Returns true is the specified span crosses this span. * * @param s The span to compare with this span. * @return true is the specified span overlaps this span and contains a non-overlapping section; * false otherwise. */ public boolean crosses(Span s) { int sstart = s.getStart(); // either s's start is in this or this' start is in s return !this.contains(s) && !s.contains(this) && (getStart() <= sstart && sstart < getEnd() || sstart <= getStart() && getStart() < s.getEnd()); }
/** * Returns true if the specified span intersects with this span. * * @param s The span to compare with this span. * @return true is the spans overlap; false otherwise. */ public boolean intersects(Span s) { int sstart = s.getStart(); // either s's start is in this or this' start is in s return this.contains(s) || s.contains(this) || getStart() <= sstart && sstart < getEnd() || sstart <= getStart() && getStart() < s.getEnd(); }
/** Checks if the specified span is equal to the current span. */ public boolean equals(Object o) { boolean result; if (o == this) { result = true; } else if (o instanceof Span) { Span s = (Span) o; result = (getStart() == s.getStart()) && (getEnd() == s.getEnd()) && (getType() != null ? type.equals(s.getType()) : true); } else { result = false; } return result; }
/** * Returns true if the specified span is the begin of this span and the specified span is * contained in this span. * * @param s The span to compare with this span. * @return true if the specified span starts with this span and is contained in this span; false * otherwise */ public boolean startsWith(Span s) { return getStart() == s.getStart() && contains(s); }
/** * Returns true if the specified span is contained by this span. Identical spans are considered to * contain each other. * * @param s The span to compare with this span. * @return true is the specified span is contained by this span; false otherwise. */ public boolean contains(Span s) { return start <= s.getStart() && s.getEnd() <= end; }