Skip to content

Commit 9e8460c

Browse files
committed
Small bugfix
1 parent e11b2e4 commit 9e8460c

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

client/src/main/java/in/clayfish/printful/models/Builder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package in.clayfish.printful.models;
22

3+
import in.clayfish.printful.exceptions.ValidationFailedException;
4+
35
/**
46
* @author shuklaalok7
57
* @since 18/01/2017
68
*/
79
public interface Builder<T> {
810

911
/**
10-
* @return
12+
* @return Built object of type T
13+
* @throws ValidationFailedException If {@link #check()} has been called and built object fails
14+
* basic validation constraints
1115
*/
12-
T build();
16+
T build() throws ValidationFailedException;
1317

1418
/**
19+
* Once call to this method is chained, {@link #build()} can throw
20+
* {@link ValidationFailedException} because it validates the objects after building it.
21+
*
1522
* @return Builder object
1623
*/
1724
Builder<T> check();

client/src/main/java/in/clayfish/printful/models/includable/Address.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public Builder() {
126126
this.address = new Address();
127127
}
128128

129+
@Override
129130
public Builder check() {
130131
this.checkValidity = true;
131132
return this;
@@ -185,10 +186,7 @@ public Builder company(String company) {
185186
return this;
186187
}
187188

188-
/**
189-
*
190-
* @return
191-
*/
189+
@Override
192190
public Address build() {
193191
if (checkValidity) {
194192
checkValidity();
@@ -202,10 +200,10 @@ public Address build() {
202200
private void checkValidity() {
203201
if (this.address.country == null || this.address.country.getCode() == null || this.address.country.getCode().isEmpty()
204202
|| this.address.state == null || this.address.state.getCode() == null || this.address.state.getCode().isEmpty()
205-
|| this.address.name == null || !this.address.name.isEmpty()
206-
|| this.address.city == null || !this.address.city.isEmpty()
207-
|| this.address.address1 == null || !this.address.address1.isEmpty()
208-
|| this.address.zip == null || !this.address.zip.isEmpty()) {
203+
|| this.address.name == null || this.address.name.isEmpty()
204+
|| this.address.city == null || this.address.city.isEmpty()
205+
|| this.address.address1 == null || this.address.address1.isEmpty()
206+
|| this.address.zip == null || this.address.zip.isEmpty()) {
209207
throw new ValidationFailedException();
210208
}
211209
}

0 commit comments

Comments
 (0)