/**
 * Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.beryx.viewreka.core;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.CompareToBuilder;

public class Version implements Comparable<Version> {
    private final int major;
    private final int minor;
    private final int patch;
    private final String label;
    private final boolean releaseBuild;

    public Version(int major, int minor, int patch) {
        this(major, minor, patch, "", true);
    }

    public Version(int major, int minor, int patch, String label, boolean releaseBuild) {
        this.major = major;
        this.minor = minor;
        this.patch = patch;
        this.label = label;
        this.releaseBuild = releaseBuild;
    }

    public int getMajor() {
        return major;
    }

    public int getMinor() {
        return minor;
    }

    public int getPatch() {
        return patch;
    }

    public String getLabel() {
        return label;
    }

    public boolean isReleaseBuild() {
        return releaseBuild;
    }

    @Override
    public String toString() {
        // This implementation is similar to https://github.com/ethankhall/gradle-semantic-versioning/blob/master/src/main/groovy/io/ehdev/version/Version.groovy
        String versionString = major + "." + minor + "." + patch;
        if(!StringUtils.isBlank(label)) {
            versionString += "-" + label;
        }
        if(!releaseBuild) {
            versionString += "-SNAPSHOT";
        }
        return versionString;
    }

    @Override
    public int compareTo(Version v) {
        return new CompareToBuilder()
                .append(major, v.major)
                .append(minor, v.minor)
                .append(patch, v.patch)
                .append(label, v.label)
                .append(releaseBuild, v.releaseBuild)
                .build();
    }
}

@@ -1267,16 +1267,50 @@
 .label =
+ StringUtils.isBlank(label) ? %22%22 :
  label;%0A
@@ -2139,32 +2139,835 @@
 nString;%0A    %7D%0A%0A
+    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        Version version = (Version) o;%0A%0A        if (major != version.major) return false;%0A        if (minor != version.minor) return false;%0A        if (patch != version.patch) return false;%0A        if (releaseBuild != version.releaseBuild) return false;%0A        return label != null ? label.equals(version.label) : version.label == null;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = major;%0A        result = 31 * result + minor;%0A        result = 31 * result + patch;%0A        result = 31 * result + (label != null ? label.hashCode() : 0);%0A        result = 31 * result + (releaseBuild ? 1 : 0);%0A        return result;%0A    %7D%0A%0A
     @Override%0A  

add equals and hashCode to Version