All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ehcache.impl.internal.classes.commonslang.Validate Maven / Gradle / Ivy

There is a newer version: 3.10.8
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

/*
 * This is a modified version of the original Apache class.  It has had unused
 * members removed.
 */
package org.ehcache.impl.internal.classes.commonslang;

/**
 * 

This class assists in validating arguments. The validation methods are * based along the following principles: *

    *
  • An invalid {@code null} argument causes a {@link NullPointerException}.
  • *
  • A non-{@code null} argument causes an {@link IllegalArgumentException}.
  • *
  • An invalid index into an array/collection/map/string causes an {@link IndexOutOfBoundsException}.
  • *
* *

All exceptions messages are * format strings * as defined by the Java platform. For example: * *

 * Validate.isTrue(i > 0, "The value must be greater than zero: %d", i);
 * Validate.notNull(surname, "The surname must not be %s", null);
 * 
* *

#ThreadSafe# * @see java.lang.String#format(String, Object...) * @since 2.0 */ public class Validate { /** * Constructor. This class should not normally be instantiated. */ public Validate() { super(); } /** *

Validate that the specified argument is not {@code null}; * otherwise throwing an exception with the specified message. * *

Validate.notNull(myObject, "The object must not be null");
* * @param the object type * @param object the object to check * @param message the {@link String#format(String, Object...)} exception message if invalid, not null * @param values the optional values for the formatted exception message * @return the validated object (never {@code null} for method chaining) * @throws NullPointerException if the object is {@code null} */ public static T notNull(final T object, final String message, final Object... values) { if (object == null) { throw new NullPointerException(String.format(message, values)); } return object; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy