java参数判断_[Java教程]判断参数是否符合要求的一个类
发布日期:2021-06-24 11:31:55 浏览次数:2 分类:技术文章

本文共 2154 字,大约阅读时间需要 7 分钟。

[Java教程]判断参数是否符合要求的一个类

0 2013-09-23 16:00:15 import java.util.Collection;public class Args { public static void check(final boolean expression, final String message) { if (!expression) { throw new IllegalArgumentException(message); } } public static void check(final boolean expression, final String message, final Object... args) { if (!expression) { throw new IllegalArgumentException(String.format(message, args)); } } public static T notNull(final T argument, final String name) { if (argument == null) { throw new IllegalArgumentException(name + " may not be null"); } return argument; } public static 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 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 > 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; } public static int positive(final int n, final String name) { if (n <= 0) { throw new IllegalArgumentException(name + " may not be negative or zero"); } return n; } public static long positive(final long n, final String name) { if (n <= 0) { throw new IllegalArgumentException(name + " may not be negative or zero"); } return n; } public static int notNegative(final int n, final String name) { if (n < 0) { throw new IllegalArgumentException(name + " may not be negative"); } return n; } public static long notNegative(final long n, final String name) { if (n < 0) { throw new IllegalArgumentException(name + " may not be negative"); } return n; }}

本文网址:http://www.shaoqun.com/a/71167.html

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。

0

转载地址:https://blog.csdn.net/weixin_32512381/article/details/114821327 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java基础入门第二版课第八章_Java基础入门-第八章-15
下一篇:对方正在输入 java_pom.xml · 对方正在输入.../java2flyweb - Gitee.com

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月22日 09时55分10秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章