Interface Range<A>

Type Parameters:
A - the element type of the range
All Known Implementing Classes:
Range.Bounded, Range.Empty

public sealed interface Range<A> permits Range.Empty<A>, Range.Bounded<A>
PostgreSQL range type. Represents a range of values of type A with full bound inclusivity information.

A range can be:

  • Empty — no values are in the range
  • Bounded — with an optional lower and/or upper bound. A null lower bound means negative infinity; a null upper bound means positive infinity. Infinite bounds are always exclusive regardless of the inclusivity flag.

The standard PostgreSQL range types are:

  • int4rangeRange<Integer>
  • int8rangeRange<Long>
  • numrangeRange<java.math.BigDecimal>
  • tsrangeRange<java.time.LocalDateTime>
  • tstzrangeRange<java.time.Instant>
  • daterangeRange<java.time.LocalDate>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A bounded range with explicit bound inclusivity.
    static final record 
    An empty range containing no values.
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static <A> Range<A>
    bounded(A lower, A upper)
    Creates a half-open range [lower, upper) — inclusive lower, exclusive upper.
    static <A> Range<A>
    Creates an empty range.
    static <A> Range<A>
    of(A lower, boolean lowerInclusive, A upper, boolean upperInclusive)
    Creates a range with the given bounds and their inclusivity.
    static <A> Range<A>
    Creates an unbounded range (,) — from negative infinity to positive infinity.
  • Method Details

    • empty

      static <A> Range<A> empty()
      Creates an empty range.
    • of

      static <A> Range<A> of(A lower, boolean lowerInclusive, A upper, boolean upperInclusive)
      Creates a range with the given bounds and their inclusivity.
      Parameters:
      lower - lower bound, or null for negative infinity (always exclusive)
      lowerInclusive - whether the lower bound is inclusive
      upper - upper bound, or null for positive infinity (always exclusive)
      upperInclusive - whether the upper bound is inclusive
    • bounded

      static <A> Range<A> bounded(A lower, A upper)
      Creates a half-open range [lower, upper) — inclusive lower, exclusive upper. This is the canonical form for discrete range types (int4range, int8range, daterange).
    • unbounded

      static <A> Range<A> unbounded()
      Creates an unbounded range (,) — from negative infinity to positive infinity.