-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMacAddressStatistics.java
More file actions
65 lines (59 loc) · 2.39 KB
/
MacAddressStatistics.java
File metadata and controls
65 lines (59 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
public class MacAddressStatistics {
private SizeBalancedTree macAddressTree;
private Map<String,Integer> map;
private Map<String,Integer> countOfMac;
public MacAddressStatistics () {
//this.map = Collections.synchronizedMap(new HashMap<String, Integer>());
this.map = new ConcurrentHashMap<String, Integer>();
ValueComparator bvc = new ValueComparator(map);
this.countOfMac = Collections.synchronizedMap(new TreeMap<String, Integer>(bvc));
//this.macAddressTree = new SizeBalancedTree<NodeOfMac>();
}
/**
* 传入MAC地址,搜索MAC的SBT,新建节点或替换节点
*
* @param macAddress
*/
public void insert(String macAddress) {
if (map.containsKey(macAddress)) {
Integer times = map.get(macAddress);
map.put(macAddress, times+1);
}
else {
map.put(macAddress, 1);
}
// NodeOfMac tempNodeMac = new NodeOfMac(MacUtil.macToLong(macAddress),1);
// SizeBalancedTree.Node tempNode = macAddressTree.find(tempNodeMac);
// if (tempNode == null){
// macAddressTree.insert(tempNodeMac);
// }
// else {
//
// tempNodeMac.setCounter(Integer.parseInt(tempNode.data.toString())+1);
// macAddressTree.findAndChange(tempNodeMac);
// }
}
/**
* 遍历SBT,返回结果
*/
public Map<String,Integer> getAnswer () {
for (Map.Entry<String, Integer> entry : map.entrySet()) {
//Map.entry<Integer,String> 映射项(键-值对) 有几个方法:用上面的名字entry
//entry.getKey() ;entry.getValue(); entry.setValue();
//map.entrySet() 返回此映射中包含的映射关系的 Set视图。
// System.out.println("key= " + entry.getKey() + " and value= "
// + entry.getValue());
if (entry.getValue()>1000){
this.countOfMac.put(entry.getKey(), entry.getValue());
}
}
//this.countOfMac.putAll(map);
return this.countOfMac;
//System.out.println(macAddressTree.breadthFirstSearch());
}
}