判断参数是否符合要求的一个类

import java.util.Collection;public class Args {check(final boolean expression, final String message) {if (!expression) {throw new IllegalArgumentException(message);}}check(final boolean expression, final String message, final Object… args) {if (!expression) {throw new IllegalArgumentException(String.format(message, args));}}public static <T> T notNull(final T argument, final String name) {if (argument == null) {throw new IllegalArgumentException(name + " may not be null");}return argument;}public static <T extends CharSequence> T notEmpty(final T argument, final String name) {if (argument == null) {throw new IllegalArgumentException(name + " may not be null");}if (TextUtils.isEmpty(argument)) {throw new IllegalArgumentException(name + " may not be empty");}return argument;}public static <T extends CharSequence> T notBlank(final T argument, final String name) {if (argument == null) {throw new IllegalArgumentException(name + " may not be null");}if (TextUtils.isBlank(argument)) {throw new IllegalArgumentException(name + " may not be blank");}return argument;}public static <E, T extends Collection<E>> T notEmpty(final T argument, final String name) {if (argument == null) {throw new IllegalArgumentException(name + " may not be null");}if (argument.isEmpty()) {throw new IllegalArgumentException(name + " may not be empty");}return argument;}positive(final int n, final String name) {if (n <= 0) {throw new IllegalArgumentException(name + " may not be negative or zero");}return n;}positive(final long n, final String name) {if (n <= 0) {throw new IllegalArgumentException(name + " may not be negative or zero");}return n;}notNegative(final int n, final String name) {if (n < 0) {throw new IllegalArgumentException(name + " may not be negative");}return n;}notNegative(final long n, final String name) {if (n < 0) {throw new IllegalArgumentException(name + " may not be negative");}return n;}}

,累死累活不说,走马观花反而少了真实体验,

判断参数是否符合要求的一个类

相关文章:

你感兴趣的文章:

标签云: