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

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

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

96.15
today-context/src/main/java/infra/cache/interceptor/CacheOperation.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.cache.interceptor;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.Collections;
23
import java.util.LinkedHashSet;
24
import java.util.Set;
25

26
import infra.lang.Assert;
27
import infra.util.StringUtils;
28

29
/**
30
 * Base class for cache operations.
31
 *
32
 * @author Costin Leau
33
 * @author Stephane Nicoll
34
 * @author Marcin Kamionowski
35
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
36
 * @since 4.0
37
 */
38
public abstract class CacheOperation implements BasicOperation {
39

40
  private final String name;
41

42
  private final Set<String> cacheNames;
43

44
  private final String key;
45

46
  private final String keyGenerator;
47

48
  private final String cacheManager;
49

50
  private final String cacheResolver;
51

52
  private final String condition;
53

54
  private final String toString;
55

56
  private final boolean hasKeyString;
57
  private final boolean hasConditionString;
58

59
  /**
60
   * Create a new {@link CacheOperation} instance from the given builder.
61
   */
62
  protected CacheOperation(Builder b) {
2✔
63
    this.name = b.name;
4✔
64
    this.cacheNames = b.cacheNames;
4✔
65
    this.key = b.key;
4✔
66
    this.keyGenerator = b.keyGenerator;
4✔
67
    this.cacheManager = b.cacheManager;
4✔
68
    this.cacheResolver = b.cacheResolver;
4✔
69
    this.condition = b.condition;
4✔
70
    this.hasKeyString = StringUtils.hasText(b.key);
5✔
71
    this.hasConditionString = StringUtils.hasText(b.condition);
5✔
72
    this.toString = b.getOperationDescription().toString();
5✔
73
  }
1✔
74

75
  public String getName() {
76
    return this.name;
×
77
  }
78

79
  @Override
80
  public Set<String> getCacheNames() {
81
    return this.cacheNames;
3✔
82
  }
83

84
  public String getKey() {
85
    return this.key;
3✔
86
  }
87

88
  public String getKeyGenerator() {
89
    return this.keyGenerator;
3✔
90
  }
91

92
  public String getCacheManager() {
93
    return this.cacheManager;
3✔
94
  }
95

96
  public String getCacheResolver() {
97
    return this.cacheResolver;
3✔
98
  }
99

100
  public String getCondition() {
101
    return this.condition;
3✔
102
  }
103

104
  public boolean hasKeyString() {
105
    return hasKeyString;
3✔
106
  }
107

108
  public boolean hasConditionString() {
109
    return hasConditionString;
3✔
110
  }
111

112
  /**
113
   * This implementation compares the {@code toString()} results.
114
   *
115
   * @see #toString()
116
   */
117
  @Override
118
  public boolean equals(@Nullable Object other) {
119
    return (other instanceof CacheOperation && toString().equals(other.toString()));
12!
120
  }
121

122
  /**
123
   * This implementation returns {@code toString()}'s hash code.
124
   *
125
   * @see #toString()
126
   */
127
  @Override
128
  public int hashCode() {
129
    return toString().hashCode();
4✔
130
  }
131

132
  /**
133
   * Return an identifying description for this cache operation.
134
   * <p>Returned value is produced by calling {@link Builder#getOperationDescription()}
135
   * during object construction. This method is used in {@link #hashCode} and
136
   * {@link #equals}.
137
   *
138
   * @see Builder#getOperationDescription()
139
   */
140
  @Override
141
  public final String toString() {
142
    return this.toString;
3✔
143
  }
144

145
  /**
146
   * Base class for builders that can be used to create a {@link CacheOperation}.
147
   */
148
  public abstract static class Builder {
2✔
149

150
    private String name = "";
3✔
151

152
    private Set<String> cacheNames = Collections.emptySet();
3✔
153

154
    private String key = "";
3✔
155

156
    private String keyGenerator = "";
3✔
157

158
    private String cacheManager = "";
3✔
159

160
    private String cacheResolver = "";
3✔
161

162
    private String condition = "";
4✔
163

164
    public void setName(String name) {
165
      Assert.hasText(name, "Name must not be empty");
3✔
166
      this.name = name;
3✔
167
    }
1✔
168

169
    public void setCacheName(String cacheName) {
170
      Assert.hasText(cacheName, "Cache name must not be empty");
3✔
171
      this.cacheNames = Collections.singleton(cacheName);
4✔
172
    }
1✔
173

174
    public void setCacheNames(String... cacheNames) {
175
      this.cacheNames = new LinkedHashSet<>(cacheNames.length);
7✔
176
      for (String cacheName : cacheNames) {
16✔
177
        Assert.hasText(cacheName, "Cache name must be non-empty if specified");
3✔
178
        this.cacheNames.add(cacheName);
5✔
179
      }
180
    }
1✔
181

182
    public Set<String> getCacheNames() {
183
      return this.cacheNames;
3✔
184
    }
185

186
    public void setKey(String key) {
187
      Assert.notNull(key, "Key is required");
3✔
188
      this.key = key;
3✔
189
    }
1✔
190

191
    public String getKey() {
192
      return this.key;
3✔
193
    }
194

195
    public String getKeyGenerator() {
196
      return this.keyGenerator;
3✔
197
    }
198

199
    public String getCacheManager() {
200
      return this.cacheManager;
3✔
201
    }
202

203
    public String getCacheResolver() {
204
      return this.cacheResolver;
3✔
205
    }
206

207
    public void setKeyGenerator(String keyGenerator) {
208
      Assert.notNull(keyGenerator, "KeyGenerator name is required");
3✔
209
      this.keyGenerator = keyGenerator;
3✔
210
    }
1✔
211

212
    public void setCacheManager(String cacheManager) {
213
      Assert.notNull(cacheManager, "CacheManager name is required");
3✔
214
      this.cacheManager = cacheManager;
3✔
215
    }
1✔
216

217
    public void setCacheResolver(String cacheResolver) {
218
      Assert.notNull(cacheResolver, "CacheResolver name is required");
3✔
219
      this.cacheResolver = cacheResolver;
3✔
220
    }
1✔
221

222
    public void setCondition(String condition) {
223
      Assert.notNull(condition, "Condition is required");
3✔
224
      this.condition = condition;
3✔
225
    }
1✔
226

227
    /**
228
     * Return an identifying description for this caching operation.
229
     * <p>Available to subclasses, for inclusion in their {@code toString()} result.
230
     */
231
    protected StringBuilder getOperationDescription() {
232
      StringBuilder result = new StringBuilder(getClass().getSimpleName());
7✔
233
      result.append('[').append(this.name);
7✔
234
      result.append("] caches=").append(this.cacheNames);
7✔
235
      result.append(" | key='").append(this.key);
7✔
236
      result.append("' | keyGenerator='").append(this.keyGenerator);
7✔
237
      result.append("' | cacheManager='").append(this.cacheManager);
7✔
238
      result.append("' | cacheResolver='").append(this.cacheResolver);
7✔
239
      result.append("' | condition='").append(this.condition).append('\'');
9✔
240
      return result;
2✔
241
    }
242

243
    public abstract CacheOperation build();
244
  }
245

246
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc