|
17 | 17 | import androidx.annotation.NonNull;
|
18 | 18 | import androidx.annotation.Nullable;
|
19 | 19 | import androidx.annotation.RestrictTo;
|
20 |
| -import com.google.firebase.firestore.core.CompositeFilter; |
21 | 20 | import com.google.firebase.firestore.core.FieldFilter.Operator;
|
22 | 21 | import java.util.Arrays;
|
23 | 22 | import java.util.List;
|
24 | 23 |
|
| 24 | +// TODO(orquery): Remove the `hide` and scope annotations. |
25 | 25 | /** @hide */
|
26 | 26 | @RestrictTo(RestrictTo.Scope.LIBRARY)
|
| 27 | +/** |
| 28 | + * A {@code Filter} represents a restriction on one or more field values and can be used to refine |
| 29 | + * the results of a {@code Query}. |
| 30 | + */ |
27 | 31 | public class Filter {
|
28 | 32 | static class UnaryFilter extends Filter {
|
29 | 33 | private final FieldPath field;
|
@@ -70,112 +74,274 @@ public com.google.firebase.firestore.core.CompositeFilter.Operator getOperator()
|
70 | 74 | }
|
71 | 75 | }
|
72 | 76 |
|
| 77 | + /** |
| 78 | + * Creates a new filter for checking that the given field is equal to the given value. |
| 79 | + * |
| 80 | + * @param field The field used for the filter. |
| 81 | + * @param value The value used for the filter. |
| 82 | + * @return The newly created filter. |
| 83 | + */ |
73 | 84 | @NonNull
|
74 | 85 | public static Filter equalTo(@NonNull String field, @Nullable Object value) {
|
75 | 86 | return equalTo(FieldPath.fromDotSeparatedPath(field), value);
|
76 | 87 | }
|
77 | 88 |
|
| 89 | + /** |
| 90 | + * Creates a new filter for checking that the given field is equal to the given value. |
| 91 | + * |
| 92 | + * @param fieldPath The field path used for the filter. |
| 93 | + * @param value The value used for the filter. |
| 94 | + * @return The newly created filter. |
| 95 | + */ |
78 | 96 | @NonNull
|
79 | 97 | public static Filter equalTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
80 | 98 | return new UnaryFilter(fieldPath, Operator.EQUAL, value);
|
81 | 99 | }
|
82 | 100 |
|
| 101 | + /** |
| 102 | + * Creates a new filter for checking that the given field is not equal to the given value. |
| 103 | + * |
| 104 | + * @param field The field used for the filter. |
| 105 | + * @param value The value used for the filter. |
| 106 | + * @return The newly created filter. |
| 107 | + */ |
83 | 108 | @NonNull
|
84 | 109 | public static Filter notEqualTo(@NonNull String field, @Nullable Object value) {
|
85 | 110 | return notEqualTo(FieldPath.fromDotSeparatedPath(field), value);
|
86 | 111 | }
|
87 | 112 |
|
| 113 | + /** |
| 114 | + * Creates a new filter for checking that the given field is not equal to the given value. |
| 115 | + * |
| 116 | + * @param fieldPath The field path used for the filter. |
| 117 | + * @param value The value used for the filter. |
| 118 | + * @return The newly created filter. |
| 119 | + */ |
88 | 120 | @NonNull
|
89 | 121 | public static Filter notEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
90 | 122 | return new UnaryFilter(fieldPath, Operator.NOT_EQUAL, value);
|
91 | 123 | }
|
92 | 124 |
|
| 125 | + /** |
| 126 | + * Creates a new filter for checking that the given field is greater than the given value. |
| 127 | + * |
| 128 | + * @param field The field used for the filter. |
| 129 | + * @param value The value used for the filter. |
| 130 | + * @return The newly created filter. |
| 131 | + */ |
93 | 132 | @NonNull
|
94 | 133 | public static Filter greaterThan(@NonNull String field, @Nullable Object value) {
|
95 | 134 | return greaterThan(FieldPath.fromDotSeparatedPath(field), value);
|
96 | 135 | }
|
97 | 136 |
|
| 137 | + /** |
| 138 | + * Creates a new filter for checking that the given field is greater than the given value. |
| 139 | + * |
| 140 | + * @param fieldPath The field path used for the filter. |
| 141 | + * @param value The value used for the filter. |
| 142 | + * @return The newly created filter. |
| 143 | + */ |
98 | 144 | @NonNull
|
99 | 145 | public static Filter greaterThan(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
100 | 146 | return new UnaryFilter(fieldPath, Operator.GREATER_THAN, value);
|
101 | 147 | }
|
102 | 148 |
|
| 149 | + /** |
| 150 | + * Creates a new filter for checking that the given field is greater than or equal to the given |
| 151 | + * value. |
| 152 | + * |
| 153 | + * @param field The field used for the filter. |
| 154 | + * @param value The value used for the filter. |
| 155 | + * @return The newly created filter. |
| 156 | + */ |
103 | 157 | @NonNull
|
104 | 158 | public static Filter greaterThanOrEqualTo(@NonNull String field, @Nullable Object value) {
|
105 | 159 | return greaterThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value);
|
106 | 160 | }
|
107 | 161 |
|
| 162 | + /** |
| 163 | + * Creates a new filter for checking that the given field is greater than or equal to the given |
| 164 | + * value. |
| 165 | + * |
| 166 | + * @param fieldPath The field path used for the filter. |
| 167 | + * @param value The value used for the filter. |
| 168 | + * @return The newly created filter. |
| 169 | + */ |
108 | 170 | @NonNull
|
109 | 171 | public static Filter greaterThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
110 | 172 | return new UnaryFilter(fieldPath, Operator.GREATER_THAN_OR_EQUAL, value);
|
111 | 173 | }
|
112 | 174 |
|
| 175 | + /** |
| 176 | + * Creates a new filter for checking that the given field is less than the given value. |
| 177 | + * |
| 178 | + * @param field The field used for the filter. |
| 179 | + * @param value The value used for the filter. |
| 180 | + * @return The newly created filter. |
| 181 | + */ |
113 | 182 | @NonNull
|
114 | 183 | public static Filter lessThan(@NonNull String field, @Nullable Object value) {
|
115 | 184 | return lessThan(FieldPath.fromDotSeparatedPath(field), value);
|
116 | 185 | }
|
117 | 186 |
|
| 187 | + /** |
| 188 | + * Creates a new filter for checking that the given field is less than the given value. |
| 189 | + * |
| 190 | + * @param fieldPath The field path used for the filter. |
| 191 | + * @param value The value used for the filter. |
| 192 | + * @return The newly created filter. |
| 193 | + */ |
118 | 194 | @NonNull
|
119 | 195 | public static Filter lessThan(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
120 | 196 | return new UnaryFilter(fieldPath, Operator.LESS_THAN, value);
|
121 | 197 | }
|
122 | 198 |
|
| 199 | + /** |
| 200 | + * Creates a new filter for checking that the given field is less than or equal to the given |
| 201 | + * value. |
| 202 | + * |
| 203 | + * @param field The field used for the filter. |
| 204 | + * @param value The value used for the filter. |
| 205 | + * @return The newly created filter. |
| 206 | + */ |
123 | 207 | @NonNull
|
124 | 208 | public static Filter lessThanOrEqualTo(@NonNull String field, @Nullable Object value) {
|
125 | 209 | return lessThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value);
|
126 | 210 | }
|
127 | 211 |
|
| 212 | + /** |
| 213 | + * Creates a new filter for checking that the given field is less than or equal to the given |
| 214 | + * value. |
| 215 | + * |
| 216 | + * @param fieldPath The field path used for the filter. |
| 217 | + * @param value The value used for the filter. |
| 218 | + * @return The newly created filter. |
| 219 | + */ |
128 | 220 | @NonNull
|
129 | 221 | public static Filter lessThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
130 | 222 | return new UnaryFilter(fieldPath, Operator.LESS_THAN_OR_EQUAL, value);
|
131 | 223 | }
|
132 | 224 |
|
| 225 | + /** |
| 226 | + * Creates a new filter for checking that the given array field contains the given value. |
| 227 | + * |
| 228 | + * @param field The field used for the filter. |
| 229 | + * @param value The value used for the filter. |
| 230 | + * @return The newly created filter. |
| 231 | + */ |
133 | 232 | @NonNull
|
134 | 233 | public static Filter arrayContains(@NonNull String field, @Nullable Object value) {
|
135 | 234 | return arrayContains(FieldPath.fromDotSeparatedPath(field), value);
|
136 | 235 | }
|
137 | 236 |
|
| 237 | + /** |
| 238 | + * Creates a new filter for checking that the given array field contains the given value. |
| 239 | + * |
| 240 | + * @param fieldPath The field path used for the filter. |
| 241 | + * @param value The value used for the filter. |
| 242 | + * @return The newly created filter. |
| 243 | + */ |
138 | 244 | @NonNull
|
139 | 245 | public static Filter arrayContains(@NonNull FieldPath fieldPath, @Nullable Object value) {
|
140 | 246 | return new UnaryFilter(fieldPath, Operator.ARRAY_CONTAINS, value);
|
141 | 247 | }
|
142 | 248 |
|
| 249 | + /** |
| 250 | + * Creates a new filter for checking that the given array field contains any of the given values. |
| 251 | + * |
| 252 | + * @param field The field used for the filter. |
| 253 | + * @param values The list of values used for the filter. |
| 254 | + * @return The newly created filter. |
| 255 | + */ |
143 | 256 | @NonNull
|
144 |
| - public static Filter arrayContainsAny(@NonNull String field, @Nullable Object value) { |
145 |
| - return arrayContainsAny(FieldPath.fromDotSeparatedPath(field), value); |
| 257 | + public static Filter arrayContainsAny( |
| 258 | + @NonNull String field, @NonNull List<? extends Object> values) { |
| 259 | + return arrayContainsAny(FieldPath.fromDotSeparatedPath(field), values); |
146 | 260 | }
|
147 | 261 |
|
| 262 | + /** |
| 263 | + * Creates a new filter for checking that the given array field contains any of the given values. |
| 264 | + * |
| 265 | + * @param fieldPath The field path used for the filter. |
| 266 | + * @param values The list of values used for the filter. |
| 267 | + * @return The newly created filter. |
| 268 | + */ |
148 | 269 | @NonNull
|
149 |
| - public static Filter arrayContainsAny(@NonNull FieldPath fieldPath, @Nullable Object value) { |
150 |
| - return new UnaryFilter(fieldPath, Operator.ARRAY_CONTAINS_ANY, value); |
| 270 | + public static Filter arrayContainsAny( |
| 271 | + @NonNull FieldPath fieldPath, @NonNull List<? extends Object> values) { |
| 272 | + return new UnaryFilter(fieldPath, Operator.ARRAY_CONTAINS_ANY, values); |
151 | 273 | }
|
152 | 274 |
|
| 275 | + /** |
| 276 | + * Creates a new filter for checking that the given field equals any of the given values. |
| 277 | + * |
| 278 | + * @param field The field used for the filter. |
| 279 | + * @param values The list of values used for the filter. |
| 280 | + * @return The newly created filter. |
| 281 | + */ |
153 | 282 | @NonNull
|
154 |
| - public static Filter inArray(@NonNull String field, @Nullable Object value) { |
155 |
| - return inArray(FieldPath.fromDotSeparatedPath(field), value); |
| 283 | + public static Filter inArray(@NonNull String field, @NonNull List<? extends Object> values) { |
| 284 | + return inArray(FieldPath.fromDotSeparatedPath(field), values); |
156 | 285 | }
|
157 | 286 |
|
| 287 | + /** |
| 288 | + * Creates a new filter for checking that the given field equals any of the given values. |
| 289 | + * |
| 290 | + * @param fieldPath The field path used for the filter. |
| 291 | + * @param values The list of values used for the filter. |
| 292 | + * @return The newly created filter. |
| 293 | + */ |
158 | 294 | @NonNull
|
159 |
| - public static Filter inArray(@NonNull FieldPath fieldPath, @Nullable Object value) { |
160 |
| - return new UnaryFilter(fieldPath, Operator.IN, value); |
| 295 | + public static Filter inArray( |
| 296 | + @NonNull FieldPath fieldPath, @NonNull List<? extends Object> values) { |
| 297 | + return new UnaryFilter(fieldPath, Operator.IN, values); |
161 | 298 | }
|
162 | 299 |
|
| 300 | + /** |
| 301 | + * Creates a new filter for checking that the given field does not equal any of the given values. |
| 302 | + * |
| 303 | + * @param field The field path used for the filter. |
| 304 | + * @param values The list of values used for the filter. |
| 305 | + * @return The newly created filter. |
| 306 | + */ |
163 | 307 | @NonNull
|
164 |
| - public static Filter notInArray(@NonNull String field, @Nullable Object value) { |
165 |
| - return notInArray(FieldPath.fromDotSeparatedPath(field), value); |
| 308 | + public static Filter notInArray(@NonNull String field, @NonNull List<? extends Object> values) { |
| 309 | + return notInArray(FieldPath.fromDotSeparatedPath(field), values); |
166 | 310 | }
|
167 | 311 |
|
| 312 | + /** |
| 313 | + * Creates a new filter for checking that the given field does not equal any of the given values. |
| 314 | + * |
| 315 | + * @param fieldPath The field path used for the filter. |
| 316 | + * @param values The list of values used for the filter. |
| 317 | + * @return The newly created filter. |
| 318 | + */ |
168 | 319 | @NonNull
|
169 |
| - public static Filter notInArray(@NonNull FieldPath fieldPath, @Nullable Object value) { |
170 |
| - return new UnaryFilter(fieldPath, Operator.NOT_IN, value); |
| 320 | + public static Filter notInArray( |
| 321 | + @NonNull FieldPath fieldPath, @NonNull List<? extends Object> values) { |
| 322 | + return new UnaryFilter(fieldPath, Operator.NOT_IN, values); |
171 | 323 | }
|
172 | 324 |
|
| 325 | + /** |
| 326 | + * Creates a new filter that is a disjunction of the given filters. A disjunction filter includes |
| 327 | + * a document if it satisfies <em>any</em> of the given filters. |
| 328 | + * |
| 329 | + * @param filters The list of filters to perform a disjunction for. |
| 330 | + * @return The newly created filter. |
| 331 | + */ |
173 | 332 | @NonNull
|
174 | 333 | public static Filter or(Filter... filters) {
|
175 | 334 | return new CompositeFilter(
|
176 | 335 | Arrays.asList(filters), com.google.firebase.firestore.core.CompositeFilter.Operator.OR);
|
177 | 336 | }
|
178 | 337 |
|
| 338 | + /** |
| 339 | + * Creates a new filter that is a conjunction of the given filters. A conjunction filter includes |
| 340 | + * a document if it satisfies <em>all</em> of the given filters. |
| 341 | + * |
| 342 | + * @param filters The list of filters to perform a disjunction for. |
| 343 | + * @return The newly created filter. |
| 344 | + */ |
179 | 345 | @NonNull
|
180 | 346 | public static Filter and(Filter... filters) {
|
181 | 347 | return new CompositeFilter(
|
|
0 commit comments