#743: Range.java

projectforge-business/src/main/java/org/projectforge/framework/utils/Range.java Lines: 102 · Author: Kai Reinhard · Type: Java generic Comparable<T>-based interval 102 lines · 43 code · 47 comments · 12 blank

Purpose

A generic closed interval [minValue, maxValue] with a doesMatch(value) containment check. 102 lines. Works with any type that implements Comparable — integers, dates, strings, BigDecimals, etc. The constructor auto-sorts the two boundary values — new Range(5, 1) produces minValue=1, maxValue=5 regardless of argument order. The doesMatch(value) method checks minValue <= value <= maxValue using compareTo().

This is part of the range matching framework: Range<T> (single interval) → Ranges<T> (union of intervals) → IntRanges (#735, integer specialization). Used for timesheet week filtering, date range matching, and numeric value validation.

Fluent API

Setters setMinValue() and setMaxValue() return this for chaining: new Range<>(1, 10).setMinValue(2).setMaxValue(9). Note: changing min/max after construction does not re-sort — if you set min=100 and max=1, doesMatch() will always return false (no value can be simultaneously >= 100 and <= 1). The auto-sort only happens in the constructor.