From 31bee0b6cf2ea6b40ae985db743bfe913fa500c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Tue, 14 Oct 2025 20:02:01 +0200 Subject: [PATCH] :sparkles: allow comparing v2 field confidence --- .github/workflows/_build.yml | 2 +- .github/workflows/_publish-docs.yml | 3 +- .github/workflows/_test-integrations.yml | 2 +- .../parsing/v2/field/FieldConfidence.java | 54 +++++++++++++++++-- .../com/mindee/parsing/v2/InferenceTest.java | 5 ++ 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index c94ea2fae..458d5ced4 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -29,7 +29,7 @@ jobs: gpg --list-secret-keys --keyid-format LONG - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: ${{ matrix.java-version }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/_publish-docs.yml b/.github/workflows/_publish-docs.yml index 8d0631ac4..d03a3e925 100644 --- a/.github/workflows/_publish-docs.yml +++ b/.github/workflows/_publish-docs.yml @@ -14,7 +14,7 @@ jobs: submodules: recursive - name: Set up JDK - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: "11" distribution: "temurin" @@ -46,7 +46,6 @@ jobs: exit 1 fi - - name: Copy Code Samples run: | mkdir -p ./target/site/apidocs diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 6fefaa7b3..fe4bed41a 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -23,7 +23,7 @@ jobs: submodules: recursive - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: ${{ matrix.java-version }} distribution: ${{ matrix.distribution }} diff --git a/src/main/java/com/mindee/parsing/v2/field/FieldConfidence.java b/src/main/java/com/mindee/parsing/v2/field/FieldConfidence.java index 8651f02f6..01daa01fa 100644 --- a/src/main/java/com/mindee/parsing/v2/field/FieldConfidence.java +++ b/src/main/java/com/mindee/parsing/v2/field/FieldConfidence.java @@ -7,10 +7,10 @@ * Confidence level of a field as returned by the V2 API. */ public enum FieldConfidence { - Certain("Certain"), - High("High"), + Low("Low"), Medium("Medium"), - Low("Low"); + High("High"), + Certain("Certain"); private final String json; @@ -35,4 +35,52 @@ public static FieldConfidence fromJson(String value) { } throw new IllegalArgumentException("Unknown confidence level '" + value + "'."); } + + /** + * Compares the current FieldConfidence level with another FieldConfidence level + * to determine if the current level is greater. + * + * @param other the other FieldConfidence level to compare against + * @return true if the current FieldConfidence level is greater than the specified level, + * false otherwise + */ + public boolean greaterThan(FieldConfidence other) { + return this.compareTo(other) > 0; + } + + /** + * Compares the current FieldConfidence level with another FieldConfidence level + * to determine if the current level is greater than or equal to the specified level. + * + * @param other the other FieldConfidence level to compare against + * @return true if the current FieldConfidence level is greater than or equal to the specified level, + * false otherwise + */ + public boolean greaterThanOrEqual(FieldConfidence other) { + return this.compareTo(other) >= 0; + } + + /** + * Compares the current FieldConfidence level with another FieldConfidence level + * to determine if the current level is less than the specified level. + * + * @param other the other FieldConfidence level to compare against + * @return true if the current FieldConfidence level is less than the specified level, + * false otherwise + */ + public boolean lessThan(FieldConfidence other) { + return this.compareTo(other) < 0; + } + + /** + * Compares the current FieldConfidence level with another FieldConfidence level + * to determine if the current level is less than or equal to the specified level. + * + * @param other the other FieldConfidence level to compare against + * @return true if the current FieldConfidence level is less than or equal to the specified level, + * false otherwise + */ + public boolean lessThanOrEqual(FieldConfidence other) { + return this.compareTo(other) <= 0; + } } diff --git a/src/test/java/com/mindee/parsing/v2/InferenceTest.java b/src/test/java/com/mindee/parsing/v2/InferenceTest.java index 983fe40c2..456239d29 100644 --- a/src/test/java/com/mindee/parsing/v2/InferenceTest.java +++ b/src/test/java/com/mindee/parsing/v2/InferenceTest.java @@ -426,6 +426,11 @@ void standardFieldTypes_confidenceAndLocations() throws IOException { FieldConfidence confidence = fieldSimpleString.getConfidence(); boolean isCertain = confidence == FieldConfidence.Certain; assertTrue(isCertain); + assertEquals(3, confidence.ordinal()); + assertTrue(confidence.greaterThanOrEqual(FieldConfidence.Certain)); + assertTrue(confidence.greaterThan(FieldConfidence.Medium)); + assertTrue(confidence.lessThanOrEqual(FieldConfidence.Certain)); + assertFalse(confidence.lessThan(FieldConfidence.Certain)); List locations = fieldSimpleString.getLocations(); assertEquals(1, locations.size());