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

Commit be7629b

Browse files
authored
Query: maintenance (#202)
* Query: Deprecate numericFilters * Gradle: Add support-annotation library * Query: Nullity annotations
1 parent 981b1b0 commit be7629b

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

algoliasearch/common.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ repositories {
7474

7575
dependencies {
7676
compile 'com.android.support:appcompat-v7:24.2.1'
77+
compile 'com.android.support:support-annotations:24.2.1'
7778
compile fileTree(include: ['*.jar'], dir: 'libs')
7879

7980
testCompile "junit:junit:4.12"

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

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ public String[] getAnalyticsTags() {
183183
* Search for entries around a given latitude/longitude.
184184
*
185185
*/
186-
public @NonNull Query setAroundLatLng(LatLng location) {
186+
public @NonNull Query setAroundLatLng(@Nullable LatLng location) {
187187
if (location == null) {
188188
return set(KEY_AROUND_LAT_LNG, null);
189189
} else {
190190
return set(KEY_AROUND_LAT_LNG, location.lat + "," + location.lng);
191191
}
192192
}
193193

194-
public LatLng getAroundLatLng() {
194+
public @Nullable LatLng getAroundLatLng() {
195195
return LatLng.parse(get(KEY_AROUND_LAT_LNG));
196196
}
197197

@@ -363,7 +363,7 @@ public String[] getFacets() {
363363
*
364364
* @deprecated Use {@link Query#getFilters()} instead.
365365
*/
366-
public JSONArray getFacetFilters() {
366+
public @Nullable JSONArray getFacetFilters() {
367367
try {
368368
String value = get(KEY_FACET_FILTERS);
369369
if (value != null) {
@@ -395,7 +395,7 @@ public JSONArray getFacetFilters() {
395395
* Get the numeric, facet or/and tag filters for this Query.
396396
* @return a String with this query's filters.
397397
*/
398-
public String getFilters() {
398+
public @Nullable String getFilters() {
399399
return get(KEY_FILTERS);
400400
}
401401

@@ -419,7 +419,7 @@ public Boolean getGetRankingInfo() {
419419
return set(KEY_HIGHLIGHT_POST_TAG, tag);
420420
}
421421

422-
public String getHighlightPostTag() {
422+
public @Nullable String getHighlightPostTag() {
423423
return get(KEY_HIGHLIGHT_POST_TAG);
424424
}
425425

@@ -429,7 +429,7 @@ public String getHighlightPostTag() {
429429
return set(KEY_HIGHLIGHT_PRE_TAG, tag);
430430
}
431431

432-
public String getHighlightPreTag() {
432+
public @Nullable String getHighlightPreTag() {
433433
return get(KEY_HIGHLIGHT_PRE_TAG);
434434
}
435435

@@ -457,7 +457,7 @@ public static final class IgnorePlurals {
457457
public final boolean enabled;
458458

459459
/** A list containing every active language's code. When {@code null}, all supported languages are be used. */
460-
public final List<String> languageCodes;
460+
public @Nullable final List<String> languageCodes;
461461

462462
/**
463463
* Construct an IgnorePlurals object for a boolean value.
@@ -507,7 +507,7 @@ public String toString() {
507507
}
508508
}
509509

510-
static @NonNull IgnorePlurals parse(String s) {
510+
static @NonNull IgnorePlurals parse(@Nullable String s) {
511511
if (s == null || s.length() == 0 || s.equals("null")) {
512512
return new IgnorePlurals(false);
513513
} else if ("true".equals(s) || "false".equals(s)) {
@@ -536,7 +536,7 @@ public String toString() {
536536
}
537537

538538
@Override
539-
public boolean equals(Object o) {
539+
public boolean equals(@Nullable Object o) {
540540
if (this == o) {
541541
return true;
542542
}
@@ -601,7 +601,9 @@ Query setIgnorePlurals(@Nullable String... languageISOCodes) {
601601
*/
602602
public static final class GeoRect
603603
{
604+
@NonNull
604605
public final LatLng p1;
606+
@NonNull
605607
public final LatLng p2;
606608

607609
public GeoRect(@NonNull LatLng p1, @NonNull LatLng p2) {
@@ -610,7 +612,7 @@ public GeoRect(@NonNull LatLng p1, @NonNull LatLng p2) {
610612
}
611613

612614
@Override
613-
public boolean equals(Object other) {
615+
public boolean equals(@Nullable Object other) {
614616
return other != null && other instanceof GeoRect
615617
&& this.p1.equals(((GeoRect)other).p1)
616618
&& this.p2.equals(((GeoRect)other).p2);
@@ -632,7 +634,7 @@ public int hashCode() {
632634
*
633635
* You can use several bounding boxes (OR) by calling this method several times.
634636
*/
635-
public @NonNull Query setInsideBoundingBox(GeoRect... boxes) {
637+
public @NonNull Query setInsideBoundingBox(@Nullable GeoRect... boxes) {
636638
if (boxes == null) {
637639
set(KEY_INSIDE_BOUNDING_BOX, null);
638640
} else {
@@ -654,7 +656,7 @@ public int hashCode() {
654656
return this;
655657
}
656658

657-
public GeoRect[] getInsideBoundingBox() {
659+
public @Nullable GeoRect[] getInsideBoundingBox() {
658660
try {
659661
String value = get(KEY_INSIDE_BOUNDING_BOX);
660662
if (value != null) {
@@ -689,7 +691,7 @@ public GeoRect[] getInsideBoundingBox() {
689691
* At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form "_geoloc":{"lat":48.853409, "lng":2.348800} or
690692
* "_geoloc":[{"lat":48.853409, "lng":2.348800},{"lat":48.547456, "lng":2.972075}] if you have several geo-locations in your record).
691693
*/
692-
public @NonNull Query setInsidePolygon(LatLng... points) {
694+
public @NonNull Query setInsidePolygon(@Nullable LatLng... points) {
693695
if (points == null) {
694696
set(KEY_INSIDE_POLYGON, null);
695697
} else if (points.length < 3) {
@@ -709,7 +711,7 @@ public GeoRect[] getInsideBoundingBox() {
709711
return this;
710712
}
711713

712-
public LatLng[] getInsidePolygon() {
714+
public @Nullable LatLng[] getInsidePolygon() {
713715
try {
714716
String value = get(KEY_INSIDE_POLYGON);
715717
if (value != null) {
@@ -803,11 +805,21 @@ public Integer getMinWordSizefor2Typos() {
803805

804806
private static final String KEY_NUMERIC_FILTERS = "numericFilters";
805807

808+
/**
809+
* Set the <b>deprecated</b> {@code numericFilters} parameter.
810+
*
811+
* @deprecated Use {@link Query#setFilters(String)} instead.
812+
*/
806813
public @NonNull Query setNumericFilters(JSONArray filters) {
807814
return set(KEY_NUMERIC_FILTERS, filters);
808815
}
809816

810-
public JSONArray getNumericFilters() {
817+
/**
818+
* Get the value of <b>deprecated</b> {@code facetFilters} parameter.
819+
*
820+
* @deprecated Use {@link Query#getFilters()} instead.
821+
*/
822+
public @Nullable JSONArray getNumericFilters() {
811823
try {
812824
String value = get(KEY_NUMERIC_FILTERS);
813825
if (value != null) {
@@ -859,7 +871,7 @@ public Integer getPage() {
859871
return set(KEY_QUERY, query);
860872
}
861873

862-
public String getQuery() {
874+
public @Nullable String getQuery() {
863875
return get(KEY_QUERY);
864876
}
865877

@@ -868,7 +880,7 @@ public String getQuery() {
868880
/**
869881
* Select how the query words are interpreted:
870882
*/
871-
public @NonNull Query setQueryType(QueryType type) {
883+
public @NonNull Query setQueryType(@Nullable QueryType type) {
872884
if (type == null) {
873885
set(KEY_QUERY_TYPE, null);
874886
} else {
@@ -887,7 +899,7 @@ public String getQuery() {
887899
return this;
888900
}
889901

890-
public QueryType getQueryType()
902+
public @Nullable QueryType getQueryType()
891903
{
892904
String value = get(KEY_QUERY_TYPE);
893905
if (value != null) {
@@ -919,7 +931,7 @@ public QueryType getQueryType()
919931
throw new AlgoliaException("removeStopWords should be a Boolean or a String.");
920932
}
921933

922-
public Object getRemoveStopWords() {
934+
public @Nullable Object getRemoveStopWords() {
923935
final String value = get(KEY_REMOVE_STOP_WORDS);
924936
if (value == null) {
925937
return null;
@@ -936,7 +948,7 @@ public Object getRemoveStopWords() {
936948
/**
937949
* Select the strategy to adopt when a query does not return any result.
938950
*/
939-
public @NonNull Query setRemoveWordsIfNoResults(RemoveWordsIfNoResults type) {
951+
public @NonNull Query setRemoveWordsIfNoResults(@Nullable RemoveWordsIfNoResults type) {
940952
if (type == null) {
941953
set(KEY_REMOVE_WORDS_IF_NO_RESULT, null);
942954
} else {
@@ -958,7 +970,7 @@ public Object getRemoveStopWords() {
958970
return this;
959971
}
960972

961-
public RemoveWordsIfNoResults getRemoveWordsIfNoResults()
973+
public @Nullable RemoveWordsIfNoResults getRemoveWordsIfNoResults()
962974
{
963975
String value = get(KEY_REMOVE_WORDS_IF_NO_RESULT);
964976
if (value != null) {
@@ -1021,7 +1033,7 @@ public String[] getRestrictSearchableAttributes()
10211033
return set(KEY_SNIPPET_ELLIPSIS_TEXT, snippetEllipsisText);
10221034
}
10231035

1024-
public String getSnippetEllipsisText() {
1036+
public @Nullable String getSnippetEllipsisText() {
10251037
return get(KEY_SNIPPET_ELLIPSIS_TEXT);
10261038
}
10271039

@@ -1046,7 +1058,7 @@ public Boolean getSynonyms() {
10461058
return set(KEY_TAG_FILTERS, tagFilters);
10471059
}
10481060

1049-
public JSONArray getTagFilters() {
1061+
public @Nullable JSONArray getTagFilters() {
10501062
try {
10511063
String value = get(KEY_TAG_FILTERS);
10521064
if (value != null) {
@@ -1061,7 +1073,7 @@ public JSONArray getTagFilters() {
10611073

10621074
private static final String KEY_TYPO_TOLERANCE = "typoTolerance";
10631075

1064-
public @NonNull Query setTypoTolerance(TypoTolerance type) {
1076+
public @NonNull Query setTypoTolerance(@Nullable TypoTolerance type) {
10651077
if (type == null) {
10661078
set(KEY_TYPO_TOLERANCE, null);
10671079
} else {
@@ -1083,7 +1095,7 @@ public JSONArray getTagFilters() {
10831095
return this;
10841096
}
10851097

1086-
public TypoTolerance getTypoTolerance()
1098+
public @Nullable TypoTolerance getTypoTolerance()
10871099
{
10881100
String value = get(KEY_TYPO_TOLERANCE);
10891101
if (value != null) {
@@ -1103,7 +1115,7 @@ public TypoTolerance getTypoTolerance()
11031115

11041116
private static final String KEY_EXACT_ON_SINGLE_WORD_QUERY = "exactOnSingleWordQuery";
11051117

1106-
public @NonNull Query setExactOnSingleWordQuery(ExactOnSingleWordQuery type) {
1118+
public @NonNull Query setExactOnSingleWordQuery(@Nullable ExactOnSingleWordQuery type) {
11071119
if (type == null) {
11081120
set(KEY_EXACT_ON_SINGLE_WORD_QUERY, null);
11091121
} else {
@@ -1122,7 +1134,7 @@ public TypoTolerance getTypoTolerance()
11221134
return this;
11231135
}
11241136

1125-
public ExactOnSingleWordQuery getExactOnSingleWordQuery()
1137+
public @Nullable ExactOnSingleWordQuery getExactOnSingleWordQuery()
11261138
{
11271139
String value = get(KEY_EXACT_ON_SINGLE_WORD_QUERY);
11281140
if (value != null) {
@@ -1140,7 +1152,7 @@ public ExactOnSingleWordQuery getExactOnSingleWordQuery()
11401152

11411153
private static final String KEY_ALTERNATIVES_AS_EXACT = "alternativesAsExact";
11421154

1143-
public @NonNull Query setAlternativesAsExact(AlternativesAsExact[] types) {
1155+
public @NonNull Query setAlternativesAsExact(@Nullable AlternativesAsExact[] types) {
11441156
if (types == null) {
11451157
set(KEY_ALTERNATIVES_AS_EXACT, null);
11461158
} else {
@@ -1164,7 +1176,7 @@ public ExactOnSingleWordQuery getExactOnSingleWordQuery()
11641176
return this;
11651177
}
11661178

1167-
public AlternativesAsExact[] getAlternativesAsExact()
1179+
public @Nullable AlternativesAsExact[] getAlternativesAsExact()
11681180
{
11691181
String alternativesStr = get(KEY_ALTERNATIVES_AS_EXACT);
11701182
if (alternativesStr == null) {

0 commit comments

Comments
 (0)