feat: add Interval record to represent start and end points with overlap functionality

This commit is contained in:
2025-12-05 22:05:55 +01:00
parent 8865e87b9e
commit 33c121fa75

View File

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