jaffirm
The jaffirm
package provides simple and fast pre/postcondition and invariant
checking functions.
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 17.
- High coverage test suite.
- OSGi-ready
- JPMS-ready
- ISC license.
Usage
Declare preconditions with the Preconditions
class.
Declare postconditions with the Postconditions
class.
Declare invariants with the Invariants
class.
import static com.io7m.jaffirm.core.Contracts.conditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionsI;
int exampleSingles(final int x)
{
checkPreconditionI(x, x > 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 & Development Snapshots
Releases
You can subscribe to the atom feed to be notified of project releases.
The most recently released version of the package is 4.0.1.
4.0.1 Release (2024-05-05Z)
- Update org.immutables:value:2.10.0 → 2.10.1.
- Update org.junit.jupiter:junit-jupiter-api:5.10.1 → 5.10.2.
- Update org.junit.jupiter:junit-jupiter-engine:5.10.1 → 5.10.2.
- Update com.io7m.junreachable:com.io7m.junreachable.core 4.0.0 → 4.0.2.
- Update com.io7m.immutables.style 0.0.1 → 1.0.0.
The compiled artifacts for the release (and all previous releases) are available on Maven Central.
Maven Modules
<dependency> <group>com.io7m.jaffirm</group> <artifactId>com.io7m.jaffirm.core</artifactId> <version>4.0.1</version> </dependency><dependency> <group>com.io7m.jaffirm</group> <artifactId>com.io7m.jaffirm.tests</artifactId> <version>4.0.1</version> </dependency>
Previous Releases
The changelogs for the most recent previous releases are as follows:
4.0.0 Release (2022-04-09Z)
- Require JDK 17 (Backwards incompatible)
3.0.4 Release (2020-04-03Z)
- Use primogenitor 3.8.0
3.0.3 Release (2020-04-03Z)
- Use primogenitor 3.7.0
3.0.2 Release (2020-04-03Z)
- Use primogenitor 3.6.0
Development Snapshots
At the time of writing, the current unstable development version of the package is 4.0.2-SNAPSHOT.
Development snapshots may be available in the Central Portal Snapshots repository. Snapshots are published to this repository every time the project is built by the project's continuous integration system, but snapshots do expire after around ninety days and so may or may not be available depending on when a build of the package was last triggered.
Manual
This project does not have any user manuals or other documentation beyond what might be present on the page above.
Sources
This project uses Git to manage source code.
Repository: https://www.github.com/io7m-com/jaffirm
$ git clone --recursive https://www.github.com/io7m-com/jaffirm
Issues
This project uses GitHub Issues to track issues.
License
Copyright © 2023 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.