Skip to content

Commit

Permalink
#158: removed magical chars
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Dec 19, 2023
1 parent 9574f8d commit e50749a
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public final class VersionRange implements Comparable<VersionRange> {

private final boolean rightIsExclusive;

private static final String VERSION_SEPARATOR = ">";

private static final String START_EXCLUDING_PREFIX = "(";

private static final String START_INCLUDING_PREFIX = "[";

private static final String END_EXCLUDING_SUFFIX = ")";

private static final String END_INCLUDING_SUFFIX = "]";

/**
* The constructor.
*
Expand Down Expand Up @@ -186,15 +196,15 @@ public boolean equals(Object obj) {
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append(this.leftIsExclusive ? '(' : '[');
sb.append(this.leftIsExclusive ? START_EXCLUDING_PREFIX : START_INCLUDING_PREFIX);
if (this.min != null) {
sb.append(this.min);
}
sb.append('>');
sb.append(VERSION_SEPARATOR);
if (this.max != null) {
sb.append(this.max);
}
sb.append(this.rightIsExclusive ? ')' : ']');
sb.append(this.rightIsExclusive ? END_EXCLUDING_SUFFIX : END_INCLUDING_SUFFIX);
return sb.toString();
}

Expand All @@ -207,22 +217,22 @@ public static VersionRange of(String value) {
boolean leftIsExclusive = false;
boolean rightIsExclusive = false;

if (value.startsWith("(")) {
if (value.startsWith(START_EXCLUDING_PREFIX)) {
leftIsExclusive = true;
value = value.substring(1);
value = value.substring(START_EXCLUDING_PREFIX.length());
}
if (value.startsWith("[")) {
value = value.substring(1);
if (value.startsWith(START_INCLUDING_PREFIX)) {
value = value.substring(START_INCLUDING_PREFIX.length());
}
if (value.endsWith(")")) {
if (value.endsWith(END_EXCLUDING_SUFFIX)) {
rightIsExclusive = true;
value = value.substring(0, value.length() - 1);
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}
if (value.endsWith("]")) {
value = value.substring(0, value.length() - 1);
if (value.endsWith(END_INCLUDING_SUFFIX)) {
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}

int index = value.indexOf('>');
int index = value.indexOf(VERSION_SEPARATOR);
if (index == -1) {
return null; // log warning?
}
Expand All @@ -239,4 +249,29 @@ public static VersionRange of(String value) {
return new VersionRange(min, max, leftIsExclusive, rightIsExclusive);
}

public static String getVersionSeparator() {

return VERSION_SEPARATOR;
}

public static String getStartExcludingPrefix() {

return START_EXCLUDING_PREFIX;
}

public static String getStartIncludingPrefix() {

return START_INCLUDING_PREFIX;
}

public static String getEndExcludingSuffix() {

return END_EXCLUDING_SUFFIX;
}

public static String getEndIncludingSuffix() {

return END_INCLUDING_SUFFIX;
}

}

0 comments on commit e50749a

Please sign in to comment.