diff --git a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/domain/IntRange.java b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/domain/IntRange.java index 9d0e8937..c4b5101c 100644 --- a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/domain/IntRange.java +++ b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/domain/IntRange.java @@ -16,8 +16,6 @@ */ package nl.overheid.aerius.shared.domain; -import java.util.function.Function; - /** * Object to use to check if a given value is within a range. * The range object can be created using a string representation of the range. like [1,10). @@ -31,12 +29,14 @@ public boolean inRange(final int value) { @Override public String toString() { - final Function same = b -> b ? "=" : ""; - final boolean withLow = low != Integer.MIN_VALUE; - final boolean withHigh = high != Integer.MAX_VALUE; - - return (withLow ? ('>' + same.apply(lowInclusive) + low) : "") - + (withLow && withHigh ? " - " : "") - + (withHigh ? ('<' + same.apply(highInclusive) + high) : ""); + if (low == Integer.MIN_VALUE) { + return (highInclusive ? "≤ " : "< ") + high; + } else if (high == Integer.MAX_VALUE) { + return (lowInclusive ? "≥ " : "> ") + low; + } else { + final String lowBracket = lowInclusive ? "[" : "("; + final String highBracket = highInclusive ? "]" : ")"; + return lowBracket + low + "-" + high + highBracket; + } } } diff --git a/source/imaer-util/src/test/java/nl/overheid/aerius/util/IntRangeTest.java b/source/imaer-util/src/test/java/nl/overheid/aerius/util/IntRangeTest.java index cdf0c4ce..df29d6dd 100644 --- a/source/imaer-util/src/test/java/nl/overheid/aerius/util/IntRangeTest.java +++ b/source/imaer-util/src/test/java/nl/overheid/aerius/util/IntRangeTest.java @@ -87,13 +87,13 @@ void testToString(final String range, final String expectedString) { static List toStringData() { return List.of( - Arguments.of("[,20)", "<20"), - Arguments.of("[,20]", "<=20"), - Arguments.of("[10,20]", ">=10 - <=20"), - Arguments.of("(10,20]", ">10 - <=20"), - Arguments.of("(10,20)", ">10 - <20"), - Arguments.of("[10,20)", ">=10 - <20"), - Arguments.of("[10,)", ">=10"), - Arguments.of("(10,)", ">10")); + Arguments.of("[,20)", "< 20"), + Arguments.of("[,20]", "≤ 20"), + Arguments.of("[10,20]", "[10-20]"), + Arguments.of("(10,20]", "(10-20]"), + Arguments.of("(10,20)", "(10-20)"), + Arguments.of("[10,20)", "[10-20)"), + Arguments.of("[10,)", "≥ 10"), + Arguments.of("(10,)", "> 10")); } }