Skip to content

Commit 0b51ecb

Browse files
committed
Make fields of Response final
Immutability is always preferrable, and their is no reason for a Response to change so it is inherently immutable.
1 parent c351ee5 commit 0b51ecb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/main/java/com/debortoliwines/odoo/api/Response.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
public class Response {
44

5-
private boolean isSuccessful;
6-
private Exception errorCause;
7-
private Object responseObject;
5+
private final boolean isSuccessful;
6+
private final Exception errorCause;
7+
private final Object responseObject;
8+
private final Object[] responseObjectAsArray;
89

9-
public Response(Exception errorCause) {
10+
public Response(final Exception errorCause) {
1011
this.isSuccessful = false;
1112
this.errorCause = errorCause;
1213
this.responseObject = null;
14+
this.responseObjectAsArray = new Object[0];
1315
}
1416

15-
public Response(Object responseObject) {
17+
public Response(final Object responseObject) {
1618
this.isSuccessful = true;
1719
this.errorCause = null;
1820
this.responseObject = responseObject;
21+
if (responseObject instanceof Object[]) {
22+
this.responseObjectAsArray = (Object[]) responseObject;
23+
} else {
24+
this.responseObjectAsArray = new Object[] { responseObject };
25+
}
1926
}
2027

2128
public boolean isSuccessful() {
@@ -31,10 +38,6 @@ public Object getResponseObject() {
3138
}
3239

3340
public Object[] getResponseObjectAsArray() {
34-
if (responseObject instanceof Object[]) {
35-
return (Object[]) responseObject;
36-
} else {
37-
return new Object[] { responseObject };
38-
}
41+
return responseObjectAsArray;
3942
}
4043
}

0 commit comments

Comments
 (0)