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

ben-manes / caffeine / #5173

29 Dec 2025 05:27AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5173

push

github

ben-manes
speed up development ci build

0 of 3838 branches covered (0.0%)

0 of 7869 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
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Node.java
1
/*
2
 * Copyright 2015 Ben Manes. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.benmanes.caffeine.cache;
17

18
import static java.util.Locale.US;
19

20
import java.lang.ref.ReferenceQueue;
21

22
import org.jspecify.annotations.Nullable;
23

24
import com.github.benmanes.caffeine.cache.AccessOrderDeque.AccessOrder;
25
import com.github.benmanes.caffeine.cache.WriteOrderDeque.WriteOrder;
26
import com.google.errorprone.annotations.concurrent.GuardedBy;
27

28
/**
29
 * An entry in the cache containing the key, value, weight, access, and write metadata. The key
30
 * or value may be held weakly or softly requiring identity comparison.
31
 *
32
 * @author ben.manes@gmail.com (Ben Manes)
33
 */
34
abstract class Node<K, V> implements AccessOrder<Node<K, V>>, WriteOrder<Node<K, V>> {
×
35

36
  /** Return the key or {@code null} if it has been reclaimed by the garbage collector. */
37
  public abstract @Nullable K getKey();
38

39
  /**
40
   * Returns the reference that the cache is holding the entry by. This is either the key if
41
   * strongly held or a {@link java.lang.ref.WeakReference} to that key.
42
   */
43
  public abstract Object getKeyReference();
44

45
  /**
46
   * Returns the reference that the cache is holding the entry by or {@code null} if the underlying
47
   * key has been reclaimed by the garbage collector.
48
   */
49
  public abstract @Nullable Object getKeyReferenceOrNull();
50

51
  /** Return the value or {@code null} if it has been reclaimed by the garbage collector. */
52
  public abstract @Nullable V getValue();
53

54
  /**
55
   * Returns the reference to the value. This is either the value if strongly held or a
56
   * {@link java.lang.ref.Reference} to that value.
57
   */
58
  public abstract Object getValueReference();
59

60
  /** Sets the value, which may be held strongly, weakly, or softly. */
61
  @GuardedBy("this")
62
  public abstract void setValue(V value, @Nullable ReferenceQueue<V> referenceQueue);
63

64
  /**
65
   * Returns {@code true} if the given objects are considered equivalent. A strongly held value is
66
   * compared by equality and a weakly or softly held value is compared by identity.
67
   */
68
  public abstract boolean containsValue(Object value);
69

70
  /** Returns the weight of this entry from the entry's perspective. */
71
  @GuardedBy("this")
72
  public int getWeight() {
73
    return 1;
×
74
  }
75

76
  /** Sets the weight from the entry's perspective. */
77
  @GuardedBy("this")
78
  public void setWeight(int weight) {}
×
79

80
  /** Returns the weight of this entry from the policy's perspective. */
81
  // @GuardedBy("evictionLock")
82
  public int getPolicyWeight() {
83
    return 1;
×
84
  }
85

86
  /** Sets the weight from the policy's perspective. */
87
  // @GuardedBy("evictionLock")
88
  public void setPolicyWeight(int weight) {}
×
89

90
  /* --------------- Health --------------- */
91

92
  /** If the entry is available in the hash-table and page replacement policy. */
93
  public abstract boolean isAlive();
94

95
  /**
96
   * If the entry was removed from the hash-table and is awaiting removal from the page
97
   * replacement policy.
98
   */
99
  @GuardedBy("this")
100
  public abstract boolean isRetired();
101

102
  /** If the entry was removed from the hash-table and the page replacement policy. */
103
  @GuardedBy("this")
104
  public abstract boolean isDead();
105

106
  /** Sets the node to the <code>retired</code> state. */
107
  @GuardedBy("this")
108
  public abstract void retire();
109

110
  /** Sets the node to the <code>dead</code> state. */
111
  @GuardedBy("this")
112
  public abstract void die();
113

114
  /* --------------- Variable order --------------- */
115

116
  /** Returns the variable expiration time, in nanoseconds. */
117
  public long getVariableTime() {
118
    return 0L;
×
119
  }
120

121
  /**
122
   * Sets the variable expiration time in nanoseconds. This update may be set lazily and rely on the
123
   * memory fence when the lock is released.
124
   */
125
  public void setVariableTime(long time) {}
×
126

127
  /**
128
   * Atomically sets the variable time to the given updated value if the current value equals the
129
   * expected value and returns if the update was successful.
130
   */
131
  public boolean casVariableTime(long expect, long update) {
132
    throw new UnsupportedOperationException();
×
133
  }
134

135
  // @GuardedBy("evictionLock")
136
  public Node<K, V> getPreviousInVariableOrder() {
137
    throw new UnsupportedOperationException();
×
138
  }
139

140
  // @GuardedBy("evictionLock")
141
  public void setPreviousInVariableOrder(@Nullable Node<K, V> prev) {
142
    throw new UnsupportedOperationException();
×
143
  }
144

145
  // @GuardedBy("evictionLock")
146
  public Node<K, V> getNextInVariableOrder() {
147
    throw new UnsupportedOperationException();
×
148
  }
149

150
  // @GuardedBy("evictionLock")
151
  public void setNextInVariableOrder(@Nullable Node<K, V> prev) {
152
    throw new UnsupportedOperationException();
×
153
  }
154

155
  /* --------------- Access order --------------- */
156

157
  public static final int WINDOW = 0;
158
  public static final int PROBATION = 1;
159
  public static final int PROTECTED = 2;
160

161
  /** Returns if the entry is in the Window or Main space. */
162
  public boolean inWindow() {
163
    return getQueueType() == WINDOW;
×
164
  }
165

166
  /** Returns if the entry is in the Main space's probation queue. */
167
  public boolean inMainProbation() {
168
    return getQueueType() == PROBATION;
×
169
  }
170

171
  /** Returns if the entry is in the Main space's protected queue. */
172
  public boolean inMainProtected() {
173
    return getQueueType() == PROTECTED;
×
174
  }
175

176
  /** Sets the status to the Window queue. */
177
  public void makeWindow() {
178
    setQueueType(WINDOW);
×
179
  }
×
180

181
  /** Sets the status to the Main space's probation queue. */
182
  public void makeMainProbation() {
183
    setQueueType(PROBATION);
×
184
  }
×
185

186
  /** Sets the status to the Main space's protected queue. */
187
  public void makeMainProtected() {
188
    setQueueType(PROTECTED);
×
189
  }
×
190

191
  /** Returns the queue that the entry's resides in (window, probation, or protected). */
192
  public int getQueueType() {
193
    return WINDOW;
×
194
  }
195

196
  /** Set queue that the entry resides in (window, probation, or protected). */
197
  public void setQueueType(int queueType) {
198
    throw new UnsupportedOperationException();
×
199
  }
200

201
  /** Returns the time that this entry was last accessed, in ns. */
202
  public long getAccessTime() {
203
    return 0L;
×
204
  }
205

206
  /**
207
   * Sets the access time in nanoseconds. This update may be set lazily and rely on the memory fence
208
   * when the lock is released.
209
   */
210
  public void setAccessTime(long time) {}
×
211

212
  @Override
213
  // @GuardedBy("evictionLock")
214
  public @Nullable Node<K, V> getPreviousInAccessOrder() {
215
    return null;
×
216
  }
217

218
  @Override
219
  // @GuardedBy("evictionLock")
220
  public void setPreviousInAccessOrder(@Nullable Node<K, V> prev) {
221
    throw new UnsupportedOperationException();
×
222
  }
223

224
  @Override
225
  // @GuardedBy("evictionLock")
226
  public @Nullable Node<K, V> getNextInAccessOrder() {
227
    return null;
×
228
  }
229

230
  @Override
231
  // @GuardedBy("evictionLock")
232
  public void setNextInAccessOrder(@Nullable Node<K, V> next) {
233
    throw new UnsupportedOperationException();
×
234
  }
235

236
  /* --------------- Write order --------------- */
237

238
  /** Returns the time that this entry was last written, in ns. */
239
  public long getWriteTime() {
240
    return 0L;
×
241
  }
242

243
  /**
244
   * Sets the write-time in nanoseconds. This update may be set lazily and rely on the memory fence
245
   * when the lock is released.
246
   */
247
  public void setWriteTime(long time) {}
×
248

249
  /**
250
   * Atomically sets the write-time to the given updated value if the current value equals the
251
   * expected value and returns if the update was successful.
252
   */
253
  public boolean casWriteTime(long expect, long update) {
254
    throw new UnsupportedOperationException();
×
255
  }
256

257
  @Override
258
  // @GuardedBy("evictionLock")
259
  public @Nullable Node<K, V> getPreviousInWriteOrder() {
260
    return null;
×
261
  }
262

263
  @Override
264
  // @GuardedBy("evictionLock")
265
  public void setPreviousInWriteOrder(@Nullable Node<K, V> prev) {
266
    throw new UnsupportedOperationException();
×
267
  }
268

269
  @Override
270
  // @GuardedBy("evictionLock")
271
  public @Nullable Node<K, V> getNextInWriteOrder() {
272
    return null;
×
273
  }
274

275
  @Override
276
  // @GuardedBy("evictionLock")
277
  public void setNextInWriteOrder(@Nullable Node<K, V> next) {
278
    throw new UnsupportedOperationException();
×
279
  }
280

281
  @Override
282
  @SuppressWarnings("GuardedBy")
283
  public final String toString() {
284
    return String.format(US, "%s=[key=%s, value=%s, weight=%d, queueType=%,d, accessTimeNS=%,d, "
×
285
        + "writeTimeNS=%,d, varTimeNs=%,d, prevInAccess=%s, nextInAccess=%s, prevInWrite=%s, "
286
        + "nextInWrite=%s]", getClass().getSimpleName(), getKey(), getValue(), getWeight(),
×
287
        getQueueType(), getAccessTime(), getWriteTime(), getVariableTime(),
×
288
        getPreviousInAccessOrder() != null, getNextInAccessOrder() != null,
×
289
        getPreviousInWriteOrder() != null, getNextInWriteOrder() != null);
×
290
  }
291
}
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

© 2026 Coveralls, Inc