Java Formatter Usage validateCondition(boolean condition, String messageFormat, Object... messageArgs)

Here you can find the source of validateCondition(boolean condition, String messageFormat, Object... messageArgs)

Description

Validates that a condition is true .

License

Apache License

Parameter

Parameter Description
condition The condition to validate
messageFormat The java.util.Formatter format string of the message to be passed to the exception that is thrown if validation fails
messageArgs The substitution arguments for the format string

Exception

Parameter Description
IllegalArgumentException If the validation fails

Declaration

public static void validateCondition(boolean condition, String messageFormat, Object... messageArgs) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2012 Eric McIntyre//from  www. j av  a 2 s  .c o  m
 * 
 * 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.
 ******************************************************************************/

public class Main {
    /**
     * Validates that a condition is {@code true}. Useful for general and concise comparisons.
     * 
     * @param condition
     *            The condition to validate
     * @param messageFormat
     *            The {@linkplain java.util.Formatter format string} of the message to be passed to the exception that
     *            is thrown if validation fails
     * @param messageArgs
     *            The substitution arguments for the format string
     * @throws IllegalArgumentException
     *             If the validation fails
     */
    public static void validateCondition(boolean condition, String messageFormat, Object... messageArgs) {

        if (!condition) {
            throw new IllegalArgumentException(String.format(messageFormat, messageArgs));
        }
    }
}

Related

  1. substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj)
  2. toHexString(final byte[] data)
  3. toReadableSize(long bytes)
  4. toTwoDigit(double f)
  5. toUUIDFormat(byte[] bytes)
  6. warnfErr(String format, String... params)