From e50749a627f1ad3a47f893277c9e9d73fc4e3e81 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Tue, 19 Dec 2023 16:12:58 +0100 Subject: [PATCH] #158: removed magical chars --- .../tools/ide/version/VersionRange.java | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java b/cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java index 8eed7f151..7c9f00b97 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java +++ b/cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java @@ -15,6 +15,16 @@ public final class VersionRange implements Comparable { 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. * @@ -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(); } @@ -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? } @@ -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; + } + }