-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheManager.java
More file actions
54 lines (43 loc) · 1.18 KB
/
Copy pathCacheManager.java
File metadata and controls
54 lines (43 loc) · 1.18 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
/*
Ori Paso - 209493683
*/
package test;
import java.util.HashSet;
import java.util.Objects;
public class CacheManager {
private int cacheSize;
private HashSet<String> set = new HashSet<>();
CacheReplacementPolicy crp;
// constructor of cache manager
public CacheManager(int Size ,CacheReplacementPolicy cashReplacement)
{
this.cacheSize = Size;
this.crp = cashReplacement;
}
// Add word to the cache by the rules of the crp
public boolean query (String word)
{
return set.contains(word);
}
public void add (String word)
{
if(set.size() >= cacheSize)
{
String removed = crp.remove();
set.remove(removed);
}
crp.add(word);
set.add(word);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheManager that = (CacheManager) o;
return cacheSize == that.cacheSize && Objects.equals(set, that.set) && Objects.equals(crp, that.crp);
}
@Override
public int hashCode() {
return Objects.hash(cacheSize, set, crp);
}
}