forked from devonfw/ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into devonfw#1112-Version-prefix-not-working-as…
…-expected
- Loading branch information
Showing
11 changed files
with
1,020 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
url-updater/src/main/java/com/devonfw/tools/ide/version/CharCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.devonfw.tools.ide.version; | ||
|
||
/** | ||
* Enum with the available categories of a {@link Character} for a {@link VersionSegment}. | ||
*/ | ||
enum CharCategory { | ||
|
||
/** Category for {@link VersionSegment#getSeparator() separator} characters. */ | ||
SEPARATOR, | ||
|
||
/** Category for {@link VersionSegment#getLetters() letter} characters. */ | ||
LETTER, | ||
|
||
/** Category for {@link VersionSegment#getDigits() digit} characters. */ | ||
DIGIT; | ||
|
||
public static CharCategory of(char c) { | ||
|
||
if (isLetter(c)) { | ||
return LETTER; | ||
} else if (isDigit(c)) { | ||
return DIGIT; | ||
} else { | ||
return SEPARATOR; | ||
} | ||
} | ||
|
||
static boolean isDigit(char c) { | ||
|
||
return (c >= '0') && (c <= '9'); | ||
} | ||
|
||
static boolean isLetter(char c) { | ||
|
||
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); | ||
} | ||
|
||
static boolean isValidSeparator(char c) { | ||
|
||
return (c == '.') || (c == '-') || (c == '_'); | ||
} | ||
|
||
static boolean isLetterSeparator(char c) { | ||
|
||
return (c == '-') || (c == '_'); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
url-updater/src/main/java/com/devonfw/tools/ide/version/CharReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.devonfw.tools.ide.version; | ||
|
||
/** | ||
* Stateful object to read a {@link String} as stream of characters. | ||
*/ | ||
final class CharReader { | ||
|
||
private final String string; | ||
|
||
private final int len; | ||
|
||
private int i; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param string the {@link String} to read. | ||
*/ | ||
public CharReader(String string) { | ||
|
||
super(); | ||
this.string = string; | ||
this.len = string.length(); | ||
this.i = 0; | ||
} | ||
|
||
public boolean hasNext() { | ||
|
||
return (this.i < this.len); | ||
} | ||
|
||
public char peek() { | ||
|
||
if (this.i < this.len) { | ||
return this.string.charAt(this.i); | ||
} | ||
return '\0'; | ||
} | ||
|
||
public char next() { | ||
|
||
if (this.i < this.len) { | ||
return this.string.charAt(this.i++); | ||
} | ||
return '\0'; | ||
} | ||
|
||
public String readSeparator() { | ||
|
||
int start = this.i; | ||
while (this.i < this.len) { | ||
char c = this.string.charAt(this.i); | ||
if (!CharCategory.isDigit(c) && !CharCategory.isLetter(c)) { | ||
this.i++; | ||
} else { | ||
break; | ||
} | ||
} | ||
return this.string.substring(start, this.i); | ||
} | ||
|
||
public String readDigits() { | ||
|
||
int start = this.i; | ||
while (this.i < this.len) { | ||
char c = this.string.charAt(this.i); | ||
if (CharCategory.isDigit(c)) { | ||
this.i++; | ||
} else { | ||
break; | ||
} | ||
} | ||
return this.string.substring(start, this.i); | ||
} | ||
|
||
public String readLetters() { | ||
|
||
int start = this.i; | ||
while (this.i < this.len) { | ||
int step = 0; | ||
char c = this.string.charAt(this.i); | ||
if (CharCategory.isLetter(c)) { | ||
step = 1; | ||
} else if ((this.i > start) && CharCategory.isLetterSeparator(c)) { | ||
int j = this.i + 1; | ||
if (j < this.len) { | ||
char next = this.string.charAt(j); | ||
if (CharCategory.isLetter(next)) { | ||
step = 2; | ||
} | ||
} | ||
} | ||
if (step == 0) { | ||
break; | ||
} | ||
this.i = this.i + step; | ||
} | ||
return this.string.substring(start, this.i); | ||
} | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
url-updater/src/main/java/com/devonfw/tools/ide/version/VersionComparisonResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.devonfw.tools.ide.version; | ||
|
||
/** | ||
* Result of {@link VersionObject#compareVersion(Object)}. | ||
*/ | ||
public enum VersionComparisonResult { | ||
|
||
/** The first version is smaller than the second one. */ | ||
LESS, | ||
|
||
/** {@link #LESS Less} but {@link #isUnsafe() unsafe}. */ | ||
LESS_UNSAFE, | ||
|
||
/** Both versions are equal. */ | ||
EQUAL, | ||
|
||
/** {@link #EQUAL} but {@link #isUnsafe() unsafe}. */ | ||
EQUAL_UNSAFE, | ||
|
||
/** The second version is larger than the second one. */ | ||
GREATER, | ||
|
||
/** {@link #GREATER Greater} but {@link #isUnsafe() unsafe}. */ | ||
GREATER_UNSAFE; | ||
|
||
/** | ||
* @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. | ||
* | ||
* @see #LESS_UNSAFE | ||
* @see #GREATER_UNSAFE | ||
*/ | ||
public boolean isUnsafe() { | ||
|
||
return (this == LESS_UNSAFE) || (this == GREATER_UNSAFE); | ||
} | ||
|
||
/** | ||
* @return {@code true} if the first version was smaller than the second one, {@code false} otherwise. | ||
*/ | ||
public boolean isLess() { | ||
|
||
return (this == LESS) || (this == LESS_UNSAFE); | ||
} | ||
|
||
/** | ||
* @return {@code true} if both versions were equal, {@code false} otherwise. | ||
*/ | ||
public boolean isEqual() { | ||
|
||
return (this == EQUAL) || (this == EQUAL_UNSAFE); | ||
} | ||
|
||
/** | ||
* @return {@code true} if the first version was larger than the second one, {@code false} otherwise. | ||
*/ | ||
public boolean isGreater() { | ||
|
||
return (this == GREATER) || (this == GREATER_UNSAFE); | ||
} | ||
|
||
/** | ||
* @return an integer value equivalent with the {@link VersionComparisonResult} and compliant with | ||
* {@link VersionObject#compareTo(Object)}. | ||
*/ | ||
public int asValue() { | ||
|
||
switch (this) { | ||
case LESS: | ||
case LESS_UNSAFE: | ||
return -1; | ||
case EQUAL: | ||
case EQUAL_UNSAFE: | ||
return 0; | ||
case GREATER: | ||
case GREATER_UNSAFE: | ||
return 1; | ||
default: | ||
throw new IllegalStateException(toString()); | ||
} | ||
} | ||
|
||
/** | ||
* @param unsafe the new value of {@link #isUnsafe()}. | ||
* @return an equivalent {@link VersionComparisonResult} with the given {@link #isUnsafe() unsafe} value. | ||
*/ | ||
public VersionComparisonResult withUnsafe(boolean unsafe) { | ||
|
||
if (unsafe) { | ||
return withUnsafe(); | ||
} else { | ||
return withSafe(); | ||
} | ||
} | ||
|
||
/** | ||
* @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code true}. | ||
*/ | ||
public VersionComparisonResult withUnsafe() { | ||
|
||
if (isGreater()) { | ||
return GREATER_UNSAFE; | ||
} else if (isLess()) { | ||
return LESS_UNSAFE; | ||
} else { | ||
return EQUAL_UNSAFE; | ||
} | ||
} | ||
|
||
/** | ||
* @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code false}. | ||
*/ | ||
public VersionComparisonResult withSafe() { | ||
|
||
if (isGreater()) { | ||
return GREATER; | ||
} else if (isLess()) { | ||
return LESS; | ||
} else { | ||
return EQUAL; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.