forked from j62/ctbrec
Add null check
This commit is contained in:
parent
627eb585c8
commit
d8e78bb910
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue