forked from Meldexun/RLTweaker
-
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.
Update VersionDelimiter to support classifier
- Loading branch information
Showing
5 changed files
with
68 additions
and
76 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
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
128 changes: 60 additions & 68 deletions
128
src/main/java/com/charles445/rltweaker/util/VersionDelimiter.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 |
---|---|---|
@@ -1,90 +1,82 @@ | ||
package com.charles445.rltweaker.util; | ||
|
||
public class VersionDelimiter | ||
{ | ||
public int major; | ||
public int minor; | ||
public int patch; | ||
|
||
public VersionDelimiter(String ss) | ||
{ | ||
if(ss==null || ss.isEmpty()) | ||
{ | ||
wipeVersion(); | ||
return; | ||
} | ||
|
||
String[] split = ss.split("\\."); | ||
|
||
if(split.length!=3) | ||
{ | ||
wipeVersion(); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
this.major = Integer.parseInt(split[0]); | ||
this.minor = Integer.parseInt(split[1]); | ||
this.patch = Integer.parseInt(split[2]); | ||
} | ||
catch(NumberFormatException e) | ||
{ | ||
wipeVersion(); | ||
return; | ||
} | ||
import javax.annotation.Nullable; | ||
|
||
public class VersionDelimiter { | ||
|
||
public static final VersionDelimiter UNKOWN = new VersionDelimiter(0, 0, 0, null); | ||
public final int major; | ||
public final int minor; | ||
public final int patch; | ||
public final String classifier; | ||
|
||
public VersionDelimiter(int major, int minor, int patch) { | ||
this(major, minor, patch, null); | ||
} | ||
|
||
public VersionDelimiter(int major, int minor, int patch) | ||
{ | ||
|
||
public VersionDelimiter(int major, int minor, int patch, @Nullable String classifier) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
this.classifier = classifier; | ||
} | ||
|
||
public static VersionDelimiter parse(String s) { | ||
if (s == null || s.isEmpty()) { | ||
return UNKOWN; | ||
} | ||
|
||
int i = s.indexOf('-'); | ||
return i != -1 ? parse(s.substring(0, i), s.substring(i + 1)) : parse(s, null); | ||
} | ||
|
||
private static VersionDelimiter parse(String s, @Nullable String classifier) { | ||
int i1 = s.indexOf('.'); | ||
int i2 = s.indexOf('.', i1 + 1); | ||
|
||
if (i1 == -1 || i2 == -1) { | ||
return UNKOWN; | ||
} | ||
|
||
try { | ||
String s1 = s.substring(0, i1); | ||
String s2 = s.substring(i1 + 1, i2); | ||
String s3 = s.substring(i2 + 1); | ||
return new VersionDelimiter(Integer.parseInt(s1), Integer.parseInt(s2), Integer.parseInt(s3), classifier); | ||
} catch (NumberFormatException e) { | ||
return UNKOWN; | ||
} | ||
} | ||
|
||
public boolean isSameOrNewerVersion(VersionDelimiter vd) | ||
{ | ||
|
||
public boolean isSameOrNewerVersion(VersionDelimiter vd) { | ||
return isSameOrNewerVersion(vd.major, vd.minor, vd.patch); | ||
} | ||
|
||
public boolean isSameOrNewerVersion(int major, int minor) | ||
{ | ||
|
||
public boolean isSameOrNewerVersion(int major, int minor) { | ||
return isSameOrNewerVersion(major, minor, 0); | ||
} | ||
|
||
public boolean isSameOrNewerVersion(int major, int minor, int patch) | ||
{ | ||
if(this.major>major) | ||
{ | ||
|
||
public boolean isSameOrNewerVersion(int major, int minor, int patch) { | ||
if (this.major > major) { | ||
return true; | ||
} | ||
else if(this.major==major) | ||
{ | ||
if(this.minor>minor) | ||
{ | ||
} else if (this.major == major) { | ||
if (this.minor > minor) { | ||
return true; | ||
} | ||
else if(this.minor==minor) | ||
{ | ||
if(this.patch>=patch) | ||
{ | ||
} else if (this.minor == minor) { | ||
if (this.patch >= patch) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private void wipeVersion() | ||
{ | ||
this.major = 0; | ||
this.minor = 0; | ||
this.patch = 0; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return ""+major+"."+minor+"."+patch; | ||
public String toString() { | ||
if (classifier != null) { | ||
return String.format("%d.%d.%d-%s", major, minor, patch, classifier); | ||
} | ||
return String.format("%d.%d.%d", major, minor, patch); | ||
} | ||
|
||
} |