• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.queryable;
18 
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.stream.Collectors;
22 
23 public interface Queryable {
24     /**
25      * Generate a string representation of the query.
26      *
27      * <p>For example, if {@code fieldName} was age, we might generate "age > 5, age < 10"
28      */
describeQuery(String fieldName)29     String describeQuery(String fieldName);
30 
31 
32     /**
33      * Join sub-parts of a query for use in {@link #describeQuery(String)}.
34      *
35      * <p>Queries which are not set should be null.
36      */
joinQueryStrings(String... queryStrings)37     static String joinQueryStrings(String... queryStrings) {
38         return Arrays.stream(queryStrings).filter(i -> i != null && !i.isEmpty())
39                 .collect(Collectors.joining(", "));
40     }
41 
42     /**
43      * Join sub-parts of a query for use in {@link #describeQuery(String)}.
44      *
45      * <p>Queries which are not set should be null.
46      */
joinQueryStrings(Collection<String> queryStrings)47     static String joinQueryStrings(Collection<String> queryStrings) {
48         return queryStrings.stream().filter(i -> i != null && !i.isEmpty())
49                 .collect(Collectors.joining(", "));
50     }
51 }
52