Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Licensed to Aduna under one or more contributor license agreements.  
   * See the NOTICE.txt file distributed with this work for additional 
   * information regarding copyright ownership. 
   *
   * Aduna licenses this file to you under the terms of the Aduna BSD 
   * License (the "License"); you may not use this file except in compliance 
   * with the License. See the LICENSE.txt file distributed with this work 
   * for the full License.
  *
  * 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 info.aduna.app;
 
 
A product version in Aduna's version format (i.e. major.minor-modifier). Where major stands for the major version number of the release, minor is the minor version number, and modifier is a modifier for the release, e.g. beta1 or RC1. Combined, this results in versions like 2.0 and 4.1-beta1.
 
 public class AppVersion implements Comparable<AppVersion> {

The version's major version number.
 
 	private int major;

The version's minor version number.
 
 	private int minor;

The version's micro version number.
 
 	private int micro;

The version's modifier, if any.
 
 	private String modifier;

Construct an uninitialized AppVersion.
 
 	public AppVersion() {
 		this(-1, -1, -1, null);
 	}

Creates a new major.minor version number, e.g. 1.0.
 
 	public AppVersion(int majorint minor) {
 		this(majorminor, -1, null);
 	}

Creates a new major.minor.micro version number, e.g. 1.0.1.
 
 	public AppVersion(int majorint minorint micro) {
 		this(majorminormicronull);
 	}

Creates a new major.minor-modifier version number, e.g. 1.0-beta1.
 
 	public AppVersion(int majorint minorString modifier) {
 		this(majorminor, -1, modifier);
 	}

Creates a new major.minor.micro-modifier version number, e.g. 1.0.1-SNAPSHOT.
 
 	public AppVersion(int majorint minorint microString modifier) {
 		this. = major;
 		this. = minor;
 		this. = micro;
 		this. = modifier;
 	}

Gets the version's major version number.
 
 	public int getMajor() {
 		return ;
 	}
 
 	public void setMajor(int major) {
		this. = major;
	}

Gets the version's minor version number.
	public int getMinor() {
		return ;
	}
	public void setMinor(int minor) {
		this. = minor;
	}

Gets the version's micro version number.
	public int getMicro() {
		return ;
	}
	public void setMicro(int micro) {
		this. = micro;
	}

Gets the version's release modifier part.
	public String getModifier() {
		return ;
	}
	public void setModifier(String modifier) {
		this. = modifier;
	}
	public boolean equals(Object other) {
		boolean isEqual = false;
		if (other instanceof AppVersion) {
			AppVersion o = (AppVersion)other;
			isEqual =  == o.major &&  == o.minor &&  == o.micro;
			if (isEqual) {
				isEqual =  == o.modifier ||  != null && .equalsIgnoreCase(o.modifier);
			}
		}
		return isEqual;
	}
	public int hashCode() {
		int hash = 31 * (31 *  + );
		if ( > 0) {
			hash += ;
		}
		if ( != null) {
		}
		return hash;
	}

Checks if this version is older than the specified version, according to the result of compareTo(info.aduna.app.AppVersion).
	public boolean olderThan(AppVersion other) {
		return this.compareTo(other) < 0;
	}

Checks if this version is newer than the specified version, according to the result of compareTo(info.aduna.app.AppVersion).
	public boolean newerThan(AppVersion other) {
		return this.compareTo(other) > 0;
	}

Compares two version numbers according to their major, minor and micro version numbers, ordering from oldest to newests version. If all three version numbers are equal then their modifiers are compared lexicographically (based on the Unicode value of each character), ignoring case. Versions without a modifier are considered to be the "final" versions and come after otherwise equal versions with a modifier.

Returns:
0 if both versions are equal, a negative number if this version is older than other, or a positive number otherwise.
	public int compareTo(AppVersion other) {
		int result =  - other.major;
		if (result == 0) {
			result =  - other.minor;
		}
		if (result == 0) {
			result =  - other.micro;
		}
		if (result == 0 && !ObjectUtil.nullEquals(other.modifier)) {
			if ( == null) {
				result = 1;
			}
			else if (other.modifier == null) {
				result = -1;
			}
			else {
				result = .compareToIgnoreCase(other.modifier);
			}
		}
		return result;
	}

Parses a version string into a Version object.

Parameters:
versionString A version string, e.g. 1.0.1 or 1.0-beta1.
Returns:
The parsed Version.
Throws:
java.lang.NumberFormatException If versionString could not be parsed to a version.
	public static AppVersion parse(String versionString) {
		if (versionString.equals("dev")) {
			return new AppVersion(-1, -1, "dev");
		}
		int minorSeperator = versionString.indexOf('.');
		int microSeperator = versionString.indexOf('.'minorSeperator + 1);
		int modifierSeperator = versionString.indexOf('-', Math.max(minorSeperatormicroSeperator));
		if (minorSeperator == -1) {
			throw new NumberFormatException("Illegal version string: " + versionString);
		}
		String major = versionString.substring(0, minorSeperator);
		String minor = null;
		String micro = null;
		String modifier = null;
		if (microSeperator == -1) {
			// Without micro version number
			if (modifierSeperator == -1) {
				minor = versionString.substring(minorSeperator + 1);
			}
			else {
				minor = versionString.substring(minorSeperator + 1, modifierSeperator);
				modifier = versionString.substring(modifierSeperator + 1);
			}
		}
		else {
			// With micro version number
			minor = versionString.substring(minorSeperator + 1, microSeperator);
			if (modifierSeperator == -1) {
				micro = versionString.substring(microSeperator + 1);
			}
			else {
				micro = versionString.substring(microSeperator + 1, modifierSeperator);
				modifier = versionString.substring(modifierSeperator + 1);
			}
		}
		int majorInt = Integer.parseInt(major);
		int minorInt = Integer.parseInt(minor);
		int microInt = micro == null ? -1 : Integer.parseInt(micro);
		return new AppVersion(majorIntminorIntmicroIntmodifier);
	}

Returns the string represention of this version.
	public String toString() {
		StringBuilder sb = new StringBuilder(16);
		if ( >= 0) {
		}
		if ( >= 0) {
		}
		if ( != null) {
			if (sb.length() > 0) {
				sb.append('-');
			}
		}
		return sb.toString();
	}
New to GrepCode? Check out our FAQ X