vite.api.vo.Test Maven / Gradle / Ivy
The newest version!
package vite.api.vo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class Test {
public static Map groupMap = new ConcurrentHashMap<>();
public static Map ipMap = new ConcurrentHashMap<>();
public static Map addressMap = new ConcurrentHashMap<>();
public static Map uuidMap = new ConcurrentHashMap<>();
public static class Group {
private String groupuuid;
private ItemInfo itemInfo;
Set ipset = new HashSet<>();
Set uuidSet = new HashSet<>();
Set addressSet = new HashSet<>();
Set set = new HashSet<>();
public void addItemInfo(ItemInfo itemInfo) {
this.set.add(itemInfo);
this.ipset.add(itemInfo.getIp());
this.uuidSet.add(itemInfo.getUuid());
this.addressSet.add(itemInfo.getAddress());
}
public Set getIpset() {
return ipset;
}
public void setIpset(Set ipset) {
this.ipset = ipset;
}
public Set getUuidSet() {
return uuidSet;
}
public void setUuidSet(Set uuidSet) {
this.uuidSet = uuidSet;
}
public Set getAddressSet() {
return addressSet;
}
public void setAddressSet(Set addressSet) {
this.addressSet = addressSet;
}
public ItemInfo getItemInfo() {
return itemInfo;
}
public void setItemInfo(ItemInfo itemInfo) {
this.itemInfo = itemInfo;
}
public Set getSet() {
return set;
}
public void setSet(Set set) {
this.set = set;
}
public String getGroupuuid() {
return groupuuid;
}
public void setGroupuuid(String groupuuid) {
this.groupuuid = groupuuid;
}
@Override
public String toString() {
return ipset.size() + " " + addressSet.size() + " " + uuidSet.size();
}
}
public static class ItemInfo {
private String ip;
private String uuid;
private String address;
public ItemInfo(String ip, String uuid, String address) {
this.ip = ip;
this.uuid = uuid;
this.address = address;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof ItemInfo)) {
return false;
}
if (!this.uuid.equals(((ItemInfo) obj).getUuid())) {
return false;
}
if (!this.address.equals(((ItemInfo) obj).getAddress())) {
return false;
}
if (!this.ip.equals(((ItemInfo) obj).getIp())) {
return false;
}
return true;
}
@Override
public int hashCode() {
return (ip + uuid + address).hashCode();
}
@Override
public String toString() {
return ip + "\t" + uuid + "\t" + address;
}
}
public static void main(String[] args) {
File file = new File("/Users/eric/Downloads/metaw.csv");
BufferedReader reader = null;
try {
// System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
//System.out.println("line " + line + ": " + tempString);
String[] items = tempString.split(",");
String ip = items[3];
String address = items[2];
String uuid = items[1];
if (ip.equals("")) {
continue;
}
if (address.equals("")) {
continue;
}
if (uuid.equals("")) {
continue;
}
Group group = null;
Group groupIp = ipMap.get(ip);
Group groupAddress = addressMap.get(address);
Group groupuuid = uuidMap.get(uuid);
group = groupIp != null ? groupIp : groupAddress != null ? groupAddress : groupuuid != null ? groupuuid : null;
ItemInfo itemInfo = new ItemInfo(ip, uuid, address);
if (group == null) {
Group grouptmp = new Group();
if (itemInfo.getAddress().equals("\"vite_411dccbeab2c18862093ac8032a90d04ef42127a0bdf3f5b50\"")) {
System.out.println(itemInfo);
}
grouptmp.setGroupuuid(itemInfo.getAddress());
group = grouptmp;
groupMap.put(group.getGroupuuid(), group);
}
group.addItemInfo(itemInfo);
if (groupIp != null) {
} else {
ipMap.put(ip, group);
}
if (groupAddress != null) {
} else {
addressMap.put(address, group);
}
if (groupuuid != null) {
} else {
uuidMap.put(uuid, group);
}
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
System.out.println(groupMap.size());
for (Map.Entry entry : groupMap.entrySet()) {
/**
if (entry.getValue().getSet().size() > 10) {
System.out.println("--------------begin:" + entry.getValue().getSet().size() + "------------------");
Iterator it = entry.getValue().getSet().iterator();
while (it.hasNext()) {
System.out.println(it.next().toString());
}
System.out.println("--------------end------------------");
}**/
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy