Merge pull request #44 from DaveJarvis/patch-1

Added source code comments.
This commit is contained in:
Robert Bor 2016-11-28 07:58:29 +01:00 committed by GitHub
commit 8c422583b5

View File

@ -5,24 +5,51 @@ public class Interval implements Intervalable {
private int start; private int start;
private int end; private int end;
/**
* Constructs an interval with a start and end position.
*
* @param start The interval's starting text position.
* @param end The interval's ending text position.
*/
public Interval(final int start, final int end) { public Interval(final int start, final int end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
} }
/**
* Returns the starting offset into the text for this interval.
*
* @return A number between 0 (start of text) and the text length.
*/
public int getStart() { public int getStart() {
return this.start; return this.start;
} }
/**
* Returns the ending offset into the text for this interval.
*
* @return A number between getStart() + 1 and the text length.
*/
public int getEnd() { public int getEnd() {
return this.end; return this.end;
} }
/**
* Returns the length of the interval.
*
* @return The end position less the start position, plus one.
*/
public int size() { public int size() {
return end - start + 1; return end - start + 1;
} }
public boolean overlapsWith(Interval other) { /**
* Answers whether the given interval overlaps this interval
* instance.
*
* @return true The intervals overlap.
*/
public boolean overlapsWith(final Interval other) {
return this.start <= other.getEnd() && return this.start <= other.getEnd() &&
this.end >= other.getStart(); this.end >= other.getStart();
} }
@ -56,9 +83,14 @@ public class Interval implements Intervalable {
return comparison != 0 ? comparison : this.end - other.getEnd(); return comparison != 0 ? comparison : this.end - other.getEnd();
} }
/**
* Returns the starting offset and ending offset separated
* by a full colon (:).
*
* @return A non-null String, never empty.
*/
@Override @Override
public String toString() { public String toString() {
return this.start + ":" + this.end; return this.start + ":" + this.end;
} }
} }