【发布时间】:2017-03-16 03:51:58
【问题描述】:
我有一个休息端点,它将具有以下 3 个参数的 url 视为有效: regno, hostid, 位置 雷尼奥, domid, 位置 regno,提供者
除了这些组合之外的任何东西都是无效的。 我有一个验证器方法来检查这个
if (!StringUtils.isEmpty(criteria.getRegno())) {
if ((!StringUtils.isEmpty(criteria.getHostid()) || !StringUtils.isEmpty(criteria.getDomId())) && !StringUtils.isEmpty(criteria.getLocation())) {
criteria.setSearchType(GET_HOST_SEARCH_TYPE);
} else if (!StringUtils.isEmpty(criteria.getProvider()) && (StringUtils.isEmpty(criteria.getLocation()) && StringUtils.isEmpty(criteria.getHostid) && StringUtils.isEmpty(criteria.getDomId()))) {
criteria.setSearchType(GET_PROVIDER_SEARCH_TYPE);
} else {
throw new BadRequestException("Either Provider, Location, Hostid or domid is missing");
}
} else {
throw new BadRequestException("Regno is missing");
}
我不喜欢我使用大量 if else 语句的事实。如果有更好的可读方式,请随时提供帮助。
【问题讨论】:
-
给出一个带参数的有效完整url字符串示例
-
localhost/search?location=india®no=12532&hostid=gdy-101
标签: java algorithm if-statement hashmap truthtable