Skip to content

Commit

Permalink
Eliminate kstructural
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed May 4, 2024
1 parent 9b87745 commit 0e56965
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 544 deletions.
63 changes: 63 additions & 0 deletions README.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

## 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 21.
* High coverage test suite.
* [OSGi-ready](https://www.osgi.org/)
* [JPMS-ready](https://en.wikipedia.org/wiki/Java_Platform_Module_System)
* 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
```
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,67 @@ jaffirm
| OpenJDK (Temurin) LTS | Linux | [![Build (OpenJDK (Temurin) LTS, Linux)](https://img.shields.io/github/actions/workflow/status/io7m-com/jaffirm/main.linux.temurin.lts.yml)](https://www.github.com/io7m-com/jaffirm/actions?query=workflow%3Amain.linux.temurin.lts)|
| OpenJDK (Temurin) Current | Windows | [![Build (OpenJDK (Temurin) Current, Windows)](https://img.shields.io/github/actions/workflow/status/io7m-com/jaffirm/main.windows.temurin.current.yml)](https://www.github.com/io7m-com/jaffirm/actions?query=workflow%3Amain.windows.temurin.current)|
| OpenJDK (Temurin) LTS | Windows | [![Build (OpenJDK (Temurin) LTS, Windows)](https://img.shields.io/github/actions/workflow/status/io7m-com/jaffirm/main.windows.temurin.lts.yml)](https://www.github.com/io7m-com/jaffirm/actions?query=workflow%3Amain.windows.temurin.lts)|

## 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 21.
* High coverage test suite.
* [OSGi-ready](https://www.osgi.org/)
* [JPMS-ready](https://en.wikipedia.org/wiki/Java_Platform_Module_System)
* 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
```

242 changes: 0 additions & 242 deletions com.io7m.jaffirm.documentation/pom.xml

This file was deleted.

20 changes: 0 additions & 20 deletions com.io7m.jaffirm.documentation/src/main/assembly/documentation.xml

This file was deleted.

0 comments on commit 0e56965

Please sign in to comment.