Skip to content

Commit dd5c959

Browse files
authored
✨ allow comparing v2 field confidence (#274)
1 parent b4c6e68 commit dd5c959

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

.github/workflows/_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
gpg --list-secret-keys --keyid-format LONG
3030
3131
- name: Set up JDK ${{ matrix.java-version }}
32-
uses: actions/setup-java@v4
32+
uses: actions/setup-java@v5
3333
with:
3434
java-version: ${{ matrix.java-version }}
3535
distribution: ${{ matrix.distribution }}

.github/workflows/_publish-docs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
submodules: recursive
1515

1616
- name: Set up JDK
17-
uses: actions/setup-java@v4
17+
uses: actions/setup-java@v5
1818
with:
1919
java-version: "11"
2020
distribution: "temurin"
@@ -46,7 +46,6 @@ jobs:
4646
exit 1
4747
fi
4848
49-
5049
- name: Copy Code Samples
5150
run: |
5251
mkdir -p ./target/site/apidocs

.github/workflows/_test-integrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
submodules: recursive
2424

2525
- name: Set up JDK ${{ matrix.java-version }}
26-
uses: actions/setup-java@v4
26+
uses: actions/setup-java@v5
2727
with:
2828
java-version: ${{ matrix.java-version }}
2929
distribution: ${{ matrix.distribution }}

src/main/java/com/mindee/parsing/v2/field/FieldConfidence.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* Confidence level of a field as returned by the V2 API.
88
*/
99
public enum FieldConfidence {
10-
Certain("Certain"),
11-
High("High"),
10+
Low("Low"),
1211
Medium("Medium"),
13-
Low("Low");
12+
High("High"),
13+
Certain("Certain");
1414

1515
private final String json;
1616

@@ -35,4 +35,52 @@ public static FieldConfidence fromJson(String value) {
3535
}
3636
throw new IllegalArgumentException("Unknown confidence level '" + value + "'.");
3737
}
38+
39+
/**
40+
* Compares the current FieldConfidence level with another FieldConfidence level
41+
* to determine if the current level is greater.
42+
*
43+
* @param other the other FieldConfidence level to compare against
44+
* @return true if the current FieldConfidence level is greater than the specified level,
45+
* false otherwise
46+
*/
47+
public boolean greaterThan(FieldConfidence other) {
48+
return this.compareTo(other) > 0;
49+
}
50+
51+
/**
52+
* Compares the current FieldConfidence level with another FieldConfidence level
53+
* to determine if the current level is greater than or equal to the specified level.
54+
*
55+
* @param other the other FieldConfidence level to compare against
56+
* @return true if the current FieldConfidence level is greater than or equal to the specified level,
57+
* false otherwise
58+
*/
59+
public boolean greaterThanOrEqual(FieldConfidence other) {
60+
return this.compareTo(other) >= 0;
61+
}
62+
63+
/**
64+
* Compares the current FieldConfidence level with another FieldConfidence level
65+
* to determine if the current level is less than the specified level.
66+
*
67+
* @param other the other FieldConfidence level to compare against
68+
* @return true if the current FieldConfidence level is less than the specified level,
69+
* false otherwise
70+
*/
71+
public boolean lessThan(FieldConfidence other) {
72+
return this.compareTo(other) < 0;
73+
}
74+
75+
/**
76+
* Compares the current FieldConfidence level with another FieldConfidence level
77+
* to determine if the current level is less than or equal to the specified level.
78+
*
79+
* @param other the other FieldConfidence level to compare against
80+
* @return true if the current FieldConfidence level is less than or equal to the specified level,
81+
* false otherwise
82+
*/
83+
public boolean lessThanOrEqual(FieldConfidence other) {
84+
return this.compareTo(other) <= 0;
85+
}
3886
}

src/test/java/com/mindee/parsing/v2/InferenceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ void standardFieldTypes_confidenceAndLocations() throws IOException {
426426
FieldConfidence confidence = fieldSimpleString.getConfidence();
427427
boolean isCertain = confidence == FieldConfidence.Certain;
428428
assertTrue(isCertain);
429+
assertEquals(3, confidence.ordinal());
430+
assertTrue(confidence.greaterThanOrEqual(FieldConfidence.Certain));
431+
assertTrue(confidence.greaterThan(FieldConfidence.Medium));
432+
assertTrue(confidence.lessThanOrEqual(FieldConfidence.Certain));
433+
assertFalse(confidence.lessThan(FieldConfidence.Certain));
429434

430435
List<FieldLocation> locations = fieldSimpleString.getLocations();
431436
assertEquals(1, locations.size());

0 commit comments

Comments
 (0)