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

pkiraly / metadata-qa-api / #675

07 May 2025 05:31PM UTC coverage: 87.233% (-0.01%) from 87.247%
#675

push

pkiraly
Implement SonarCloud quality suggestions #159

0 of 2 new or added lines in 1 file covered. (0.0%)

2 existing lines in 2 files now uncovered.

5521 of 6329 relevant lines covered (87.23%)

0.87 hits per line

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

86.11
/src/main/java/de/gwdg/metadataqa/api/counter/FieldCounter.java
1
package de.gwdg.metadataqa.api.counter;
2

3
import de.gwdg.metadataqa.api.util.CompressionLevel;
4
import de.gwdg.metadataqa.api.util.Converter;
5

6
import java.io.Serializable;
7
import java.util.ArrayList;
8
import java.util.LinkedHashMap;
9
import java.util.List;
10
import java.util.Map;
11

12
import de.gwdg.metadataqa.api.util.FileUtils;
13
import org.apache.commons.lang3.StringUtils;
14

15
/**
16
 * Generic field counter
17
 *
18
 * @author Péter Király <peter.kiraly at gwdg.de>
19
 * @param <T> the type of elements held in this collection
20
 */
21
public class FieldCounter<T> implements Serializable {
22

23
  private static final long serialVersionUID = -2422037365837281017L;
24
  private final Map<String, T> fieldMap;
25

26
  public FieldCounter() {
1✔
27
    fieldMap = new LinkedHashMap<>();
1✔
28
  }
1✔
29

30
  public boolean has(String key) {
31
    return fieldMap.containsKey(key);
1✔
32
  }
33

34
  public T get(String key) {
35
    return fieldMap.get(key);
1✔
36
  }
37

38
  public void put(String key, T value) {
39
    fieldMap.put(key, value);
1✔
40
  }
1✔
41

42
  public void remove(String key) {
43
    fieldMap.remove(key);
1✔
44
  }
1✔
45

46
  public void putAll(Map<String, T> map) {
47
    fieldMap.putAll(map);
×
48
  }
×
49

50
  public int size() {
51
    return fieldMap.size();
1✔
52
  }
53

54
  public void putAll(FieldCounter<T> other) {
55
    fieldMap.putAll(other.getMap());
×
56
  }
×
57

58
  public Map<String, T> getMap() {
59
    return fieldMap;
1✔
60
  }
61

62
  public String getCsv(boolean withLabel) {
63
    return getCsv(withLabel, CompressionLevel.ZERO);
1✔
64
  }
65

66
  public String getCsv(boolean withLabel, CompressionLevel compressionLevel) {
67
    List<String> items = getList(withLabel, compressionLevel);
1✔
68
    return StringUtils.join(items, ',');
1✔
69
  }
70

71
  public List<String> getList(boolean withLabel, CompressionLevel compressionLevel) {
72
    List<String> items = new ArrayList<>();
1✔
73
    for (Map.Entry<String, T> entry : fieldMap.entrySet()) {
1✔
74
      var item = new StringBuilder();
1✔
75
      if (withLabel) {
1✔
76
        item.append(String.format("\"%s\":", entry.getKey()));
1✔
77
      }
78
      var value = Converter.asString(entry.getValue());
1✔
79
      if (!(entry.getValue() instanceof Integer)
1✔
80
          && compressionLevel != CompressionLevel.ZERO) {
81
        value = Converter.compressNumber(value, compressionLevel);
1✔
82
      }
83
      item.append(FileUtils.escape(value));
1✔
84
      items.add(item.toString());
1✔
85
    }
1✔
86
    return items;
1✔
87
  }
88

89
  public List<Object> getCsv() {
90
    List<Object> values = new ArrayList<>();
1✔
91
    for (T value : fieldMap.values()) {
1✔
92
      values.add(value);
1✔
93
    }
1✔
94
    return values;
1✔
95
  }
96

97
  @Override
98
  public String toString() {
UNCOV
99
    return "FieldCounter{" +
×
100
      "fieldMap=" + fieldMap +
101
      '}';
102
  }
103
}
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