• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/AbstractCacheBuilder.java
1
package com.alicp.jetcache;
2

3
import java.util.List;
4
import java.util.concurrent.TimeUnit;
5
import java.util.function.Function;
6

7
/**
8
 * Created on 16/9/7.
9
 *
10
 * @author huangli
11
 */
12
public abstract class AbstractCacheBuilder<T extends AbstractCacheBuilder<T>> implements CacheBuilder, Cloneable {
×
13

14
    protected CacheConfig config;
15
    private Function<CacheConfig, Cache> buildFunc;
16

17
    public abstract CacheConfig getConfig();
18

19
    protected T self() {
20
        return (T) this;
×
21
    }
22

23
    public T buildFunc(Function<CacheConfig, Cache> buildFunc) {
24
        this.buildFunc = buildFunc;
×
25
        return self();
×
26
    }
27

28
    protected void beforeBuild() {
29
    }
×
30

31
    @Deprecated
32
    public final <K, V> Cache<K, V> build() {
33
        return buildCache();
×
34
    }
35

36
    @Override
37
    public final <K, V> Cache<K, V> buildCache() {
38
        if (buildFunc == null) {
×
39
            throw new CacheConfigException("no buildFunc");
×
40
        }
41
        beforeBuild();
×
42
        CacheConfig c = getConfig().clone();
×
43
        Cache<K, V> cache = buildFunc.apply(c);
×
44
        if (c.getLoader() != null) {
×
45
            if (c.getRefreshPolicy() == null) {
×
46
                cache = new LoadingCache<>(cache);
×
47
            } else {
48
                cache = new RefreshCache<>(cache);
×
49
            }
50
        }
51
        return cache;
×
52
    }
53

54
    @Override
55
    public Object clone() {
56
        AbstractCacheBuilder copy = null;
×
57
        try {
58
            copy = (AbstractCacheBuilder) super.clone();
×
59
            copy.config = getConfig().clone();
×
60
            return copy;
×
61
        } catch (CloneNotSupportedException e) {
×
62
            throw new CacheException(e);
×
63
        }
64
    }
65

66
    public T keyConvertor(Function<Object, Object> keyConvertor) {
67
        getConfig().setKeyConvertor(keyConvertor);
×
68
        return self();
×
69
    }
70

71
    public void setKeyConvertor(Function<Object, Object> keyConvertor) {
72
        getConfig().setKeyConvertor(keyConvertor);
×
73
    }
×
74

75
    public T expireAfterAccess(long defaultExpire, TimeUnit timeUnit) {
76
        getConfig().setExpireAfterAccessInMillis(timeUnit.toMillis(defaultExpire));
×
77
        return self();
×
78
    }
79

80
    public void setExpireAfterAccessInMillis(long expireAfterAccessInMillis) {
81
        getConfig().setExpireAfterAccessInMillis(expireAfterAccessInMillis);
×
82
    }
×
83

84
    public T expireAfterWrite(long defaultExpire, TimeUnit timeUnit) {
85
        getConfig().setExpireAfterWriteInMillis(timeUnit.toMillis(defaultExpire));
×
86
        return self();
×
87
    }
88

89
    public void setExpireAfterWriteInMillis(long expireAfterWriteInMillis) {
90
        getConfig().setExpireAfterWriteInMillis(expireAfterWriteInMillis);
×
91
    }
×
92

93
    public T addMonitor(CacheMonitor monitor) {
94
        getConfig().getMonitors().add(monitor);
×
95
        return self();
×
96
    }
97

98
    public void setMonitors(List<CacheMonitor> monitors) {
99
        getConfig().setMonitors(monitors);
×
100
    }
×
101

102
    public T cacheNullValue(boolean cacheNullValue) {
103
        getConfig().setCacheNullValue(cacheNullValue);
×
104
        return self();
×
105
    }
106

107
    public void setCacheNullValue(boolean cacheNullValue) {
108
        getConfig().setCacheNullValue(cacheNullValue);
×
109
    }
×
110

111
    public <K, V> T loader(CacheLoader<K, V> loader) {
112
        getConfig().setLoader(loader);
×
113
        return self();
×
114
    }
115

116
    public <K, V> void setLoader(CacheLoader<K, V> loader) {
117
        getConfig().setLoader(loader);
×
118
    }
×
119

120
    public T refreshPolicy(RefreshPolicy refreshPolicy) {
121
        getConfig().setRefreshPolicy(refreshPolicy);
×
122
        return self();
×
123
    }
124

125
    public void setRefreshPolicy(RefreshPolicy refreshPolicy) {
126
        getConfig().setRefreshPolicy(refreshPolicy);
×
127
    }
×
128

129
    public T cachePenetrateProtect(boolean cachePenetrateProtect) {
130
        getConfig().setCachePenetrationProtect(cachePenetrateProtect);
×
131
        return self();
×
132
    }
133

134
    public void setCachePenetrateProtect(boolean cachePenetrateProtect) {
135
        getConfig().setCachePenetrationProtect(cachePenetrateProtect);
×
136
    }
×
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc