From 33c121fa750afa2dca60f9ef5b69d1fbdbbb0162 Mon Sep 17 00:00:00 2001 From: WOBBLEFANG THE THIRD Date: Fri, 5 Dec 2025 22:05:55 +0100 Subject: [PATCH] feat: add Interval record to represent start and end points with overlap functionality --- src/main/java/de/th_luebeck/ws25/Interval.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/de/th_luebeck/ws25/Interval.java 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); + } +}