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