Java tutorial
/* * Copyright 2013-2016 the original author or authors. * * 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 gov.nyc.doitt.gis.geoclient.util; import java.util.Collection; /** * Copy of methods in org.springframework.util.Assert class to allow this * framework to not depend on Spring. * * @author mlipper * */ public abstract class Assert { /** * Assert that an object is not <code>null</code> . * <pre class="code">Assert.notNull(clazz, "The class must not be null");</pre> * @param object the object to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the object is <code>null</code> */ public static void notNull(Object object, String message) { if (object == null) { throw new IllegalArgumentException(message); } } /** * Assert that an object is not <code>null</code> . * <pre class="code">Assert.notNull(clazz);</pre> * @param object the object to check * @throws IllegalArgumentException if the object is <code>null</code> */ public static void notNull(Object object) { notNull(object, "[Assertion failed] - this argument is required; it must not be null"); } /** * Assert that a collection has elements; that is, it must not be * <code>null</code> and must have at least one element. * <pre class="code">Assert.notEmpty(collection, "Collection must have elements");</pre> * @param collection the collection to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements */ public static void notEmpty(@SuppressWarnings("rawtypes") Collection collection, String message) { if (collection == null || collection.isEmpty()) { throw new IllegalArgumentException(message); } } }