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

devonfw / IDEasy / 16074195902

04 Jul 2025 12:50PM UTC coverage: 67.974% (+0.08%) from 67.899%
16074195902

Pull #1406

github

web-flow
Merge 110c4b21c into ba246604e
Pull Request #1406: #1404: change ini file design to preserve comments

3269 of 5212 branches covered (62.72%)

Branch coverage included in aggregate %.

8358 of 11893 relevant lines covered (70.28%)

3.11 hits per line

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

97.06
cli/src/main/java/com/devonfw/tools/ide/io/IniFileImpl.java
1
package com.devonfw.tools.ide.io;
2

3
import java.util.LinkedHashMap;
4
import java.util.LinkedList;
5
import java.util.List;
6
import java.util.Map;
7

8
/**
9
 * Implementation of {@link IniFile} preserves order of sections and properties between reading and writing
10
 */
11
public class IniFileImpl implements IniFile {
12

13
  private final Map<String, IniSection> iniMap;
14

15
  private final Map<String, IniProperty> properties;
16

17
  private final List<IniElement> fileElements;
18

19
  /**
20
   * creates empty IniFileImpl
21
   */
22
  public IniFileImpl() {
2✔
23
    this.iniMap = new LinkedHashMap<>();
5✔
24
    this.fileElements = new LinkedList<>();
5✔
25
    this.properties = new LinkedHashMap<>();
5✔
26
  }
1✔
27

28
  @Override
29
  public String[] getSectionNames() {
30
    return iniMap.keySet().toArray(String[]::new);
10✔
31
  }
32

33
  @Override
34
  public boolean removeSection(String section) {
35
    boolean sectionExists = iniMap.containsKey(section);
5✔
36
    IniSection removedSection = iniMap.remove(section);
6✔
37
    fileElements.remove(removedSection);
5✔
38
    return sectionExists;
2✔
39
  }
40

41
  @Override
42
  public IniSection getSection(String section) {
43
    return iniMap.get(section);
6✔
44
  }
45

46
  @Override
47
  public IniSection getOrCreateSection(String section) {
48
    if (iniMap.containsKey(section)) {
5✔
49
      return iniMap.get(section);
6✔
50
    } else {
51
      IniSection newSection = new IniSectionImpl(section);
5✔
52
      iniMap.put(section, newSection);
6✔
53
      fileElements.add(newSection);
5✔
54
      return newSection;
2✔
55
    }
56
  }
57

58
  @Override
59
  public void setProperty(String key, String value) {
60
    IniProperty property = new IniPropertyImpl(key, value);
6✔
61
    fileElements.add(property);
5✔
62
    properties.put(key, property);
6✔
63
  }
1✔
64

65
  @Override
66
  public IniProperty getProperty(String key) {
67
    return properties.get(key);
×
68
  }
69

70
  @Override
71
  public void addComment(String comment, int indentLevel) {
72
    fileElements.add(new IniCommentImpl(comment, indentLevel));
9✔
73
  }
1✔
74

75
  @Override
76
  public String toString() {
77
    StringBuilder stringBuilder = new StringBuilder();
4✔
78
    for (IniElement element : fileElements) {
11✔
79
      stringBuilder.append("\t".repeat(Math.max(0, element.getIndentLevel())));
9✔
80
      stringBuilder.append(element).append("\n");
6✔
81
    }
1✔
82
    return stringBuilder.toString();
3✔
83
  }
84
}
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