forked from j62/ctbrec
1
0
Fork 0

Add null check

This commit is contained in:
0xboobface 2019-12-31 12:53:12 +01:00
parent 627eb585c8
commit d8e78bb910
1 changed files with 4 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package ctbrec;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -10,14 +11,15 @@ public class Version implements Comparable<Version> {
String designator = "";
public static Version of(String s) {
Objects.requireNonNull(s, "Version string cannot be null");
Pattern p = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(?:-(.+))?");
Matcher m = p.matcher(s);
if(m.matches()) {
if (m.matches()) {
Version v = new Version();
v.major = Integer.parseInt(m.group(1));
v.minor = Integer.parseInt(m.group(2));
v.revision = Integer.parseInt(m.group(3));
if(m.group(4) != null) {
if (m.group(4) != null) {
v.designator = m.group(4);
}
return v;