CacheCount.java
1.23 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
package com.yoho.search.cache.model;
import java.util.concurrent.atomic.AtomicLong;
public class CacheCount {
private AtomicLong totalCount = null;
private AtomicLong matchCount = null;
public CacheCount(){
this.totalCount = new AtomicLong(0);
this.matchCount = new AtomicLong(0);
}
public CacheCount(long totalCountVal,long matchCountVal){
this.totalCount = new AtomicLong(totalCountVal);
this.matchCount = new AtomicLong(matchCountVal);
}
public void clear() {
this.totalCount = new AtomicLong(0);
this.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() + "]";
}
}