This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-argus-service/src/main/java/com/nis/web/task/IpToLongThread.java
renkaige 980ecdf7a8 1:新增业务
2:修改统计报表业务
2018-12-17 14:08:03 +06:00

54 lines
1.3 KiB
Java

package com.nis.web.task;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class IpToLongThread implements Callable<Map<Long, String>> {
private static Logger logger = LoggerFactory.getLogger(IpToLongThread.class);
private List<String> list;
public IpToLongThread(List<String> list) {
super();
this.list = list;
}
public IpToLongThread() {
super();
}
@Override
public Map<Long, String> call() throws Exception {
Map<Long, String> map=new HashMap<>();
logger.info("线程{}开始执行", Thread.currentThread().getName());
for (int i = 0; i < list.size(); i++) {
map.put(ipToLong(list.get(i)), list.get(i));
}
logger.info("线程{}执行结束", Thread.currentThread().getName());
return map;
}
public long ipToLong(String ipAddress) {
long result = 0;
String[] ipAddressInArray = ipAddress.split("\\.");
for (int i = 3; i >= 0; i--) {
long ip = Long.parseLong(ipAddressInArray[3 - i]);
// left shifting 24,16,8,0 and bitwise OR
// 1. 192 << 24
// 1. 168 << 16
// 1. 1 << 8
// 1. 2 << 0
result |= ip << (i * 8);
}
return result;
}
}