Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit d8d8c5e

Browse files
authored
@Nullable/NotNull: Ensure consistency with documentation (#130) (#132)
1 parent dfb6408 commit d8d8c5e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/Client.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.os.Handler;
2929
import android.os.Looper;
3030
import android.support.annotation.NonNull;
31+
import android.support.annotation.Nullable;
3132

3233
import org.json.JSONArray;
3334
import org.json.JSONException;
@@ -151,7 +152,7 @@ public Client(@NonNull String applicationID, @NonNull String apiKey) {
151152
* @param apiKey A valid API key for the service.
152153
* @param hosts An explicit list of hosts to target, or null to use the default hosts.
153154
*/
154-
public Client(@NonNull String applicationID, @NonNull String apiKey, String[] hosts) {
155+
public Client(@NonNull String applicationID, @NonNull String apiKey, @Nullable String[] hosts) {
155156
this.applicationID = applicationID;
156157
this.apiKey = apiKey;
157158
this.addUserAgent(new LibraryVersion("Algolia for Android", version));
@@ -197,7 +198,7 @@ public String getApplicationID() {
197198
* @param name Header name.
198199
* @param value Value for the header. If null, the header will be removed.
199200
*/
200-
public void setHeader(@NonNull String name, String value) {
201+
public void setHeader(@NonNull String name, @Nullable String value) {
201202
if (value == null) {
202203
headers.remove(name);
203204
} else {
@@ -916,7 +917,7 @@ protected void onCancelled(APIResult apiResult) {
916917
*
917918
* @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
918919
*/
919-
AsyncTaskRequest(CompletionHandler completionHandler) {
920+
AsyncTaskRequest(@Nullable CompletionHandler completionHandler) {
920921
this(completionHandler, searchExecutorService);
921922
}
922923

@@ -926,7 +927,7 @@ protected void onCancelled(APIResult apiResult) {
926927
* @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
927928
* @param executorService Executor service on which to execute the request.
928929
*/
929-
AsyncTaskRequest(CompletionHandler completionHandler, @NonNull ExecutorService executorService) {
930+
AsyncTaskRequest(@Nullable CompletionHandler completionHandler, @NonNull ExecutorService executorService) {
930931
this.completionHandler = completionHandler;
931932
this.executorService = executorService;
932933
}

algoliasearch/src/main/java/com/algolia/search/saas/Index.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.algolia.search.saas;
2525

2626
import android.support.annotation.NonNull;
27+
import android.support.annotation.Nullable;
2728

2829
import org.json.JSONArray;
2930
import org.json.JSONException;
@@ -111,8 +112,8 @@ protected String getEncodedIndexName() {
111112
* @param completionHandler The listener that will be notified of the request's outcome.
112113
* @return A cancellable request.
113114
*/
114-
public Request searchAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler) {
115-
final Query queryCopy = new Query(query);
115+
public Request searchAsync(@Nullable Query query, @Nullable CompletionHandler completionHandler) {
116+
final Query queryCopy = query != null ? new Query(query) : new Query();
116117
return getClient().new AsyncTaskRequest(completionHandler) {
117118
@NonNull
118119
@Override JSONObject run() throws AlgoliaException {
@@ -126,7 +127,7 @@ public Request searchAsync(@NonNull Query query, @NonNull CompletionHandler comp
126127
*
127128
* @return Search results.
128129
*/
129-
public JSONObject searchSync(@NonNull Query query) throws AlgoliaException {
130+
public JSONObject searchSync(@Nullable Query query) throws AlgoliaException {
130131
return search(query);
131132
}
132133

@@ -836,7 +837,11 @@ protected void deleteByQuery(@NonNull Query query) throws AlgoliaException {
836837
* @return a JSONObject containing search results
837838
* @throws AlgoliaException
838839
*/
839-
protected JSONObject search(@NonNull Query query) throws AlgoliaException {
840+
protected JSONObject search(@Nullable Query query) throws AlgoliaException {
841+
if (query == null) {
842+
query = new Query();
843+
}
844+
840845
String cacheKey = null;
841846
byte[] rawResponse = null;
842847
if (isCacheEnabled) {
@@ -862,7 +867,11 @@ protected JSONObject search(@NonNull Query query) throws AlgoliaException {
862867
* @return a byte array containing search results
863868
* @throws AlgoliaException
864869
*/
865-
protected byte[] searchRaw(@NonNull Query query) throws AlgoliaException {
870+
protected byte[] searchRaw(@Nullable Query query) throws AlgoliaException {
871+
if (query == null) {
872+
query = new Query();
873+
}
874+
866875
try {
867876
String paramsString = query.build();
868877
if (paramsString.length() > 0) {

algoliasearch/src/main/java/com/algolia/search/saas/Query.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.algolia.search.saas;
22

33
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
45
import android.text.TextUtils;
56

67
import org.json.JSONArray;
@@ -1241,7 +1242,7 @@ private static String[] parseCommaArray(String string) {
12411242
* It will first be converted to a String by the `toString()` method.
12421243
* @return This instance (used to chain calls).
12431244
*/
1244-
public @NonNull Query set(@NonNull String name, Object value) {
1245+
public @NonNull Query set(@NonNull String name, @Nullable Object value) {
12451246
if (value == null) {
12461247
parameters.remove(name);
12471248
} else {
@@ -1255,7 +1256,7 @@ private static String[] parseCommaArray(String string) {
12551256
* @param name The parameter's name.
12561257
* @return The parameter's value, or null if a parameter with the specified name does not exist.
12571258
*/
1258-
public String get(@NonNull String name) {
1259+
public @Nullable String get(@NonNull String name) {
12591260
return parameters.get(name);
12601261
}
12611262
}

0 commit comments

Comments
 (0)