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

com.doyospy.core.lang.Assert Maven / Gradle / Ivy

Go to download

Doyospy是一个小而全的基于SpringBoot的java工具类库,通过静态方法封装,方便开发者使用,降低学习成本并提升工作效率。

The newest version!
package com.doyospy.core.lang;

import java.util.function.Supplier;

/**
 * 断言工具类
 * PS:用于抛出在检查时为真的断言,断言某些对象或值是否符合规定,否则抛出异常,经常用于做变量检查
 * @author  Robin
 */
public class Assert {
    private static final String TEMPLATE_VALUE_MUST_BE_BETWEEN_AND = "The value must be between {} and {}.";

    /**
     * 断言是否为真,如果为 {@code false} 抛出给定的异常
* *
     * Assert.isTrue(i > 0, IllegalArgumentException::new);
     * 
* * @param 异常类型 * @param expression 布尔值 * @param supplier 指定断言不通过时抛出的异常 * @throws X if expression is {@code false} */ public static void isTrue(boolean expression, Supplier supplier) throws X { if (!expression) { throw supplier.get(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy