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

devonfw / IDEasy / 19263429939

11 Nov 2025 10:58AM UTC coverage: 68.878% (-0.03%) from 68.904%
19263429939

push

github

web-flow
#1551: add NetworkStatus and improve status commandlet (#1557)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3496 of 5559 branches covered (62.89%)

Branch coverage included in aggregate %.

9159 of 12814 relevant lines covered (71.48%)

3.14 hits per line

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

95.0
cli/src/main/java/com/devonfw/tools/ide/cache/CachedValue.java
1
package com.devonfw.tools.ide.cache;
2

3
import java.util.function.Supplier;
4

5
/**
6
 * A cached value that allows a good balance between reducing computing overhead and still providing accuracy.
7
 *
8
 * @param <T> type of the {@link #get() value}.
9
 */
10
public class CachedValue<T> implements Supplier<T> {
11

12
  /** Default value for {@link #getRetention() retention}. */
13
  public static final long DEFAULT_RETENTION = 20 * 1000; // 20 seconds
14

15
  private final Supplier<T> supplier;
16

17
  private final long retention;
18

19
  private long timestamp;
20

21
  private T value;
22

23
  /**
24
   * The constructor.
25
   *
26
   * @param supplier the {@link Supplier} function to compute the actual value.
27
   */
28
  public CachedValue(Supplier<T> supplier) {
29

30
    this(supplier, DEFAULT_RETENTION);
4✔
31
  }
1✔
32

33
  /**
34
   * The constructor.
35
   *
36
   * @param supplier the {@link Supplier} function to compute the actual value.
37
   * @param retention the {@link #getRetention() retention}.
38
   */
39
  public CachedValue(Supplier<T> supplier, long retention) {
40

41
    super();
2✔
42
    this.supplier = supplier;
3✔
43
    this.retention = retention;
3✔
44
  }
1✔
45

46
  /**
47
   * @return the retention time as the duration in milliseconds when the {@link CachedValue} expires and its {@link #get() value} gets recomputed.
48
   */
49
  public long getRetention() {
50

51
    return this.retention;
×
52
  }
53

54
  @Override
55
  public T get() {
56

57
    long now = System.currentTimeMillis();
2✔
58
    if ((now - this.timestamp) > retention) {
8✔
59
      this.value = this.supplier.get();
5✔
60
      this.timestamp = now;
3✔
61
    }
62
    return this.value;
3✔
63
  }
64

65
  /**
66
   * Explicitly set the cached value by-passing its internal computation. Only use this operation with care.
67
   *
68
   * @param value the explicit {@link #get() value} to set.
69
   */
70
  public void set(T value) {
71
    this.value = value;
3✔
72
    this.timestamp = System.currentTimeMillis();
3✔
73
  }
1✔
74

75
  /**
76
   * Invalidates a potentially cached value.
77
   */
78
  public void invalidate() {
79

80
    this.timestamp = 0;
3✔
81
    this.value = null;
3✔
82
  }
1✔
83
}
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