@@ -78,9 +78,10 @@ public LibraryVersion(@NonNull String name, @NonNull String version) {
78
78
79
79
@ Override
80
80
public boolean equals (Object object ) {
81
- if (!(object instanceof LibraryVersion ))
81
+ if (!(object instanceof LibraryVersion )) {
82
82
return false ;
83
- LibraryVersion other = (LibraryVersion )object ;
83
+ }
84
+ LibraryVersion other = (LibraryVersion ) object ;
84
85
return this .name .equals (other .name ) && this .version .equals (other .version );
85
86
}
86
87
@@ -150,7 +151,8 @@ private static class HostStatus {
150
151
protected ExecutorService searchExecutorService = Executors .newFixedThreadPool (4 );
151
152
152
153
/** Executor used to run completion handlers. By default, runs on the main thread. */
153
- protected @ NonNull Executor completionExecutor = new HandlerExecutor (new Handler (Looper .getMainLooper ()));
154
+ protected @ NonNull
155
+ Executor completionExecutor = new HandlerExecutor (new Handler (Looper .getMainLooper ()));
154
156
155
157
protected Map <String , WeakReference <Object >> indices = new HashMap <>();
156
158
@@ -162,19 +164,21 @@ private static class HostStatus {
162
164
* Create a new client.
163
165
*
164
166
* @param applicationID [optional] The application ID.
165
- * @param apiKey [optional] A valid API key for the service.
166
- * @param readHosts List of hosts for read operations.
167
- * @param writeHosts List of hosts for write operations.
167
+ * @param apiKey [optional] A valid API key for the service.
168
+ * @param readHosts List of hosts for read operations.
169
+ * @param writeHosts List of hosts for write operations.
168
170
*/
169
171
protected AbstractClient (@ Nullable String applicationID , @ Nullable String apiKey , @ Nullable String [] readHosts , @ Nullable String [] writeHosts ) {
170
172
this .applicationID = applicationID ;
171
173
this .apiKey = apiKey ;
172
174
this .addUserAgent (new LibraryVersion ("Algolia for Android" , version ));
173
175
this .addUserAgent (new LibraryVersion ("Android" , Build .VERSION .RELEASE ));
174
- if (readHosts != null )
176
+ if (readHosts != null ) {
175
177
setReadHosts (readHosts );
176
- if (writeHosts != null )
178
+ }
179
+ if (writeHosts != null ) {
177
180
setWriteHosts (writeHosts );
181
+ }
178
182
}
179
183
180
184
// ----------------------------------------------------------------------
@@ -322,7 +326,9 @@ public void setHostDownDelay(int hostDownDelay) {
322
326
* @param userAgent The library to add.
323
327
*/
324
328
public void addUserAgent (@ NonNull LibraryVersion userAgent ) {
325
- userAgents .add (userAgent );
329
+ if (!userAgents .contains (userAgent )) {
330
+ userAgents .add (userAgent );
331
+ }
326
332
updateUserAgents ();
327
333
}
328
334
@@ -444,6 +450,7 @@ private static String _toCharArray(InputStream stream) throws IOException {
444
450
445
451
/**
446
452
* Reads the InputStream into a byte array
453
+ *
447
454
* @param stream the InputStream to read
448
455
* @return the stream's content as a byte[]
449
456
* @throws AlgoliaException if the stream can't be read or flushed
@@ -638,12 +645,10 @@ private byte[] _requestRaw(@NonNull Method m, @NonNull String url, @Nullable Map
638
645
}
639
646
return rawResponse ;
640
647
641
- }
642
- catch (JSONException e ) { // fatal
648
+ } catch (JSONException e ) { // fatal
643
649
consumeQuietly (hostConnection );
644
650
throw new AlgoliaException ("Invalid JSON returned by server" , e );
645
- }
646
- catch (UnsupportedEncodingException e ) { // fatal
651
+ } catch (UnsupportedEncodingException e ) { // fatal
647
652
consumeQuietly (hostConnection );
648
653
throw new AlgoliaException ("Invalid encoding returned by server" , e );
649
654
} catch (IOException e ) { // host error, continue on the next host
@@ -697,6 +702,7 @@ private void checkTimeout(int connectTimeout) {
697
702
698
703
/**
699
704
* Get the hosts that are not considered down in a given list.
705
+ *
700
706
* @param hosts a list of hosts whose {@link HostStatus} will be checked.
701
707
* @return the hosts considered up, or all hosts if none is known to be reachable.
702
708
*/
@@ -727,7 +733,7 @@ abstract protected class AsyncTaskRequest extends FutureRequest {
727
733
* Construct a new request with the specified completion handler, executing on the client's search executor,
728
734
* and calling the completion handler on the client's completion executor.
729
735
*
730
- * @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
736
+ * @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
731
737
*/
732
738
protected AsyncTaskRequest (@ Nullable CompletionHandler completionHandler ) {
733
739
this (completionHandler , searchExecutorService );
@@ -737,8 +743,8 @@ protected AsyncTaskRequest(@Nullable CompletionHandler completionHandler) {
737
743
* Construct a new request with the specified completion handler, executing on the specified executor, and
738
744
* calling the completion handler on the client's completion executor.
739
745
*
740
- * @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
741
- * @param requestExecutor Executor on which to execute the request.
746
+ * @param completionHandler The completion handler to be notified of results. May be null if the caller omitted it.
747
+ * @param requestExecutor Executor on which to execute the request.
742
748
*/
743
749
protected AsyncTaskRequest (@ Nullable CompletionHandler completionHandler , @ NonNull Executor requestExecutor ) {
744
750
super (completionHandler , requestExecutor , completionExecutor );
0 commit comments