-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSetMain.java
72 lines (61 loc) · 1.9 KB
/
TestSetMain.java
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
66
67
68
69
70
71
72
package com.ds_algo.i_set;
import com.tool.common.TimeTool;
import com.tool.common.file.FileInfo;
import com.tool.common.file.Files;
public class TestSetMain {
public static void main(String[] args) {
test2();
}
static void test1() {
Set<Integer> listSet = new ListSet<>();
listSet.add(10);
listSet.add(11);
listSet.add(11);
listSet.add(12);
listSet.add(10);
Set<Integer> treeSet = new TreeSet<>();
treeSet.add(12);
treeSet.add(10);
treeSet.add(7);
treeSet.add(11);
treeSet.add(10);
treeSet.add(11);
treeSet.add(9);
treeSet.traversal(new Set.Visitor<Integer>() {
@Override
public boolean visit(Integer element) {
System.out.println(element);
return false;
}
});
}
static void testSet(Set<String> set, String[] words) {
for (int i = 0; i < words.length; i++) {
set.add(words[i]);
}
// for (int i = 0; i < words.length; i++) {
// set.contains(words[i]);
// }
for (int i = 0; i < words.length; i++) {
set.remove(words[i]);
}
}
static void test2() {
FileInfo fileInfo = Files.read("/Users/tiny/Desktop/java_src/java/util",
new String[]{"java"});
System.out.println("文件数量:" + fileInfo.getFiles());
System.out.println("代码行数:" + fileInfo.getLines());
String[] words = fileInfo.words();
System.out.println("单词数量:" + words.length);
// TimeTool.check("ListSet", new TimeTool.Task() {
// public void execute() {
// testSet(new ListSet<>(), words);
// }
// });
TimeTool.check("TreeSet", new TimeTool.Task() {
public void execute() {
testSet(new TreeSet<>(), words);
}
});
}
}