Ranges.javaUnion 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.
"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.
"-5--1" → range from -5 to -1. The parser distinguishes the negative sign from the range separator by checking for two consecutive hyphens"1-5,3-7" matches both. doesMatch(4) returns true (first match in range list)Serializable — can be stored in user preferences XML. The ranges survive across sessions