Class MGL_Asserts

java.lang.Object
tech.mgl.core.utils.MGL_Asserts

public class MGL_Asserts extends Object
Name: MGL_Asserts Package: tech.mgl.frame.common Description: ${DESC} Author: bbd12 www.mgl.tech Email: hotpot@mgl.tech Date: 2017/4/26 Version: V1.0
  • Constructor Details

    • MGL_Asserts

      public MGL_Asserts()
  • Method Details

    • notBlank

      public static void notBlank(String text, String message)
      没有值则抛出异常
      Parameters:
      text -
      message -
    • state

      public static void state(boolean expression, String message)
      反状态
      Parameters:
      expression -
      message -
    • notEmpty

      public static <T> T notEmpty(T object, String message)
      判断对象是否为空
      Type Parameters:
      T -
      Parameters:
      object -
      message -
      Returns:
    • notNull

      public static <T, X extends Throwable> T notNull(T object, Supplier<X> errorSupplier) throws X
      断言对象是否不为null ,如果为null 抛出指定类型异常 并使用指定的函数获取错误信息返回
       Assert.notNull(clazz, ()->{
            // to query relation message
            return new IllegalArgumentException("relation message to return");
        });
       
      Type Parameters:
      T - 被检查对象泛型类型
      X - 异常类型
      Parameters:
      object - 被检查对象
      errorSupplier - 错误抛出异常附带的消息生产接口
      Returns:
      被检查后的对象
      Throws:
      X - if the object is null
      Since:
      5.4.5
    • notNull

      public static <T> T notNull(T object, String errorMsgTemplate, Object... params) throws IllegalArgumentException
      断言对象是否不为null ,如果为null 抛出IllegalArgumentException 异常 Assert that an object is not null .
       Assert.notNull(clazz, "The class must not be null");
       
      Type Parameters:
      T - 被检查对象泛型类型
      Parameters:
      object - 被检查对象
      errorMsgTemplate - 错误消息模板,变量使用{}表示
      params - 参数
      Returns:
      被检查后的对象
      Throws:
      IllegalArgumentException - if the object is null
    • notNull

      public static <T> T notNull(T object) throws IllegalArgumentException
      断言对象是否不为null ,如果为null 抛出IllegalArgumentException 异常
       Assert.notNull(clazz);
       
      Type Parameters:
      T - 被检查对象类型
      Parameters:
      object - 被检查对象
      Returns:
      非空对象
      Throws:
      IllegalArgumentException - if the object is null