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

devonfw / IDEasy / 24846417768

23 Apr 2026 04:23PM UTC coverage: 70.687% (+0.05%) from 70.639%
24846417768

push

github

web-flow
#1823: gitconfig duplicate longpaths (#1830)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

4345 of 6798 branches covered (63.92%)

Branch coverage included in aggregate %.

11255 of 15271 relevant lines covered (73.7%)

3.11 hits per line

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

88.33
cli/src/main/java/com/devonfw/tools/ide/io/ini/IniSection.java
1
package com.devonfw.tools.ide.io.ini;
2

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

8
/**
9
 * Implementation of {@link IniSection}
10
 */
11
public class IniSection extends IniElement {
12

13
  private final String name;
14
  private final Map<String, IniProperty> properties;
15
  private final List<IniElement> sectionElements;
16

17
  /**
18
   * creates {@link IniSection} from given section heading
19
   *
20
   * @param heading the heading line of the section
21
   */
22
  public IniSection(String heading) {
2✔
23
    if (!heading.isEmpty() && (!heading.contains("[") || !heading.contains("]"))) {
11!
24
      throw new IllegalArgumentException("Section name must be surrounded by brackets");
×
25
    }
26
    this.setContent(heading);
3✔
27
    this.name = heading.replace("[", "").replace("]", "").trim();
10✔
28
    this.properties = new LinkedHashMap<>();
5✔
29
    this.sectionElements = new ArrayList<>();
5✔
30
  }
1✔
31

32
  /**
33
   * @return the section name
34
   */
35
  public String getName() {
36
    return name;
3✔
37
  }
38

39
  /**
40
   * @return list of property keys
41
   */
42
  public List<String> getPropertyKeys() {
43
    return properties.keySet().stream().toList();
6✔
44
  }
45

46
  /**
47
   * @param key the property key
48
   * @return the property with the given key
49
   */
50
  public String getPropertyValue(String key) {
51
    return properties.get(key).getValue();
7✔
52
  }
53

54
  /**
55
   * Add or update a property in the section
56
   *
57
   * @param key property key
58
   * @param value property value
59
   */
60
  public void setProperty(String key, String value) {
61
    IniProperty existingProperty = properties.get(key);
6✔
62
    if (existingProperty == null) {
2✔
63
      String indentation = this.getIndentation();
3✔
64
      if (!this.getPropertyKeys().isEmpty()) {
4!
65
        indentation = properties.get(this.getPropertyKeys().getFirst()).getIndentation();
×
66
      }
67
      StringBuilder stringBuilder = new StringBuilder(indentation);
5✔
68
      stringBuilder.append(key);
4✔
69
      stringBuilder.append(" = ");
4✔
70
      stringBuilder.append(value);
4✔
71
      IniProperty property = new IniProperty(stringBuilder.toString());
6✔
72
      sectionElements.add(property);
5✔
73
      properties.put(key, property);
6✔
74
    } else {
1✔
75
      existingProperty.setValue(value);
3✔
76
    }
77
  }
1✔
78

79
  /**
80
   * Add or update a property in the section from a property line
81
   *
82
   * @param keyValue the property line as it appears in the file
83
   */
84
  public void setPropertyLine(String keyValue) {
85
    IniProperty property = new IniProperty(keyValue);
5✔
86
    IniProperty existing = properties.get(property.getKey());
7✔
87
    if (existing == null) {
2!
88
      sectionElements.add(property);
5✔
89
      properties.put(property.getKey(), property);
8✔
90
    } else {
91
      existing.setValue(property.getValue());
×
92
    }
93
  }
1✔
94

95
  /**
96
   * Add a comment to the section
97
   *
98
   * @param comment the comment
99
   */
100
  public void addComment(String comment) {
101
    sectionElements.add(new IniComment(comment));
8✔
102
  }
1✔
103

104
  @Override
105
  public String toString() {
106
    StringBuilder stringBuilder = new StringBuilder();
4✔
107
    if (!name.isEmpty()) {
4✔
108
      stringBuilder.append(this.getContent());
5✔
109
      stringBuilder.append("\n");
4✔
110
    }
111
    for (IniElement element : sectionElements) {
11✔
112
      stringBuilder.append(element);
4✔
113
      stringBuilder.append("\n");
4✔
114
    }
1✔
115
    return stringBuilder.toString();
3✔
116
  }
117
}
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