一、前言
关于jsoup(1.6.1)源码包中org.jsoup.helper.Validate简单校验器类,进行对象null空值校验(notNull)、布尔值判断(isTrue/isFalse)、对象数组判断(noNullElements)、错误异常定义(fail)等,详情参见源码说明。
二、源码说明
package org.jsoup.helper;@b@@b@public final class Validate@b@{@b@ public static void notNull(Object obj)@b@ {@b@ if (obj == null)@b@ throw new IllegalArgumentException("Object must not be null");@b@ }@b@@b@ public static void notNull(Object obj, String msg)@b@ {@b@ if (obj == null)@b@ throw new IllegalArgumentException(msg);@b@ }@b@@b@ public static void isTrue(boolean val)@b@ {@b@ if (!(val))@b@ throw new IllegalArgumentException("Must be true");@b@ }@b@@b@ public static void isTrue(boolean val, String msg)@b@ {@b@ if (!(val))@b@ throw new IllegalArgumentException(msg);@b@ }@b@@b@ public static void isFalse(boolean val)@b@ {@b@ if (val)@b@ throw new IllegalArgumentException("Must be false");@b@ }@b@@b@ public static void isFalse(boolean val, String msg)@b@ {@b@ if (val)@b@ throw new IllegalArgumentException(msg);@b@ }@b@@b@ public static void noNullElements(Object[] objects)@b@ {@b@ noNullElements(objects, "Array must not contain any null objects");@b@ }@b@@b@ public static void noNullElements(Object[] objects, String msg)@b@ {@b@ Object[] arr$ = objects; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Object obj = arr$[i$];@b@ if (obj == null)@b@ throw new IllegalArgumentException(msg);@b@ }@b@ }@b@@b@ public static void notEmpty(String string)@b@ {@b@ if ((string == null) || (string.length() == 0))@b@ throw new IllegalArgumentException("String must not be empty");@b@ }@b@@b@ public static void notEmpty(String string, String msg)@b@ {@b@ if ((string == null) || (string.length() == 0))@b@ throw new IllegalArgumentException(msg);@b@ }@b@@b@ public static void fail(String msg)@b@ {@b@ throw new IllegalArgumentException(msg);@b@ }@b@}