Skip to content

Commit

Permalink
devonfw#103: updated to be in line with devonfw#158
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Jan 2, 2024
1 parent fd64100 commit 312afdd
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,9 @@ public String toString() {
@JsonCreator
public static VersionRange of(String value) {

boolean leftIsExclusive = false;
boolean rightIsExclusive = false;

if (value.startsWith(START_EXCLUDING_PREFIX)) {
leftIsExclusive = true;
value = value.substring(START_EXCLUDING_PREFIX.length());
}
if (value.startsWith(START_INCLUDING_PREFIX)) {
value = value.substring(START_INCLUDING_PREFIX.length());
}
if (value.endsWith(END_EXCLUDING_SUFFIX)) {
rightIsExclusive = true;
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}
if (value.endsWith(END_INCLUDING_SUFFIX)) {
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}
boolean leftIsExclusive = value.startsWith(START_EXCLUDING_PREFIX);
boolean rightIsExclusive = value.endsWith(END_EXCLUDING_SUFFIX);
value = removeAffixes(value);

int index = value.indexOf(VERSION_SEPARATOR);
if (index == -1) {
Expand All @@ -279,4 +265,19 @@ public static VersionRange of(String value) {
return new VersionRange(min, max, leftIsExclusive, rightIsExclusive);
}

private static String removeAffixes(String value) {

if (value.startsWith(START_EXCLUDING_PREFIX)) {
value = value.substring(START_EXCLUDING_PREFIX.length());
} else if (value.startsWith(START_INCLUDING_PREFIX)) {
value = value.substring(START_INCLUDING_PREFIX.length());
}
if (value.endsWith(END_EXCLUDING_SUFFIX)) {
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
} else if (value.endsWith(END_INCLUDING_SUFFIX)) {
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}
return value;
}

}

0 comments on commit 312afdd

Please sign in to comment.