public VersionSpecification intersect(VersionSpecification other) { return new VersionSpecification( intersect(major, other.major, "major"), intersect(minor, other.minor, "minor"), intersect(micro, other.micro, "micro"), intersect(qualifier, other.qualifier, "qualifier")); }
@Override public int compare(VersionSpecification v1, VersionSpecification v2) { return v1.compareTo(v2); } }
/** * check if the Version specification is equal to the * empty spec ("match anything") **/ public boolean isEmpty() { return equals(emptyVersionSpecification); }
/** * Returns the lowest possible Version object that matches this spec **/ public Version lowestMatchingVersion() { return new Version(getMajor(), getMinor(), getMicro(), getQualifier()); }
/** * Must be called on construction after the component values are set * * @throws IllegalArgumentException If the numerical components are negative * or the qualifier string is invalid. */ private void initialize() { stringValue = toStringValue(major, minor, micro, qualifier); ensureUnspecifiedOnlyToTheRight(major, minor, micro, qualifier); if (major!=null && major < 0) throw new IllegalArgumentException("Negative major in " + this); if (minor!=null && minor < 0) throw new IllegalArgumentException("Negative minor in " + this); if (micro!=null && micro < 0) throw new IllegalArgumentException("Negative micro in " + this); String q = getQualifier(); for (int i = 0; i < q.length(); i++) { if ( !Character.isLetterOrDigit(q.charAt(i)) ) throw new IllegalArgumentException("Invalid qualifier in " + this + ": Invalid character at position " + i + " in qualifier"); } }
/** * Returns true if the given version matches this specification. * It matches if all the numeric components specified are the same * as in the version, and both qualifiers are either null or set * to the same value. I.e, a version which includes a qualifier * will only match exactly and will never return true from a * request for an unspecified qualifier. */ public boolean matches(Version version) { if (matches(this.major, version.getMajor()) && matches(this.minor, version.getMinor()) && matches(this.micro, version.getMicro())) { return (version.getQualifier().equals(this.getQualifier())); } else { return false; } }
public static VersionSpecification fromString(String versionString) { if (versionString == null) { return emptyVersionSpecification; } else { return new VersionSpecification(versionString); } }
/** * Finds the best (highest) matching version among a set. * * @return the matching version, or null if there are no matches */ protected static Version findBestMatch(VersionSpecification versionSpec, Set<Version> versions) { Version bestMatch=null; for (Version version : versions) { //No version is set if getSpecifiedMajor() == null //In that case we allow all versions if (version == null || !versionSpec.matches(version)) continue; if (bestMatch==null || bestMatch.compareTo(version)<0) bestMatch=version; } return bestMatch; }
private ComponentSpecification(SpecSplitter splitter) { this(splitter.name, VersionSpecification.fromString(splitter.version), splitter.namespace); }
int result = this.getMajor() - other.getMajor(); if (result != 0) return result; result = this.getMinor() - other.getMinor(); if (result != 0) return result; result = this.getMicro() - other.getMicro(); if (result != 0) return result; return getQualifier().compareTo(other.getQualifier());
/** Creates a version specification that only matches this version */ public VersionSpecification toSpecification() { if (this == emptyVersion) return VersionSpecification.emptyVersionSpecification; else { return new VersionSpecification(getMajor(), getMinor(), getMicro(), getQualifier()); } }
/** * Returns the bundle of a given name having the highest matching version * * @param id the id of the component to return. May not include a version, or include * an underspecified version, in which case the highest (mathcing) version which * does not contain a qualifier is returned * @return the bundle match having the highest version, or null if there was no matches */ public Bundle getBundle(ComponentSpecification id) { Bundle highestMatch=null; for (Bundle bundle : getBundles()) { assert bundle.getSymbolicName() != null : "ensureHasBundleSymbolicName not called during installation"; if ( ! bundle.getSymbolicName().equals(id.getName())) continue; if ( ! id.getVersionSpecification().matches(versionOf(bundle))) continue; if (highestMatch==null || versionOf(highestMatch).compareTo(versionOf(bundle))<0) highestMatch=bundle; } return highestMatch; }
VersionSpecification version6 = new VersionSpecification(6, 221);
/** * Checks if a componentId matches a given spec */ public boolean matches(ComponentId id) { boolean versionMatch = getVersionSpecification().matches(id.getVersion()); return getName().equals(id.getName()) && versionMatch && namespaceMatch(id.getNamespace()); }
RoutableFactory getFactory(Version version) { VersionSpecification versionSpec = version.toSpecification(); // Retrieve the factory with the highest version lower than or equal to actual version return factoryVersions.entrySet().stream() // Drop factories that have a higher version than actual version .filter(entry -> entry.getKey().compareTo(versionSpec) <= 0) // Get the factory with the highest version .max((entry1, entry2) -> entry1.getKey().compareTo(entry2.getKey())) .map(Map.Entry::getValue) // Return factory or null if no suitable factory found .orElse(null); } }
/** * Compares this <code>VersionSpecification</code> to another. * * <p> * A version is considered to be <b>equal to </b> another version if the * major, minor and micro components are equal and the qualifier component * is equal (using <code>String.equals</code>). * <p> * Note that two versions are only equal if they are equally specified, use * {@link #matches} to match a more specified version to a less specified. * * @param object The <code>VersionSpecification</code> object to be compared. * @return <code>true</code> if <code>object</code> is a * <code>VersionSpecification</code> and is equal to this object; * <code>false</code> otherwise. */ public boolean equals(Object object) { if (object == this) return true; if (!(object instanceof VersionSpecification)) return false; VersionSpecification other = (VersionSpecification) object; if ( ! equals(this.major,other.major)) return false; if ( ! equals(this.minor,other.minor)) return false; if ( ! equals(this.micro,other.micro)) return false; if ( ! equals(this.qualifier,other.qualifier)) return false; return true; }