package cloud.swiftnode.kspam.util;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Junhyeong Lim on 2017-01-08.
 */
public class Version {
    private int major = 0;
    private int minor = 0;
    private int add = 0;
    private String tag;

    public Version(String version) {
        set(version);
    }

    public void set(String version) {
        Pattern pattern = Pattern.compile("(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:-(.*))?");
        Matcher matcher = pattern.matcher(version);
        if (matcher.find()) {
            String major = matcher.group(1);
            String minor = matcher.group(2);
            String add = matcher.group(3);
            if (major != null) {
                this.major = Integer.parseInt(major);
            }
            if (minor != null) {
                this.minor = Integer.parseInt(minor);
            }
            if (add != null) {
                this.add = Integer.parseInt(add);
            }
            tag = matcher.group(4);
        }
    }

    public int getMajor() {
        return major;
    }

    public int getMinor() {
        return minor;
    }

    public int getAdd() {
        return add;
    }

    public boolean before(Version version) {
        if (major != version.getMajor()) {
            return major < version.getMajor();
        }
        if (minor != version.getMinor()) {
            return minor < version.getMinor();
        }
        return add < version.getAdd();
    }

    public boolean after(Version version) {
        if (major != version.getMajor()) {
            return major > version.getMajor();
        }
        if (minor != version.getMinor()) {
            return minor > version.getMinor();
        }
        return add > version.getAdd();
    }

    public boolean isTagged() {
        return tag != null;
    }

    @Override
    public String toString() {
        String ver = StringUtils.join(new Object[]{major, minor, add}, ".");
        if (isTagged()) {
            ver += "-" + tag;
        }
        return ver;
    }
}

@@ -214,16 +214,52 @@
 rsion %7B%0A
+    private static Pattern PATTERN;%0A
     priv
@@ -269,32 +269,32 @@
  int major = 0;%0A
-
     private int 
@@ -354,16 +354,119 @@
 g tag;%0A%0A
+    static %7B%0A        PATTERN = Pattern.compile(%22(%5C%5Cd+)(?:%5C%5C.(%5C%5Cd+))?(?:%5C%5C.(%5C%5Cd+))?(?:-(.*))?%22);%0A    %7D%0A%0A
     publ
@@ -565,99 +565,8 @@
 ) %7B%0A
-        Pattern pattern = Pattern.compile(%22(%5C%5Cd+)(?:%5C%5C.(%5C%5Cd+))?(?:%5C%5C.(%5C%5Cd+))?(?:-(.*))?%22);%0A
     
@@ -591,15 +591,15 @@
 r = 
-pattern
+PATTERN
 .mat

Fix Version code