Project icon

com.io7m.jaffirm

Build status Maven Central Codecov

The jaffirm package provides simple and fast pre/postcondition and invariant checking functions.

Contents

Features

  • Static invocation, zero-allocation code paths for the common case of non-failing contracts
  • Specialized and generic variants of all functions for use in low-latency software
  • Detailed contract failure messages by construction
  • Written in pure Java 11
  • 100% automated unit test coverage
  • OSGi-ready
  • ISC license

Example

 0,      i -> "Input " + i + " must be > 0");
  checkPreconditionI(x, x % 2 == 0, i -> "Input " + i + " must be even");
  return x * 2;
}

int exampleMultis(final int x)
{
  checkPreconditionsI(
    x,
    conditionI(i -> i > 0,      i -> "Input " + i + " must be > 0"),
    conditionI(i -> i % 2 == 0, i -> "Input " + i + " must be even"));
  return x * 2;
}

> exampleSingles(0)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: 0
  Violated conditions:
    [0]: Input 0 must be > 0

> exampleSingles(1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: 1
  Violated conditions:
    [0]: Input 1 must be even

> exampleMultis(-1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: -1
  Violated conditions:
    [0]: Input -1 must be > 0
    [1]: Input -1 must be even

]]>

Releases

The most recently published version of the software is 4.0.1.

Source code and binaries are available from the repository.

Documentation

Documentation for the 4.0.1 release is available for reading online.

Documentation for current and older releases is archived in the repository.

User documentation

See the README.

Maven

The following is a complete list of the project's modules expressed as Maven dependencies:

<dependency>
  <groupId>com.io7m.jaffirm</groupId>
  <artifactId>com.io7m.jaffirm</artifactId>
  <version>4.0.1</version>
</dependency>

<dependency>
  <groupId>com.io7m.jaffirm</groupId>
  <artifactId>com.io7m.jaffirm.core</artifactId>
  <version>4.0.1</version>
</dependency>

<dependency>
  <groupId>com.io7m.jaffirm</groupId>
  <artifactId>com.io7m.jaffirm.tests</artifactId>
  <version>4.0.1</version>
</dependency>

Each release of the project is made available on Maven Central within ten minutes of the release announcement.

Changes

Subscribe to the releases atom feed.

2024-05-05 Release: com.io7m.jaffirm 4.0.1
2024-04-19 Change: Update org.immutables:value:2.10.0 → 2.10.1.
2024-04-19 Change: Update org.junit.jupiter:junit-jupiter-api:5.10.1 → 5.10.2.
2024-04-19 Change: Update org.junit.jupiter:junit-jupiter-engine:5.10.1 → 5.10.2.
2024-05-05 Change: Update com.io7m.junreachable:com.io7m.junreachable.core 4.0.0 → 4.0.2.
2024-05-05 Change: Update com.io7m.immutables.style 0.0.1 → 1.0.0.
2022-04-09 Release: com.io7m.jaffirm 4.0.0
2022-04-09 Change: (Backwards incompatible) Require JDK 17
2020-04-03 Release: com.io7m.jaffirm 3.0.4
2020-04-03 Change: Use primogenitor 3.8.0
2020-04-03 Release: com.io7m.jaffirm 3.0.3
2020-04-03 Change: Use primogenitor 3.7.0
2020-04-03 Release: com.io7m.jaffirm 3.0.2
2020-04-03 Change: Use primogenitor 3.6.0
2019-10-16 Release: com.io7m.jaffirm 3.0.1
2019-10-16 Change: Use correct junreachable 3.0.0 release
2019-06-23 Release: com.io7m.jaffirm 3.0.0
2018-05-17 Change: (Backwards incompatible) Remove checkstyle module and use common checkstyle rules
2018-05-17 Change: Use newest primogenitor
2019-06-23 Change: (Backwards incompatible) Require JDK 11
2017-11-04 Release: com.io7m.jaffirm 2.0.0
2017-11-04 Change: (Backwards incompatible) Require JDK 9 and publish a Java 9 module.
2017-11-04 Change: (Backwards incompatible) Remove com.io7m.jnull dependency.
2017-04-07 Release: com.io7m.jaffirm 1.1.0
2017-04-07 Change: Add variadic preconditions/postconditions/invariants. (tickets: 3 )
2017-04-05 Release: com.io7m.jaffirm 1.0.1
2017-04-05 Change: Rename project. Use the new primogenitor POM and 2017 project conventions. Move documentation to kstructural.
2017-02-22 Release: com.io7m.jaffirm 1.0.0
2017-02-22 Change: Initial API-stable release.
2016-08-26 Release: com.io7m.jaffirm 0.1.0
2016-08-26 Change: Initial release.

Sources

This project uses Git to manage source code.

Repository: https://www.github.com/io7m-com/jaffirm

$ git clone https://www.github.com/io7m-com/jaffirm

License

Copyright © 2024 Mark Raynsford <code@io7m.com> https://www.io7m.com

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

Bug Tracker

The project uses GitHub Issues to track issues.