1/*
2 * Copyright (C) 2015 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.provider;
18
19import android.support.annotation.Nullable;
20import android.support.annotation.RestrictTo;
21import android.text.TextUtils;
22
23import java.util.Collection;
24
25import static android.support.annotation.RestrictTo.Scope.GROUP_ID;
26
27/**
28 * Simple static methods to be called at the start of your own methods to verify
29 * correct arguments and state.
30 * @hide
31 */
32@RestrictTo(GROUP_ID)
33final class Preconditions {
34    static void checkArgument(boolean expression, String message) {
35        if (!expression) {
36            throw new IllegalArgumentException(message);
37        }
38    }
39
40    static void checkArgumentNotNull(Object object, String message) {
41        if (object == null) {
42            throw new IllegalArgumentException(message);
43        }
44    }
45
46    static void checkArgumentEquals(String expected, @Nullable String actual, String message) {
47        if (!TextUtils.equals(expected, actual)) {
48            throw new IllegalArgumentException(String.format(message, String.valueOf(expected),
49                    String.valueOf(actual)));
50        }
51    }
52
53    static void checkState(boolean expression, String message) {
54        if (!expression) {
55            throw new IllegalStateException(message);
56        }
57    }
58}
59