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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

58.62
cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinitionStringList.java
1
package com.devonfw.tools.ide.variable;
2

3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.function.Function;
7

8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.environment.VariableLine;
10

11
/**
12
 * Implementation of {@link VariableDefinition} for a variable with the {@link #getValueType() value type} {@link String}.
13
 */
14
public class VariableDefinitionStringList extends AbstractVariableDefinition<List<String>> {
15

16
  /**
17
   * The constructor.
18
   *
19
   * @param name the {@link #getName() variable name}.
20
   */
21
  public VariableDefinitionStringList(String name) {
22

23
    super(name);
×
24
  }
×
25

26
  /**
27
   * The constructor.
28
   *
29
   * @param name the {@link #getName() variable name}.
30
   * @param legacyName the {@link #getLegacyName() legacy name}.
31
   */
32
  public VariableDefinitionStringList(String name, String legacyName) {
33

34
    super(name, legacyName);
4✔
35
  }
1✔
36

37
  /**
38
   * The constructor.
39
   *
40
   * @param name the {@link #getName() variable name}.
41
   * @param legacyName the {@link #getLegacyName() legacy name}.
42
   * @param defaultValueFactory the factory {@link Function} for the {@link #getDefaultValue(IdeContext) default value}.
43
   */
44
  public VariableDefinitionStringList(String name, String legacyName,
45
      Function<IdeContext, List<String>> defaultValueFactory) {
46

47
    super(name, legacyName, defaultValueFactory);
5✔
48
  }
1✔
49

50
  /**
51
   * The constructor.
52
   *
53
   * @param name the {@link #getName() variable name}.
54
   * @param legacyName the {@link #getLegacyName() legacy name}.
55
   * @param defaultValueFactory the factory {@link Function} for the {@link #getDefaultValue(IdeContext) default value}.
56
   * @param forceDefaultValue the {@link #isForceDefaultValue() forceDefaultValue} flag.
57
   */
58
  public VariableDefinitionStringList(String name, String legacyName,
59
      Function<IdeContext, List<String>> defaultValueFactory, boolean forceDefaultValue) {
60

61
    super(name, legacyName, defaultValueFactory, forceDefaultValue);
×
62
  }
×
63

64
  @SuppressWarnings( { "unchecked", "rawtypes" })
65
  @Override
66
  public Class<List<String>> getValueType() {
67

68
    return (Class) List.class;
×
69
  }
70

71
  @Override
72
  public List<String> fromString(String value, IdeContext context) {
73

74
    if (value.isEmpty()) {
3!
75
      return Collections.emptyList();
×
76
    }
77
    String csv = value;
2✔
78
    String separator = ",";
2✔
79
    if (isBashArray(value)) {
4✔
80
      csv = value.substring(1, value.length() - 1);
8✔
81
      separator = " ";
2✔
82
    }
83
    String[] items = csv.split(separator);
4✔
84
    List<String> list = new ArrayList<>(items.length);
6✔
85
    for (String item : items) {
16✔
86
      list.add(item.trim());
5✔
87
    }
88
    list = Collections.unmodifiableList(list);
3✔
89
    return list;
2✔
90
  }
91

92
  private boolean isBashArray(String value) {
93

94
    return value.startsWith("(") && value.endsWith(")");
12!
95
  }
96

97
  @Override
98
  public VariableLine migrateLine(VariableLine line) {
99

100
    line = super.migrateLine(line);
4✔
101
    String value = line.getValue();
3✔
102
    if ((value != null) && isBashArray(value)) {
6!
103
      List<String> list = fromString(value, null);
5✔
104
      line = line.withValue(String.join(", ", list));
6✔
105
    }
106
    return line;
2✔
107
  }
108

109
  @Override
110
  public String toString(List<String> value, IdeContext context) {
111

112
    if (value == null) {
×
113
      return "";
×
114
    }
115
    StringBuilder sb = new StringBuilder(value.size() * 5);
×
116
    for (Object element : value) {
×
117
      if (sb.length() > 0) {
×
118
        sb.append(',');
×
119
      }
120
      sb.append(element);
×
121
    }
×
122
    return sb.toString();
×
123
  }
124
}
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