DatabaseUtilsCompat.java

/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.core.database;

import android.text.TextUtils;

/**
 * Helper for accessing features in {@link android.database.DatabaseUtils}.
 *
 * @deprecated Use {@link android.database.DatabaseUtils} directly.
 */
@Deprecated
public final class DatabaseUtilsCompat {

    private DatabaseUtilsCompat() {
        /* Hide constructor */
    }

    /**
     * Concatenates two SQL WHERE clauses, handling empty or null values.
     *
     * @deprecated Use {@link android.database.DatabaseUtils#concatenateWhere(String, String)}
     * directly.
     */
    @Deprecated
    public static String concatenateWhere(String a, String b) {
        if (TextUtils.isEmpty(a)) {
            return b;
        }
        if (TextUtils.isEmpty(b)) {
            return a;
        }

        return "(" + a + ") AND (" + b + ")";
    }

    /**
     * Appends one set of selection args to another. This is useful when adding a selection
     * argument to a user provided set.
     *
     * @deprecated Use
     * {@link android.database.DatabaseUtils#appendSelectionArgs(String[], String[])} directly.
     */
    @Deprecated
    public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
        if (originalValues == null || originalValues.length == 0) {
            return newValues;
        }
        String[] result = new String[originalValues.length + newValues.length ];
        System.arraycopy(originalValues, 0, result, 0, originalValues.length);
        System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
        return result;
    }
}