CacheCount.java
950 Bytes
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
package com.yoho.search.cache.model;
import java.util.concurrent.atomic.AtomicLong;
public class CacheCount {
private AtomicLong totalCount = new AtomicLong(0);
private AtomicLong matchCount = new AtomicLong(0);
public void clear() {
totalCount = new AtomicLong(0);
matchCount = new AtomicLong(0);
}
public void incTotalCount() {
totalCount.incrementAndGet();
}
public void incMatchCount() {
matchCount.incrementAndGet();
}
public AtomicLong getTotalCount() {
return totalCount;
}
public AtomicLong getMatchCount() {
return matchCount;
}
public int getMatchPercent() {
long matchCnt = matchCount.longValue();
long totalCnt = totalCount.longValue();
if (totalCnt == 0) {
return 0;
}
return (int) (matchCnt * 100L / totalCnt);
}
@Override
public String toString() {
return "CacheCount [totalCount=" + totalCount + ", matchCount=" + matchCount + ", matchPercent=" + getMatchPercent() + "]";
}
}