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