IP归属地格式化 @param ipAddress IP归属地 @return
(String ipAddress)
| 233 | * @return |
| 234 | */ |
| 235 | private static String format(String ipAddress){ |
| 236 | if(ipAddress != null && !ipAddress.trim().isEmpty()){ |
| 237 | if(!Strings.CI.startsWith(ipAddress, "中国|0|0|0|")){//判断开始部分是否与二参数相同。不区分大小写 |
| 238 | ipAddress = Strings.CS.replace(ipAddress, "中国|", "");//中国替换成空串 |
| 239 | } |
| 240 | |
| 241 | |
| 242 | ipAddress = Strings.CS.replace(ipAddress, "|0", "");//0替换成空串 |
| 243 | LinkedHashSet<String> hashSet = new LinkedHashSet<String>(); |
| 244 | String [] regionGroup = ipAddress.split("\\|"); |
| 245 | |
| 246 | for(String info: regionGroup){ |
| 247 | if(info !=null && !info.equals("0")){ |
| 248 | hashSet.add(info); |
| 249 | } |
| 250 | } |
| 251 | if(hashSet.size() >0){ |
| 252 | return StringUtils.join(hashSet.toArray(), " "); |
| 253 | } |
| 254 | |
| 255 | //ipAddress = StringUtils.replace(ipAddress, "|0", " ");//0替换成空串 |
| 256 | //ipAddress = StringUtils.replace(ipAddress, "|", " ");//竖线替换成空格 |
| 257 | } |
| 258 | return ""; |
| 259 | } |
| 260 | } |
no test coverage detected