2
2
3
3
import java .lang .reflect .Array ;
4
4
import java .util .Arrays ;
5
- import java .util .HashMap ;
5
+ import java .util .Collections ;
6
6
import java .util .List ;
7
7
import java .util .Map ;
8
8
import java .util .concurrent .ExecutionException ;
@@ -37,7 +37,6 @@ public abstract class CreatubblesRequest<T extends CreatubblesResponse> {
37
37
private JsonObject metaCache ;
38
38
39
39
private String accessToken ;
40
- private static final String EMPTY_RESPONSE = "{}" ;
41
40
private static final String APPLICATION_VND_API_JSON = "application/vnd.api+json" ;
42
41
43
42
public CreatubblesRequest (String endPoint , HttpMethod httpMethod ) {
@@ -58,7 +57,7 @@ public CreatubblesRequest(String endPoint, HttpMethod httpMethod, String accessT
58
57
if (urlParameters != null ) {
59
58
this .urlParameters = urlParameters ;
60
59
} else {
61
- this .urlParameters = new HashMap < String , String > ();
60
+ this .urlParameters = Collections . emptyMap ();
62
61
}
63
62
this .accessToken = accessToken ;
64
63
}
@@ -137,10 +136,11 @@ private boolean isSuccessStatus(Response response) {
137
136
}
138
137
139
138
public boolean isSuccessStatusCode (int status ) {
140
- return status == 200 || status == 204 ;
139
+ return status == Response . Status . OK . getStatusCode () || status == Response . Status . CREATED . getStatusCode () ;
141
140
}
142
141
143
142
public void cancelRequest () {
143
+ //possible npe?
144
144
if (futureResponse != null & !futureResponse .isDone ()) {
145
145
futureResponse .cancel (true );
146
146
}
@@ -150,9 +150,7 @@ public Response getRawResponse() {
150
150
if (response == null && futureResponse != null && futureResponse .isDone ()) {
151
151
try {
152
152
response = futureResponse .get ();
153
- } catch (InterruptedException e ) {
154
- e .printStackTrace ();
155
- } catch (ExecutionException e ) {
153
+ } catch (InterruptedException | ExecutionException e ) {
156
154
e .printStackTrace ();
157
155
}
158
156
}
@@ -167,9 +165,7 @@ private void initResponse() {
167
165
Class <? extends T > responseClass = getResponseClass ();
168
166
if (response != null && responseClass != null ) {
169
167
String json = response .readEntity (String .class );
170
- if (isSuccessStatus (response ) && json .isEmpty ()) {
171
- json = EMPTY_RESPONSE ;
172
- } else if (!isSuccessStatus (response )) {
168
+ if (!isSuccessStatus (response )) {
173
169
responseCache = createDefaultResponse (json );
174
170
} else {
175
171
try {
@@ -206,8 +202,8 @@ private void initResponseSingle(JsonObject json) {
206
202
@ SuppressWarnings ("unchecked" )
207
203
private void initResponseArray (JsonObject json ) {
208
204
responseArrayCache = (T []) CreatubblesAPI .GSON .fromJson (json , Array .newInstance (getResponseClass (), 0 ).getClass ());
209
- for (int i = 0 ; i < responseArrayCache . length ; i ++ ) {
210
- updateResponse (responseArrayCache [ i ] );
205
+ for (T aResponseArrayCache : responseArrayCache ) {
206
+ updateResponse (aResponseArrayCache );
211
207
}
212
208
}
213
209
0 commit comments