if (rightClosed) { return left.equals(right); } else { Version adjacent1 = new Version(left.getMajor(), left.getMinor(), left.getMicro(), left.getQualifier() + "-"); return adjacent1.compareTo(right) >= 0; Version adjacent1 = new Version(left.getMajor(), left.getMinor(), left.getMicro(), left.getQualifier() + "-"); return adjacent1.equals(right); } else { Version adjacent2 = new Version(left.getMajor(), left.getMinor(), left.getMicro(), left.getQualifier() + "--"); return adjacent2.compareTo(right) >= 0;
/** * Returns a hash code value for the object. * * @return An integer which is a hash code value for this object. */ @Override public int hashCode() { if (hash != 0) { return hash; } if (empty) { return hash = 31; } int h = 31 + (leftClosed ? 7 : 5); h = 31 * h + left.hashCode(); if (right != null) { h = 31 * h + right.hashCode(); h = 31 * h + (rightClosed ? 7 : 5); } return hash = h; }
/** * Internal isEmpty behavior. * * @return {@code true} if this version range is empty; {@code false} * otherwise. */ private boolean isEmpty0() { if (right == null) { // infinity return false; } int comparison = left.compareTo(right); if (comparison == 0) { // endpoints equal return !leftClosed || !rightClosed; } return comparison > 0; // true if left > right }
/** * Returns the string representation of this version range. * * <p> * The format of the version range string will be a version string if the * right end point is <i>Infinity</i> ({@code null}) or an interval string. * * @return The string representation of this version range. */ @Override public String toString() { if (versionRangeString != null) { return versionRangeString; } String leftVersion = left.toString(); if (right == null) { StringBuffer result = new StringBuffer(leftVersion.length() + 1); result.append(left.toString0()); return versionRangeString = result.toString(); } String rightVerion = right.toString(); StringBuffer result = new StringBuffer(leftVersion.length() + rightVerion.length() + 5); result.append(leftClosed ? LEFT_CLOSED : LEFT_OPEN); result.append(left.toString0()); result.append(ENDPOINT_DELIMITER); result.append(right.toString0()); result.append(rightClosed ? RIGHT_CLOSED : RIGHT_OPEN); return versionRangeString = result.toString(); }
public IdentityRequirementBuilder(ResourceIdentity identity) { this(identity.getSymbolicName(), identity.getVersion().toString()); }
maj = parseInt(st.nextToken(), version); min = parseInt(st.nextToken(), version); if (micval.endsWith("-SNAPSHOT")) { micval = micval.substring(0, micval.indexOf('-')); mic = parseInt(micval, version); qual = "SNAPSHOT"; } else { mic = parseInt(micval, version); micro = mic; qualifier = qual; validate();
/** * Parses a version identifier from the specified string. * * <p> * See {@code Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@code emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } version = version.trim(); if (version.length() == 0) { return emptyVersion; } return new Version(version); }
/** * Compares this {@code VersionRange} object to another object. * * <p> * A version range is considered to be <b>equal to </b> another version * range if both the endpoints and their types are equal or if both version * ranges are {@link #isEmpty() empty}. * * @param object The {@code VersionRange} object to be compared. * @return {@code true} if {@code object} is a {@code VersionRange} and is * equal to this object; {@code false} otherwise. */ @Override public boolean equals(Object object) { if (object == this) { // quicktest return true; } if (!(object instanceof VersionRange)) { return false; } VersionRange other = (VersionRange) object; if (empty && other.empty) { return true; } if (right == null) { return (leftClosed == other.leftClosed) && (other.right == null) && left.equals(other.left); } return (leftClosed == other.leftClosed) && (rightClosed == other.rightClosed) && left.equals(other.left) && right.equals(other.right); }
/** * Returns whether this version range includes the specified version. * * @param version The version to test for inclusion in this version range. * @return {@code true} if the specified version is included in this version * range; {@code false} otherwise. */ public boolean includes(Version version) { if (empty) { return false; } if (left.compareTo(version) >= (leftClosed ? 1 : 0)) { return false; } if (right == null) { return true; } return right.compareTo(version) >= (rightClosed ? 0 : 1); }
@Override public Version getVersion() { String version = module.getIdentity().getVersion().toString(); return Version.parseVersion(version); }
public static Version getVersion(Capability cap, String attname) { Object attval = cap.getAttributes().get(attname); if (attval != null && !(attval instanceof Version)) { attval = new Version(attval.toString()); cap.getAttributes().put(attname, attval); } return attval != null ? (Version) attval : Version.emptyVersion; }
public EmbeddedRuntime(PropertiesProvider propertiesProvider, Attachable context) { super(propertiesProvider); serviceManager = new RuntimeServicesManager(adapt(RuntimeEventsManager.class)); storageHandler = new RuntimeStorageHandler(propertiesProvider, true); // Install system module ResourceIdentity sysid = getSystemIdentity(); Resource resource = new DefaultResourceBuilder().addIdentityCapability(sysid).getResource(); try { Dictionary<String, String> headers = new Hashtable<>(); headers.put("Bundle-SymbolicName", sysid.getSymbolicName()); headers.put("Bundle-Version", sysid.getVersion().toString()); installModule(EmbeddedRuntime.class.getClassLoader(), resource, headers, context); } catch (ModuleException ex) { throw new IllegalStateException("Cannot install system module", ex); } }
@Override public int compare(Capability cap1, Capability cap2) { // Prefer already wired if (wirings != null) { Wiring w1 = wirings.get(cap1.getResource()); Wiring w2 = wirings.get(cap2.getResource()); if (w1 != null && w2 == null) return -1; if (w1 == null && w2 != null) return +1; } // Prefer higher version Version v1 = AbstractCapability.getVersion(cap1, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); Version v2 = AbstractCapability.getVersion(cap2, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); return v2.compareTo(v1); } }; }