| 14792 |
manas |
1 |
/**
|
|
|
2 |
* Copyright 2010-present Facebook.
|
|
|
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.facebook.internal;
|
|
|
18 |
|
|
|
19 |
import java.util.Collection;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* com.facebook.internal is solely for the use of other packages within the Facebook SDK for Android. Use of
|
|
|
23 |
* any of the classes in this package is unsupported, and they may be modified or removed without warning at
|
|
|
24 |
* any time.
|
|
|
25 |
*/
|
|
|
26 |
public final class Validate {
|
|
|
27 |
public static void notNull(Object arg, String name) {
|
|
|
28 |
if (arg == null) {
|
|
|
29 |
throw new NullPointerException("Argument '" + name + "' cannot be null");
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public static <T> void notEmpty(Collection<T> container, String name) {
|
|
|
34 |
if (container.isEmpty()) {
|
|
|
35 |
throw new IllegalArgumentException("Container '" + name + "' cannot be empty");
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public static <T> void containsNoNulls(Collection<T> container, String name) {
|
|
|
40 |
Validate.notNull(container, name);
|
|
|
41 |
for (T item : container) {
|
|
|
42 |
if (item == null) {
|
|
|
43 |
throw new NullPointerException("Container '" + name + "' cannot contain null values");
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public static void containsNoNullOrEmpty(Collection<String> container, String name) {
|
|
|
49 |
Validate.notNull(container, name);
|
|
|
50 |
for (String item : container) {
|
|
|
51 |
if (item == null) {
|
|
|
52 |
throw new NullPointerException("Container '" + name + "' cannot contain null values");
|
|
|
53 |
}
|
|
|
54 |
if (item.length() == 0) {
|
|
|
55 |
throw new IllegalArgumentException("Container '" + name + "' cannot contain empty values");
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public static <T> void notEmptyAndContainsNoNulls(Collection<T> container, String name) {
|
|
|
61 |
Validate.containsNoNulls(container, name);
|
|
|
62 |
Validate.notEmpty(container, name);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public static void notNullOrEmpty(String arg, String name) {
|
|
|
66 |
if (Utility.isNullOrEmpty(arg)) {
|
|
|
67 |
throw new IllegalArgumentException("Argument '" + name + "' cannot be null or empty");
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public static void oneOf(Object arg, String name, Object... values) {
|
|
|
72 |
for (Object value : values) {
|
|
|
73 |
if (value != null) {
|
|
|
74 |
if (value.equals(arg)) {
|
|
|
75 |
return;
|
|
|
76 |
}
|
|
|
77 |
} else {
|
|
|
78 |
if (arg == null) {
|
|
|
79 |
return;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
throw new IllegalArgumentException("Argument '" + name + "' was not one of the allowed values");
|
|
|
84 |
}
|
|
|
85 |
}
|