Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.osgi.service.resolver;
 
This class represents a version range.

Since:
3.1
Noextend:
This class is not intended to be subclassed by clients.
 
 public class VersionRange {
 	private static final Version versionMax = new Version(...);
An empty version range: "0.0.0". The empty version range includes all valid versions (any version greater than or equal to the version 0.0.0).
 
 	public static final VersionRange emptyRange = new VersionRange(null);
 
 	private final Version minVersion;
 	private final boolean includeMin;
 	private final Version maxVersion;
 	private final boolean includeMax;

Constructs a VersionRange with the specified minVersion and maxVersion.

Parameters:
minVersion the minimum version of the range. If null then org.osgi.framework.Version.emptyVersion is used.
maxVersion the maximum version of the range. If null then new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE) is used.
 
 	public VersionRange(Version minVersionboolean includeMinVersion maxVersionboolean includeMax) {
 		this. = minVersion == null ? . : minVersion;
 		this. = includeMin;
 		this. = maxVersion == null ? . : maxVersion;
 		this. = includeMax;
 	}

Creates a version range from the specified string.

Here is the grammar for version range strings.

 version-range ::= interval | atleast
 interval ::= ( include-min | exclude-min ) min-version ',' max-version ( include-max | exclude-max )
 atleast ::= version
 floor ::= version
 ceiling ::= version
 include-min ::= '['
 exclude-min ::= '('
 include-max ::= ']'
 exclude-max ::= ')'
 

Parameters:
versionRange string representation of the version range or null for the empty range "0.0.0"
See also:
Version.org.osgi.framework.Version.(java.lang.String) definition of version
 
 	public VersionRange(String versionRange) {
 		if (versionRange == null || versionRange.length() == 0) {
 			 = true;
 			 = true;
 			return;
 		}
 		versionRange = versionRange.trim();
 		if (versionRange.charAt(0) == '[' || versionRange.charAt(0) == '(') {
 			int comma = versionRange.indexOf(',');
 			if (comma < 0)
 				throw new IllegalArgumentException();
 			char last = versionRange.charAt(versionRange.length() - 1);
 			if (last != ']' && last != ')')
 				throw new IllegalArgumentException();
 
 			 = Version.parseVersion(versionRange.substring(1, comma).trim());
 			 = versionRange.charAt(0) == '[';
 			 = Version.parseVersion(versionRange.substring(comma + 1, versionRange.length() - 1).trim());
 			 = last == ']';
 		} else {
 			 = Version.parseVersion(versionRange.trim());
 			 = true;
 			 = true;
 		}
 	}

Returns the minimum Version of this VersionRange.

Returns:
the minimum Version of this VersionRange
	public Version getMinimum() {
		return ;
	}

Indicates if the minimum version is included in the version range.

Returns:
true if the minimum version is included in the version range; otherwise false is returned
	public boolean getIncludeMinimum() {
		return ;
	}

Returns the maximum Version of this VersionRange.

Returns:
the maximum Version of this VersionRange
	public Version getMaximum() {
		return ;
	}

Indicates if the maximum version is included in the version range.

Returns:
true if the maximum version is included in the version range; otherwise false is returned
	public boolean getIncludeMaximum() {
		return ;
	}

Returns whether the given version is included in this VersionRange. This will depend on the minimum and maximum versions of this VersionRange and the given version.

Parameters:
version a version to be tested for inclusion in this VersionRange. If null then org.osgi.framework.Version.emptyVersion is used.
Returns:
true if the version is included, false otherwise
	public boolean isIncluded(Version version) {
		if (version == null)
			version = .;
		int minCheck =  ? 0 : 1;
		int maxCheck =  ? 0 : -1;
		return version.compareTo() >= minCheck && version.compareTo() <= maxCheck;
	}
	public boolean equals(Object object) {
		if (!(object instanceof VersionRange))
			return false;
		VersionRange vr = (VersionRangeobject;
		if (.equals(vr.getMinimum()) &&  == vr.includeMin)
			if (.equals(vr.getMaximum()) &&  == vr.includeMax)
				return true;
		return false;
	}
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + .hashCode();
		result = prime * result + .hashCode();
		result = prime * result + ( ? 1231 : 1237);
		result = prime * result + ( ? 1231 : 1237);
		return result;
	}

Returns the string representation of this version range. The encoded format uses the following grammar:
 version-range ::= interval | atleast
 interval ::= ( include-min | exclude-min ) min-version ',' max-version ( include-max | exclude-max )
 atleast ::= version
 floor ::= version
 ceiling ::= version
 include-min ::= '['
 exclude-min ::= '('
 include-max ::= ']'
 exclude-max ::= ')'
 
The following are some examples of version range strings and their predicate equivalent:
 [1.2.3, 4.5.6) -> 1.2.3 <= x < 4.5.6
 [1.2.3, 4.5.6] -> 1.2.3 <= x <= 4.5.6
 (1.2.3, 4.5.6) -> 1.2.3 < x < 4.5.6
 (1.2.3, 4.5.6] -> 1.2.3 < x <= 4.5.6
 1.2.3          -> 1.2.3 <= x
 
Note that a simple version (e.g. "1.2.3") indicates a version range which is any version greater than or equal to the specified version.

Returns:
The string representation of this version range.
See also:
org.osgi.framework.Version.toString() string representation of version
	public String toString() {
			return .toString(); // we assume infinity max; use simple version (i.e version="1.0")
		StringBuffer result = new StringBuffer();
		result.append( ? '[' : '(');
		result.append(',');
		result.append( ? ']' : ')');
		return result.toString();
	}
New to GrepCode? Check out our FAQ X