Skip to content

Commit 68d61f7

Browse files
add AddressField implementation
1 parent 524c222 commit 68d61f7

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.mindee.parsing.standard;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6+
import com.mindee.geometry.Polygon;
7+
import com.mindee.geometry.PolygonDeserializer;
8+
import com.mindee.parsing.SummaryHelper;
9+
import lombok.Getter;
10+
11+
/**
12+
* Represent a postal address field broken down into its individual components.
13+
*/
14+
@Getter
15+
@JsonIgnoreProperties(ignoreUnknown = true)
16+
public final class AddressField extends BaseField {
17+
18+
/** The full address as a single string. */
19+
private final String value;
20+
21+
/** The address exactly as it appears on the document. */
22+
private final String rawValue;
23+
24+
/** Street number. */
25+
private final String streetNumber;
26+
27+
/** Street name. */
28+
private final String streetName;
29+
30+
/** PO-box number. */
31+
private final String poBox;
32+
33+
/** Additional address complement. */
34+
private final String addressComplement;
35+
36+
/** City or locality. */
37+
private final String city;
38+
39+
/** Postal or ZIP code. */
40+
private final String postalCode;
41+
42+
/** State, province or region. */
43+
private final String state;
44+
45+
/** Country. */
46+
private final String country;
47+
48+
public AddressField(
49+
@JsonProperty("value")
50+
String value,
51+
@JsonProperty("raw_value")
52+
String rawValue,
53+
@JsonProperty("street_number")
54+
String streetNumber,
55+
@JsonProperty("street_name")
56+
String streetName,
57+
@JsonProperty("po_box")
58+
String poBox,
59+
@JsonProperty("address_complement")
60+
String addressComplement,
61+
@JsonProperty("city")
62+
String city,
63+
@JsonProperty("postal_code")
64+
String postalCode,
65+
@JsonProperty("state")
66+
String state,
67+
@JsonProperty("country")
68+
String country,
69+
@JsonProperty("confidence")
70+
Double confidence,
71+
@JsonProperty("polygon")
72+
@JsonDeserialize(using = PolygonDeserializer.class)
73+
Polygon polygon,
74+
@JsonProperty("page_id")
75+
Integer pageId
76+
) {
77+
super(confidence, polygon, pageId);
78+
this.value = value;
79+
this.rawValue = rawValue;
80+
this.streetNumber = streetNumber;
81+
this.streetName = streetName;
82+
this.poBox = poBox;
83+
this.addressComplement = addressComplement;
84+
this.city = city;
85+
this.postalCode = postalCode;
86+
this.state = state;
87+
this.country = country;
88+
}
89+
90+
/**
91+
* Address field constructor only containing the value.
92+
*/
93+
public AddressField(
94+
String value,
95+
Double confidence,
96+
Polygon polygon
97+
) {
98+
this(value, null, null, null, null,
99+
null, null, null, null, null,
100+
confidence, polygon, null);
101+
}
102+
103+
/**
104+
* The field is considered empty when the full value is either null or empty.
105+
*/
106+
public boolean isEmpty() {
107+
return value == null || value.isEmpty();
108+
}
109+
110+
@Override
111+
public String toString() {
112+
return SummaryHelper.formatString(this.value);
113+
}
114+
}

0 commit comments

Comments
 (0)