1/*
2 * Copyright (C) 2011 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
17package android.support.v4.database;
18
19import android.text.TextUtils;
20
21/**
22 * Helper for accessing features in {@link android.database.DatabaseUtils}
23 * introduced after API level 4 in a backwards compatible fashion.
24 */
25public class DatabaseUtilsCompat {
26
27    private DatabaseUtilsCompat() {
28        /* Hide constructor */
29    }
30
31    /**
32     * Concatenates two SQL WHERE clauses, handling empty or null values.
33     */
34    public static String concatenateWhere(String a, String b) {
35        if (TextUtils.isEmpty(a)) {
36            return b;
37        }
38        if (TextUtils.isEmpty(b)) {
39            return a;
40        }
41
42        return "(" + a + ") AND (" + b + ")";
43    }
44
45    /**
46     * Appends one set of selection args to another. This is useful when adding a selection
47     * argument to a user provided set.
48     */
49    public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
50        if (originalValues == null || originalValues.length == 0) {
51            return newValues;
52        }
53        String[] result = new String[originalValues.length + newValues.length ];
54        System.arraycopy(originalValues, 0, result, 0, originalValues.length);
55        System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
56        return result;
57    }
58}
59