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

devonfw / IDEasy / 11292419862

11 Oct 2024 12:34PM UTC coverage: 66.152% (-0.4%) from 66.509%
11292419862

push

github

web-flow
devonfw/ide-urls#17: fix UrlUpdater to auto-remove broken URLs and allow self-repair (#681)

2381 of 3940 branches covered (60.43%)

Branch coverage included in aggregate %.

6193 of 9021 relevant lines covered (68.65%)

3.03 hits per line

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

92.5
cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/StatusJson.java
1
package com.devonfw.tools.ide.url.model.file.json;
2

3
import java.util.Iterator;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
import java.util.Map.Entry;
7

8
import com.devonfw.tools.ide.url.model.file.UrlStatusFile;
9

10
/**
11
 * Java model class representing a "status.json" file.
12
 *
13
 * @see UrlStatusFile
14
 */
15
public class StatusJson {
16

17
  private boolean manual;
18

19
  private Map<Integer, UrlStatus> urls;
20

21
  /**
22
   * The constructor.
23
   */
24
  public StatusJson() {
2✔
25

26
    this.manual = false;
3✔
27
    this.urls = new LinkedHashMap<>();
5✔
28
  }
1✔
29

30
  /**
31
   * @return {@code true} if this file has been created manually and the containing version folder shall be ignored by the automatic update process,
32
   *     {@code false} otherwise.
33
   */
34
  public boolean isManual() {
35

36
    return this.manual;
3✔
37
  }
38

39
  /**
40
   * @param manual the new value of {@link #isManual()}.
41
   */
42
  public void setManual(boolean manual) {
43

44
    this.manual = manual;
3✔
45
  }
1✔
46

47
  /**
48
   * @return the {@link Map} with the {@link UrlStatus} objects. The {@link Map#keySet() keys} are the {@link String#hashCode() hash-codes} of the URLs.
49
   */
50
  public Map<Integer, UrlStatus> getUrls() {
51

52
    return this.urls;
3✔
53
  }
54

55
  /**
56
   * @param urlStatuses the new value of {@link #getUrls()}.
57
   */
58
  public void setUrls(Map<Integer, UrlStatus> urlStatuses) {
59

60
    this.urls = urlStatuses;
3✔
61
  }
1✔
62

63
  /**
64
   * @param url the URL to get the {@link UrlStatus} for.
65
   * @return the existing {@link UrlStatus} for the given URL or a {@code null} if not found.
66
   */
67
  public UrlStatus getStatus(String url) {
68

69
    return getStatus(url, false);
×
70
  }
71

72
  /**
73
   * @param url the URL to get or create the {@link UrlStatus} for.
74
   * @return the existing {@link UrlStatus} for the given URL or a new {@link UrlStatus} associated with the given URL.
75
   */
76
  public UrlStatus getOrCreateUrlStatus(String url) {
77

78
    return getStatus(url, true);
5✔
79
  }
80

81
  /**
82
   * @param url the URL to get or create the {@link UrlStatus} for.
83
   * @param create {@code true} for {@link #getOrCreateUrlStatus(String)} and {@code false} for {@link #getStatus(String)}.
84
   * @return the existing {@link UrlStatus} for the given URL or {@code null} or created status according to {@code create} flag.
85
   */
86
  public UrlStatus getStatus(String url, boolean create) {
87

88
    UrlStatus urlStatus;
89
    Integer key = computeKey(url);
3✔
90
    if (create) {
2✔
91
      urlStatus = this.urls.computeIfAbsent(key, hash -> new UrlStatus());
12✔
92
    } else {
93
      urlStatus = this.urls.get(key);
6✔
94
    }
95
    if (urlStatus != null) {
2✔
96
      urlStatus.markStillUsed();
2✔
97
    }
98
    return urlStatus;
2✔
99
  }
100

101
  static Integer computeKey(String url) {
102
    Integer key = Integer.valueOf(url.hashCode());
4✔
103
    return key;
2✔
104
  }
105

106
  public void remove(String url) {
107

108
    this.urls.remove(computeKey(url));
×
109
  }
×
110

111
  /**
112
   * Performs a cleanup and removes all unused entries.
113
   *
114
   * @return {@code true} if something changed during cleanup, {@code false} otherwise.
115
   */
116
  public boolean cleanup() {
117

118
    boolean changed = false;
2✔
119
    Iterator<Entry<Integer, UrlStatus>> entryIterator = this.urls.entrySet().iterator();
5✔
120
    while (entryIterator.hasNext()) {
3✔
121
      Entry<Integer, UrlStatus> entry = entryIterator.next();
4✔
122
      if (!entry.getValue().checkStillUsed()) {
5✔
123
        entryIterator.remove();
2✔
124
        changed = true;
2✔
125
      }
126
    }
1✔
127
    return changed;
2✔
128
  }
129
}
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