com.facebook.internal.Validate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of facebook-android-api Show documentation
Show all versions of facebook-android-api Show documentation
The Mavenized Facebook Android api available in Maven Central repo.
/**
* Copyright 2010-present Facebook.
*
* 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 com.facebook.internal;
import java.util.Collection;
/**
* com.facebook.internal is solely for the use of other packages within the Facebook SDK for Android. Use of
* any of the classes in this package is unsupported, and they may be modified or removed without warning at
* any time.
*/
public final class Validate {
public static void notNull(Object arg, String name) {
if (arg == null) {
throw new NullPointerException("Argument '" + name + "' cannot be null");
}
}
public static void notEmpty(Collection container, String name) {
if (container.isEmpty()) {
throw new IllegalArgumentException("Container '" + name + "' cannot be empty");
}
}
public static void containsNoNulls(Collection container, String name) {
Validate.notNull(container, name);
for (T item : container) {
if (item == null) {
throw new NullPointerException("Container '" + name + "' cannot contain null values");
}
}
}
public static void containsNoNullOrEmpty(Collection container, String name) {
Validate.notNull(container, name);
for (String item : container) {
if (item == null) {
throw new NullPointerException("Container '" + name + "' cannot contain null values");
}
if (item.length() == 0) {
throw new IllegalArgumentException("Container '" + name + "' cannot contain empty values");
}
}
}
public static void notEmptyAndContainsNoNulls(Collection container, String name) {
Validate.containsNoNulls(container, name);
Validate.notEmpty(container, name);
}
public static void notNullOrEmpty(String arg, String name) {
if (Utility.isNullOrEmpty(arg)) {
throw new IllegalArgumentException("Argument '" + name + "' cannot be null or empty");
}
}
public static void oneOf(Object arg, String name, Object... values) {
for (Object value : values) {
if (value != null) {
if (value.equals(arg)) {
return;
}
} else {
if (arg == null) {
return;
}
}
}
throw new IllegalArgumentException("Argument '" + name + "' was not one of the allowed values");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy