#744: Ranges.java

projectforge-business/src/main/java/org/projectforge/framework/utils/Ranges.java Lines: 176 · Author: Kai Reinhard · Type: Java abstract generic — extended by IntRanges 176 lines · 107 code · 52 comments · 17 blank

Purpose

Union of multiple intervals with parsing from string. 176-line abstract class. Takes a string like "1-5,10,20-25", parses it into a list of Range<T> objects plus individual values, and provides doesMatch(value) to test membership. The companion to Range — while Range handles a single interval, Ranges handles multiple intervals and values from user-provided text input.

Template Method pattern: subclass only needs to implement parseValue(String) → T. The abstract base handles all parsing, splitting, and matching logic. IntRanges is the concrete implementation for Integer.

Input format

"1-5,10,20-25"

Split on , or ; (separatorChars = ";,") → parts ["1-5", "10", "20-25"]. Each part either contains - (range) or doesn't (single value). Ranges are stored as List<Range<T>>, singles as List<T>. doesMatch(value) checks ranges first, then singles — returns true on first match. If the input string is empty or null, nullRangeMatchesAlways (default false) determines behavior.

Key behaviors