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

devonfw / IDEasy / 18680241255

21 Oct 2025 10:03AM UTC coverage: 68.407% (-0.1%) from 68.522%
18680241255

Pull #1529

github

web-flow
Merge 6c92cf30d into 03c8a307b
Pull Request #1529: #1521: Use wiremock for npm repository.

3457 of 5541 branches covered (62.39%)

Branch coverage included in aggregate %.

9045 of 12735 relevant lines covered (71.02%)

3.12 hits per line

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

61.16
cli/src/main/java/com/devonfw/tools/ide/version/VersionLetters.java
1
package com.devonfw.tools.ide.version;
2

3
import java.util.Locale;
4
import java.util.Objects;
5

6
/**
7
 * Value type for the letters of a {@link VersionSegment}.
8
 *
9
 * @see VersionSegment#getLettersString()
10
 */
11
public final class VersionLetters implements AbstractVersionPhase, VersionObject<VersionLetters> {
12

13
  /** The empty {@link VersionLetters} instance. */
14
  public static final VersionLetters EMPTY = new VersionLetters("");
5✔
15

16
  /** The undefined {@link VersionLetters} instance. */
17
  public static final VersionLetters UNDEFINED = new VersionLetters("undefined");
6✔
18

19
  private final String letters;
20

21
  private final String lettersLowerCase;
22

23
  private final VersionPhase phase;
24

25
  private final boolean prePhase;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param letters the {@link #getLetters() letters}.
31
   */
32
  private VersionLetters(String letters) {
33

34
    super();
2✔
35
    this.letters = letters;
3✔
36
    this.lettersLowerCase = letters.toLowerCase(Locale.ROOT);
5✔
37
    String phaseLetters = this.lettersLowerCase.replace('_', '-');
6✔
38
    if (phaseLetters.startsWith("pre")) {
4✔
39
      this.prePhase = true;
3✔
40
      int preLength = 3;
2✔
41
      if (phaseLetters.startsWith("pre-")) {
4✔
42
        preLength = 4;
2✔
43
      }
44
      phaseLetters = phaseLetters.substring(preLength);
4✔
45
    } else {
1✔
46
      this.prePhase = false;
3✔
47
    }
48
    this.phase = VersionPhase.of(phaseLetters);
4✔
49
  }
1✔
50

51
  /**
52
   * @return the letters or the empty {@link String} ("") for none. In canonical {@link VersionIdentifier}s letters indicate the development phase (e.g. "pre",
53
   * "rc", "alpha", "beta", "milestone", "test", "dev", "SNAPSHOT", etc.). However, letters are technically any
54
   * {@link Character#isLetter(char) letter characters} and may also be something like a code-name (e.g. "Cupcake", "Donut", "Eclair", "Froyo", "Gingerbread",
55
   * "Honeycomb", "Ice Cream Sandwich", "Jelly Bean" in case of Android internals). Please note that in such case it is impossible to properly decide which
56
   * version is greater than another versions. To avoid mistakes, the comparison supports a strict mode that will let the comparison fail in such case. However,
57
   * by default (e.g. for {@link Comparable#compareTo(Object)}) the default {@link String#compareTo(String) string comparison} (lexicographical) is used to
58
   * ensure a natural order.
59
   * @see #getPhase()
60
   */
61
  public String getLetters() {
62

63
    return this.letters;
3✔
64
  }
65

66
  /**
67
   * @return the {@link VersionPhase} for the {@link #getLetters() letters}. Will be {@link VersionPhase#UNDEFINED} if unknown and hence never {@code null}.
68
   * @see #isPrePhase()
69
   * @see #getLetters()
70
   */
71
  public VersionPhase getPhase() {
72

73
    return this.phase;
3✔
74
  }
75

76
  /**
77
   * @return {@code true} if the {@link #getLetters() letters} and a potential {@link #getPhase() phase} are prefixed with "pre" (e.g. in "pre-alpha"),
78
   * {@code false} otherwise.
79
   */
80
  public boolean isPrePhase() {
81

82
    return this.prePhase;
3✔
83
  }
84

85
  @Override
86
  public boolean isDevelopmentPhase() {
87

88
    return this.phase.isDevelopmentPhase() || isPrePhase();
11✔
89
  }
90

91
  @Override
92
  public boolean isUnstable() {
93

94
    return this.prePhase || this.phase.isUnstable();
11✔
95
  }
96

97
  @Override
98
  public boolean isStable() {
99

100
    return !this.prePhase && this.phase.isStable();
×
101
  }
102

103
  /**
104
   * @return {@code true} if empty, {@code false} otherwise.
105
   */
106
  public boolean isEmpty() {
107

108
    return this.letters.isEmpty();
4✔
109
  }
110

111
  @Override
112
  public boolean isValid() {
113

114
    return true;
×
115
  }
116

117
  @Override
118
  public VersionComparisonResult compareVersion(VersionLetters other) {
119

120
    if (!this.lettersLowerCase.equals(other.lettersLowerCase)) {
6✔
121
      if ((this.phase == VersionPhase.UNDEFINED) || (other.phase == VersionPhase.UNDEFINED)) {
8!
122
        if (this.lettersLowerCase.compareTo(other.lettersLowerCase) < 0) {
6!
123
          return VersionComparisonResult.LESS_UNSAFE;
×
124
        } else {
125
          return VersionComparisonResult.GREATER_UNSAFE;
2✔
126
        }
127
      }
128
      if (this.phase != other.phase) {
5✔
129
        if (this.phase.ordinal() < other.phase.ordinal()) {
7✔
130
          return VersionComparisonResult.LESS;
2✔
131
        } else {
132
          return VersionComparisonResult.GREATER;
2✔
133
        }
134
      } else if (this.prePhase != other.prePhase) {
5!
135
        if (this.prePhase) {
×
136
          return VersionComparisonResult.LESS;
×
137
        } else {
138
          return VersionComparisonResult.GREATER;
×
139
        }
140
      }
141
    }
142
    return VersionComparisonResult.EQUAL;
2✔
143
  }
144

145
  /**
146
   * @param other the other {@link VersionLetters} to match against.
147
   * @param pattern - {@code true} if the owning {@link VersionSegment} {@link VersionSegment#isPattern() is a pattern}, {@code false} otherwise.
148
   * @return the {@link VersionMatchResult}.
149
   * @see VersionSegment#matches(VersionSegment)
150
   */
151
  public VersionMatchResult matches(VersionLetters other, boolean pattern) {
152

153
    if (other == null) {
2!
154
      return VersionMatchResult.MISMATCH;
×
155
    }
156
    if (isEmpty() && other.isEmpty()) {
6!
157
      return VersionMatchResult.EQUAL;
2✔
158
    }
159
    if (pattern) {
×
160
      if (this.phase != VersionPhase.NONE) {
×
161
        if (this.phase != other.phase) {
×
162
          return VersionMatchResult.MISMATCH;
×
163
        }
164
      }
165
      if (!other.lettersLowerCase.startsWith(this.lettersLowerCase)) {
×
166
        return VersionMatchResult.MISMATCH;
×
167
      }
168
      return VersionMatchResult.MATCH;
×
169
    } else {
170
      if ((this.phase != other.phase) || !this.lettersLowerCase.equals(other.lettersLowerCase)) {
×
171
        return VersionMatchResult.MISMATCH;
×
172
      }
173
      return VersionMatchResult.EQUAL;
×
174
    }
175
  }
176

177
  @Override
178
  public int hashCode() {
179

180
    return this.letters.hashCode();
×
181
  }
182

183
  @Override
184
  public boolean equals(Object obj) {
185

186
    if (obj == this) {
3!
187
      return true;
×
188
    } else if (!(obj instanceof VersionLetters)) {
3!
189
      return false;
×
190
    }
191
    VersionLetters other = (VersionLetters) obj;
3✔
192
    return Objects.equals(this.letters, other.letters);
6✔
193
  }
194

195
  @Override
196
  public String toString() {
197

198
    return this.letters;
3✔
199
  }
200

201
  /**
202
   * @param letters the letters as {@link String}.
203
   * @return the parsed {@link VersionLetters}.
204
   */
205
  public static VersionLetters of(String letters) {
206

207
    if ((letters == null) || letters.isEmpty()) {
5!
208
      return EMPTY;
2✔
209
    }
210
    return new VersionLetters(letters);
5✔
211
  }
212

213
}
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