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

ben-manes / caffeine / #5157

03 Dec 2025 06:30AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5157

push

github

ben-manes
add loading type to parameterized test dimensions to reduce task size

0 of 3834 branches covered (0.0%)

0 of 7848 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
/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.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.jcache.processor;
17

18
import static java.util.Objects.requireNonNull;
19

20
import java.util.Optional;
21

22
import javax.cache.integration.CacheLoader;
23
import javax.cache.processor.EntryProcessor;
24
import javax.cache.processor.MutableEntry;
25

26
import org.jspecify.annotations.Nullable;
27

28
/**
29
 * An entry that is consumed by an {@link EntryProcessor}. The updates to the entry are replayed
30
 * on the cache when the processor completes.
31
 *
32
 * @author ben.manes@gmail.com (Ben Manes)
33
 */
34
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
35
public final class EntryProcessorEntry<K, V> implements MutableEntry<K, V> {
36
  private final boolean hasEntry;
37
  private final K key;
38

39
  private Action action;
40
  private @Nullable V value;
41
  private Optional<CacheLoader<K, V>> cacheLoader;
42

43
  public EntryProcessorEntry(K key, @Nullable V value, Optional<CacheLoader<K, V>> cacheLoader) {
×
44
    this.hasEntry = (value != null);
×
45
    this.cacheLoader = cacheLoader;
×
46
    this.action = Action.NONE;
×
47
    this.value = value;
×
48
    this.key = key;
×
49
  }
×
50

51
  @Override
52
  public boolean exists() {
53
    return (getValue() != null);
×
54
  }
55

56
  @Override
57
  public K getKey() {
58
    return key;
×
59
  }
60

61
  @Override
62
  public @Nullable V getValue() {
63
    if (action != Action.NONE) {
×
64
      return value;
×
65
    } else if (value != null) {
×
66
      action = Action.READ;
×
67
    } else if (cacheLoader.isPresent()) {
×
68
      value = cacheLoader.orElseThrow().load(key);
×
69
      cacheLoader = Optional.empty();
×
70
      if (value != null) {
×
71
        action = Action.LOADED;
×
72
      }
73
    }
74
    return value;
×
75
  }
76

77
  @Override
78
  public void remove() {
79
    action = (action == Action.CREATED) ? Action.NONE : Action.DELETED;
×
80
    if (value != null) {
×
81
      value = null;
×
82
    }
83
  }
×
84

85
  @Override
86
  public void setValue(V value) {
87
    requireNonNull(value);
×
88
    if (action != Action.CREATED) {
×
89
      action = (hasEntry && exists()) ? Action.UPDATED : Action.CREATED;
×
90
    }
91
    this.value = value;
×
92
  }
×
93

94
  /** Returns the dominant action performed by the processor on the entry. */
95
  public Action getAction() {
96
    return action;
×
97
  }
98

99
  @Override
100
  public <T> T unwrap(Class<T> clazz) {
101
    if (!clazz.isInstance(this)) {
×
102
      throw new IllegalArgumentException("Class " + clazz + " is unknown to this implementation");
×
103
    }
104
    @SuppressWarnings("unchecked")
105
    var castedEntry = (T) this;
×
106
    return castedEntry;
×
107
  }
108

109
  @Override
110
  public String toString() {
111
    return key + "=" + getValue();
×
112
  }
113
}
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