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

cn.novelweb.tool.upload.fastdfs.utils.Validate Maven / Gradle / Ivy

package cn.novelweb.tool.upload.fastdfs.utils;


import java.util.Collection;

/**
 * 

*

2020-02-03 16:33

* * @author LiZW **/ public class Validate { 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; } public static T notBlank(final T chars, final String message, final Object... values) { if (chars == null) { throw new NullPointerException(String.format(message, values)); } if (isBlank(chars)) { throw new IllegalArgumentException(String.format(message, values)); } return chars; } public static T notEmpty(final T chars, final String message, final Object... values) { if (chars == null) { throw new NullPointerException(String.format(message, values)); } if (chars.length() == 0) { throw new IllegalArgumentException(String.format(message, values)); } return chars; } public static > T notEmpty(final T collection, final String message, final Object... values) { if (collection == null) { throw new NullPointerException(String.format(message, values)); } if (collection.isEmpty()) { throw new IllegalArgumentException(String.format(message, values)); } return collection; } private static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { return false; } } return true; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy