Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
This software is licensed under the Apache 2 license, quoted below. Copyright 2010 Julien Eluard 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.semver;
 
Version following semantic defined by Semantic Versioning document.
 
 public final class Version implements Comparable<Version> {
    
    
Version element. From most meaningful to less meaningful.
 
     public enum Element {
         MAJOR, MINOR, PATCH, SPECIAL;
     }
 
     private static final String FORMAT = "(\\d)\\.(\\d)\\.(\\d)([A-Za-z][0-9A-Za-z-]*)?";
     private static final Pattern PATTERN = Pattern.compile(.);
 
     private final int major;
     private final int minor;
     private final int patch;
     private final String special;
 
     public Version(@Nonnegative final int major, @Nonnegative final int minor, @Nonnegative final int patch) {
         this(majorminorpatchnull);
     }
 
     public Version(@Nonnegative final int major, @Nonnegative final int minor, @Nonnegative final int patch, @Nullable final String special) {
         if (major < 0) {
             throw new IllegalArgumentException(.+" must be positive");
         }
         if (minor < 0) {
             throw new IllegalArgumentException(.+" must be positive");
         }
         if (patch < 0) {
             throw new IllegalArgumentException(.+" must be positive");
         }
 
         this. = major;
         this. = minor;
         this. = patch;
         this. = special;
     }

    
Creates a Version from a string representation. Must match Version#FORMAT.

Parameters:
version
Returns:
 
     public static Version parse(@Nonnull final String version) {
         final Matcher matcher = ..matcher(version);
         if (!matcher.matches()) {
             throw new IllegalArgumentException("<"+version+"> does not match format "+.);
         }
 
         final int major = Integer.valueOf(matcher.group(1));
         final int minor = Integer.valueOf(matcher.group(2));
         final int patch = Integer.valueOf(matcher.group(3));
 
         return new Version(majorminorpatchmatcher.group(4));
     }
    
    

Parameters:
type
Returns:
next Version regarding specified Version.Element
 
     public Version next(@Nonnull final Version.Element element) {
         if (element == null) {
             throw new IllegalArgumentException("null element");
         }
        switch (element) {
            case :
                return new Version(this.+1, 0, 0);
            case :
                return new Version(this.this.+1, 0);
            case :
                return new Version(this.this.this.+1);
            default:
                throw new IllegalArgumentException("Unknown element <"+element+">");
        }
    }
    public boolean isInDevelopment() {
        return this. == 0;
    }
    public boolean isStable() {
        return !isInDevelopment();
    }
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 43 * hash + this.;
        hash = 43 * hash + this.;
        hash = 43 * hash + this.;
        hash = 43 * hash + (this. != null ? this..hashCode() : 0);
        return hash;
    }
    @Override
    public boolean equals(@Nullable final Object object) {
        if (!(object instanceof Version)) {
            return false;
        }
        final Version other = (Versionobject;
        if (other.major != this. || other.minor != this. || other.patch != this.) {
            return false;
        }
        return (this. == null) ? other.special == null : this..equals(other.special);
    }
    @Override
    public int compareTo(final Version other) {
        if (equals(other)) {
            return 0;
        }
        if (other.major > this.) {
            return 1;
        } else if (other.major == this.) {
            if (other.minor > this.) {
                return 1;
            } else if (other.minor == this.) {
                if (other.patch > this.) {
                    return 1;
                } else if (other.special != null) {
                    return other.special.compareTo(this.);
                }
            }
        }
        return -1;
    }
    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append(this.).append(".").append(this.).append(".").append(this.);
        if (this. != null) {
            builder.append(this.);
        }
        return builder.toString();
    }
New to GrepCode? Check out our FAQ X