• 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

50.85
cli/src/main/java/com/devonfw/tools/ide/version/VersionComparisonResult.java
1
package com.devonfw.tools.ide.version;
2

3
/**
4
 * Result of {@link VersionObject#compareVersion(Object)}.
5
 */
6
public enum VersionComparisonResult {
3✔
7

8
  /** The first version is smaller than the second one. */
9
  LESS,
6✔
10

11
  /** {@link #LESS Less} but {@link #isUnsafe() unsafe}. */
12
  LESS_UNSAFE,
6✔
13

14
  /** Both versions are equal. */
15
  EQUAL,
6✔
16

17
  /** {@link #EQUAL} but {@link #isUnsafe() unsafe}. */
18
  EQUAL_UNSAFE,
6✔
19

20
  /** The second version is larger than the second one. */
21
  GREATER,
6✔
22

23
  /** {@link #GREATER Greater} but {@link #isUnsafe() unsafe}. */
24
  GREATER_UNSAFE;
6✔
25

26
  /**
27
   * @return {@code true} if the versions are not strictly comparable (e.g. "apple" and "banana", also for "1.0" and "1-0"), {@code false} otherwise.
28
   * @see #LESS_UNSAFE
29
   * @see #GREATER_UNSAFE
30
   */
31
  public boolean isUnsafe() {
32

33
    return (this == LESS_UNSAFE) || (this == GREATER_UNSAFE);
8!
34
  }
35

36
  /**
37
   * @return {@code true} if the first version was smaller than the second one, {@code false} otherwise.
38
   */
39
  public boolean isLess() {
40

41
    return (this == LESS) || (this == LESS_UNSAFE);
10!
42
  }
43

44
  /**
45
   * @return {@code true} if both versions were equal, {@code false} otherwise.
46
   */
47
  public boolean isEqual() {
48

49
    return (this == EQUAL) || (this == EQUAL_UNSAFE);
10!
50
  }
51

52
  /**
53
   * @return {@code true} if the first version was larger than the second one, {@code false} otherwise.
54
   */
55
  public boolean isGreater() {
56

57
    return (this == GREATER) || (this == GREATER_UNSAFE);
10✔
58
  }
59

60
  /**
61
   * @return an integer value equivalent with the {@link VersionComparisonResult} and compliant with {@link VersionObject#compareTo(Object)}.
62
   */
63
  public int asValue() {
64

65
    return switch (this) {
6!
66
      case LESS, LESS_UNSAFE -> -1;
2✔
67
      case EQUAL, EQUAL_UNSAFE -> 0;
2✔
68
      case GREATER, GREATER_UNSAFE -> 1;
2✔
69
      default -> throw new IllegalStateException(toString());
×
70
    };
71
  }
72

73
  /**
74
   * @param unsafe the new value of {@link #isUnsafe()}.
75
   * @return an equivalent {@link VersionComparisonResult} with the given {@link #isUnsafe() unsafe} value.
76
   */
77
  public VersionComparisonResult withUnsafe(boolean unsafe) {
78

79
    if (unsafe) {
×
80
      return withUnsafe();
×
81
    } else {
82
      return withSafe();
×
83
    }
84
  }
85

86
  /**
87
   * @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code true}.
88
   */
89
  public VersionComparisonResult withUnsafe() {
90

91
    if (isGreater()) {
×
92
      return GREATER_UNSAFE;
×
93
    } else if (isLess()) {
×
94
      return LESS_UNSAFE;
×
95
    } else {
96
      return EQUAL_UNSAFE;
×
97
    }
98
  }
99

100
  /**
101
   * @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code false}.
102
   */
103
  public VersionComparisonResult withSafe() {
104

105
    if (isGreater()) {
×
106
      return GREATER;
×
107
    } else if (isLess()) {
×
108
      return LESS;
×
109
    } else {
110
      return EQUAL;
×
111
    }
112
  }
113

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