Skip to content

Latest commit

 

History

History
70 lines (53 loc) · 3.06 KB

README.md

File metadata and controls

70 lines (53 loc) · 3.06 KB

jranges

Maven Central Maven Central (snapshot) Codecov Java Version

com.io7m.jranges

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

jranges

A set of functions and types for dealing with ranges and intervals.

Features

  • Immutable range types, for specifying ranges over all the available integral and floating point types.
  • Functions for checking that values fall within given ranges.
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Usage

Range Checks

Use the RangeCheck class to perform range checks:

RangeCheck.checkIncludedInLong(
  23L,
  "Number of assignments",
  RangeInclusiveL.of(0L, 99),
  "Valid number of assignments"
);

RangeCheck.checkIncludedInLong(
  130L,
  "Number of assignments",
  RangeInclusiveL.of(0L, 99),
  "Valid number of assignments"
);

The second call will throw a RangeCheckException with a message similar to Range check failed: 0 <= Number of assignments (130) <= 99 (Valid number of assignments) == false.

Range Types

The package exposes numerous immutable half-open and inclusive range types, specialized to various Java numeric types:

  • RangeHalfOpenB
  • RangeHalfOpenD
  • RangeHalfOpenI
  • RangeHalfOpenL
  • RangeInclusiveB
  • RangeInclusiveD
  • RangeInclusiveI
  • RangeInclusiveL