Home   Info   DevZone   Wiki  
UsersWeb  |  MainWeb  |  InfoWeb  |  DevZoneWeb  |  SupportWeb
org.jos.util.Version ] [ not logged in ] [ Web: Main ] goto:  options
[ get info on or edit ] login or new user ] [ list of topics, hubs & nodes, or recent changes ]

ProblemArticles


package org.jos.util;

/** A simple class that stores a version info (major, minor, bugfix), e.g.
 *	1.0.2, 1.1.4 or 3.4.10
 *
 *	@author StefanReich
 *	@version 28-Mar-98
 */
 
public final class Version {
	private int major, minor, bugfix;
	
	public Version(int major, int minor) {
		this.major = major;
		this.minor = minor;
		this.bugfix = 1;
	}

	public Version(int major, int minor, int bugfix) {
		this.major = major;
		this.minor = minor;
		this.bugfix = bugfix;
	}
	
	public boolean isNewerThan(Version v) {
		return major > v.major || (major == v.major &&
			(minor > v.minor || (minor == v.minor &&
			bugfix > v.bugfix)));
	}
	
	public boolean isNewerThanOrEqualTo(Version v) {
		return major > v.major || (major == v.major &&
			(minor > v.minor || (minor == v.minor &&
			bugfix >= v.bugfix)));
	}
	
	public boolean equals(Object o) {
		if (!(o instanceof Version)) return false;
		Version v = (Version) o;
		return major == v.major && minor == v.minor && bugfix == v.bugfix;
	}
	
	public int hashCode() {
		return major ^ (minor << 4) ^ (bugfix << 8);
	}
	
	public String toString() {
		return major+"."+minor+"."+bugfix;
	}
}



Content of these pages are owned and copyrighted by the poster.
Hosted by: