-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainApp.java
More file actions
60 lines (42 loc) · 1.26 KB
/
Copy pathMainApp.java
File metadata and controls
60 lines (42 loc) · 1.26 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
package algorithm.lru;
import java.util.Map;
/**
* @Author : yion
* @Date : 2017. 6. 1.
* @Description :
*/
public class MainApp {
public static void main(String[] args) {
LRUCache<String, String> c = new LRUCache<>(3);
c.put("1", "one"); // 1
for (Map.Entry<String, String> e : c.getAll()) {
System.out.println( e.getKey());
}
c.put("2", "two"); // 2 1
c.put("3", "three"); // 3 2 1
c.put("4", "four"); // 4 3 2
if (c.get("2") == null) {
throw new Error(); // 2 4 3
}
c.put("5", "five"); // 5 2 4
c.put("4", "four"); // 4 5 2
for (Map.Entry<String, String> e : c.getAll()) {
System.out.println( e.getKey());
}
if (c.usedEntries() != 3) {
throw new Error();
}
for (Map.Entry<String, String> e : c.getAll()) {
System.out.print( e.getKey());
}
if (!c.get("4").equals("second four")) {
System.out.println("ERROR");
}
for (Map.Entry<String, String> e : c.getAll()) {
System.out.print( e.getKey());
}
if (!c.get("2").equals("two")) {
throw new Error();
}
}
}