有没有办法过滤掉所有大于使用流API存储在Long
中的最大值的值?
目前的情况是,你可以在前端用一个简单的搜索栏搜索一些客户的身份证.
例如:123456789, 10987654321.
如果你在这两个ID之间加一个"separator",那么一切都正常.但是如果你忘记了"separator",我的代码试图把12345678910987654321
解析成一个长的,我想这就是问题所在.
这会在try 搜索后导致NumberFormatException
分.有没有办法过滤掉那些因为太大而无法解析成Long
的数字?
String hyphen = "-";
String[] customerIds = bulkCustomerIdProperty.getValue()
.replaceAll("[^0-9]", hyphen)
.split(hyphen);
...
customerFilter.setCustomerIds(Arrays.asList(customerIds).stream()
.filter(n -> !n.isEmpty())
.map(n -> Long.valueOf(n)) // convert to Long
.collect(Collectors.toSet()));