Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
The MIT License Copyright (c) 2012 TORCH GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 package org.graylog2.plugin;
 import static;
 import static;

Following semantic versioning.
 public class Version {
     private static final Logger LOG = LoggerFactory.getLogger(Version.class);
     public final int major;
     public final int minor;
     public final int patch;
     public final String additional;
     public final String abbrevCommitSha;

Reads the current version from the classpath, using and
     public static final Version CURRENT_CLASSPATH;
     static {
         Version tmpVersion;
         try {
             final URL resource = Resources.getResource("");
             final String versionProperties = Resources.toString(resource);
             final Properties version = new Properties();
             version.load(new StringReader(versionProperties));
             final int major = Integer.parseInt(version.getProperty("version.major""0"));
             final int minor = Integer.parseInt(version.getProperty("version.minor""0"));
             final int incremental = Integer.parseInt(version.getProperty("version.incremental""0"));
             final String qualifier = version.getProperty("version.qualifier""unknown");
             String commitSha = null;
             try {
                 final Properties git = new Properties();
                 final URL gitResource = Resources.getResource("");
                 final String gitProperties = Resources.toString(gitResource);
                 git.load(new StringReader(gitProperties));
                 commitSha = git.getProperty("");
             } catch (Exception e) {
                 .debug("Git commit details are not available, skipping."e);
             tmpVersion = new Version(majorminorincrementalqualifiercommitSha);
         } catch (Exception e) {
             tmpVersion = new Version(0, 0, 0, "unknown");
             .error("Unable to read file, this build has no version number. If you get this message during development, you need to run 'Generate Sources' in IDEA or run 'mvn process-resources'."e);
          = tmpVersion;
     public Version(int majorint minorint patch) {
     public Version(int majorint minorint patchString additional) {
     public Version(int majorint minorint patchString additionalString abbrevCommitSha) {
         this. = major;
         this. = minor;
         this. = patch;
         this. = additional;
        this. = abbrevCommitSha;
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (!isNullOrEmpty()) {
        if (!isNullOrEmpty()) {
            sb.append(" (").append().append(')');
        return sb.toString();

Check if this version is higher than the passed other version. Only taking major and minor version number in account.

other version to compare
    public boolean greaterMinor(Version other) {
        return (other.major < this.) || (other.major == this. && other.minor < this.);
    public boolean equals(final Object o) {
        if (this == oreturn true;
        if (o == null || getClass() != o.getClass()) return false;
        Version that = (Versiono;
        return Objects.equals(this.that.major)
                && Objects.equals(this.that.minor)
                && Objects.equals(this.that.patch)
                && Objects.equals(this.that.additional)
                && Objects.equals(this.that.abbrevCommitSha);
    public int hashCode() {
        return Objects.hash();
New to GrepCode? Check out our FAQ X