diff --git a/src/main/java/de/th_luebeck/ws25/Interval.java b/src/main/java/de/th_luebeck/ws25/Interval.java new file mode 100644 index 0000000..bfcb27f --- /dev/null +++ b/src/main/java/de/th_luebeck/ws25/Interval.java @@ -0,0 +1,18 @@ +package de.th_luebeck.ws25; + +public record Interval(int start, int end) { + + public int length() { + return end - start + 1; + } + + public boolean overlaps(Interval other) { + return this.start <= other.end && other.start <= this.end; + } + + public int overlapSize(Interval other) { + int a = Math.max(this.start, other.start); + int b = Math.min(this.end, other.end); + return Math.max(0, b - a + 1); + } +}