-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
67 lines (48 loc) · 2.67 KB
/
Copy pathSolution.java
File metadata and controls
67 lines (48 loc) · 2.67 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
66
67
//But this happened so that the word may be fulfilled which was written in their law, 'They hated me without a cause.' (John 15:25)
package com.javarush.task.task29.task2908;
/*
Кеширование
*/
public class Solution {
public static void main(String[] args) throws InterruptedException {
//////////////first example///////////////////
Square square = new Square();
CacheComputeManager<Integer, Integer> manager = new CacheComputeManager(square);
for (int i = 0; i < 8; i++) {
int j = i % 4;
Integer result = manager.compute(j);
System.out.format("%d * %d = %d\n", j, j, result);
}
/* output
0 will be cached 0 * 0 = 0
1 will be cached 1 * 1 = 1
2 will be cached 2 * 2 = 4
3 will be cached 3 * 3 = 9
0 taken from cache 0 * 0 = 0
1 taken from cache 1 * 1 = 1
2 taken from cache 2 * 2 = 4
3 taken from cache 3 * 3 = 9
*/
//////////////second example///////////////////
Copyright copyright = new Copyright();
CacheComputeManager manager2 = new CacheComputeManager(copyright);
System.out.println(manager2.compute(new Copyright.Period(3012, 3147)));
System.out.println(manager2.compute(new Copyright.Period(3012, 3146)));
System.out.println(manager2.compute(new Copyright.Period(3012, 3147)));
/* output
Period{firstYear=3012, secondYear=3147} will be cached All rights reserved (c) 3012-3147
Period{firstYear=3012, secondYear=3146} will be cached All rights reserved (c) 3012-3146
Period{firstYear=3012, secondYear=3147} taken from cache All rights reserved (c) 3012-3147
*/
}
}
/*
Кеширование
В CacheComputeManager реализуй логику пустого метода.
Догадайся, что он должен делать по названию метода и по логике класса.
Требования:
1. Метод createFutureTaskForNewArgumentThatHaveToComputeValue должен создавать и возвращать объект типа FutureTask.
2. В методе createFutureTaskForNewArgumentThatHaveToComputeValue должен создаваться объект анонимного класса, реализующего интерфейс Callable.
3. Внутри метода createFutureTaskForNewArgumentThatHaveToComputeValue должна встречаться строка "return computable.compute(arg);".
4. Программа должна выводить текст указанный в комментариях в классе Solution.
*/