Skip to content

Commit 39cdc63

Browse files
committed
✨ allow comparing v2 field confidence
1 parent b4c6e68 commit 39cdc63

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

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)