private Object readResolve() { OSGiVersion v = this; // Preserve the empty string singleton. if (qualifier.equals(VersionVector.MINS_VALUE)) v = new OSGiVersion(major, minor, micro, VersionVector.MINS_VALUE); return v; } }
public void toString(StringBuffer sb) { sb.append(major); sb.append('.'); sb.append(minor); sb.append('.'); sb.append(micro); if (qualifier != VersionVector.MINS_VALUE) { sb.append('.'); sb.append(getQualifier()); } }
public OSGiVersion(int major, int minor, int micro, Comparable<? extends Object> qualifier) { this.major = major; this.minor = minor; this.micro = micro; if (!isValidOSGiQualifier(qualifier)) throw new IllegalArgumentException(NLS.bind(Messages._0_is_not_a_valid_qualifier_in_osgi_1, "qualifier", this)); //$NON-NLS-1$ //intern the qualifier string to avoid duplication if (qualifier instanceof String) qualifier = ((String) qualifier).intern(); this.qualifier = qualifier; }
/** * Parse a version string using the {@link #RAW_FORMAT} parser. * * @param version The version to parse. * @param originalFormat The original format to assign to the created version. Can be <code>null</code>. * @param original The original version string to assign to the created version. Can be <code>null</code>. * @return A created version * @throws IllegalArgumentException If the version string could not be parsed. */ public static BasicVersion parseRaw(String version, IVersionFormat originalFormat, String original) { List<Comparable<?>> vector = RAW_FORMAT.parse(version, 0, version.length()); return (originalFormat == OSGI_FORMAT) ? OSGiVersion.fromVector(vector) : OmniVersion.fromVector(vector, originalFormat, original); }
public boolean equals(Object object) { if (object == this) return true; if (!(object instanceof OSGiVersion)) { if (object instanceof BasicVersion) { BasicVersion ov = (BasicVersion) object; return VersionVector.equals(getVector(), null, ov.getVector(), ov.getPad()); } return false; } OSGiVersion other = (OSGiVersion) object; return micro == other.micro && minor == other.minor && major == other.major && qualifier.equals(other.qualifier); }
public String getOriginal() { return toString(); }
public Version parse(String version) { List<Comparable<?>> vector = parse(version, 0, version.length()); return (this == OSGI_FORMAT) ? OSGiVersion.fromVector(vector) : OmniVersion.fromVector(vector, this, version); }
public int compareTo(Version v) { int result; if (!(v instanceof OSGiVersion)) { BasicVersion ov = (BasicVersion) v; result = VersionVector.compare(getVector(), null, ov.getVector(), ov.getPad()); } else { OSGiVersion ov = (OSGiVersion) v; result = major - ov.major; if (result == 0) { result = minor - ov.minor; if (result == 0) { result = micro - ov.micro; if (result == 0) result = VersionVector.compareSegments(qualifier, ov.qualifier); } } } return result; }
public void originalToString(StringBuffer sb, boolean rangeSafe) { toString(sb); }
/** * Creates an OSGi version identifier from the specified components. * * @param major Major component of the version identifier. * @param minor Minor component of the version identifier. * @param micro Micro component of the version identifier. * @param qualifier Qualifier component of the version identifier. If * <code>null</code> is specified, then the qualifier will be set to * the empty string. * @throws IllegalArgumentException If the numerical components are negative * or the qualifier string is invalid. */ public static Version createOSGi(int major, int minor, int micro, String qualifier) { Comparable<?> logicQualifier; if (qualifier == null || qualifier.length() == 0) { if (major == 0 && minor == 0 && micro == 0) return emptyVersion; logicQualifier = VersionVector.MINS_VALUE; // So that we can do identity compare } else if (qualifier.equals(IVersionFormat.DEFAULT_MAX_STRING_TRANSLATION)) logicQualifier = VersionVector.MAXS_VALUE; else logicQualifier = qualifier; return new OSGiVersion(major, minor, micro, logicQualifier); }
char c = version.charAt(pos); if (isDigit(c)) { return OSGiVersion.fromVector(VersionFormat.OSGI_FORMAT.parse(version, pos, maxPos)); return fmt == VersionFormat.OSGI_FORMAT ? OSGiVersion.fromVector(vector) : OmniVersion.fromVector(vector, fmt, null); return fmt == VersionFormat.OSGI_FORMAT ? OSGiVersion.fromVector(vector) : OmniVersion.fromVector(vector, fmt, version.substring(pos));
/** * Checks if this version is in compliance with the OSGi version spec. * @return A flag indicating whether the version is OSGi compatible or not. */ public boolean isOSGiCompatible() { if (vector.length < 3 || vector.length > 4) return (this == emptyVersion || this == MAX_VERSION); if (getPad() != null) return false; for (int i = 0; i < 3; ++i) { Object e = vector[i]; if (!(e instanceof Integer && ((Integer) e).intValue() >= 0)) return false; } if (vector.length == 3) return true; // No qualifier. Still compatible return OSGiVersion.isValidOSGiQualifier(vector[3]); }
static BasicVersion fromVector(List<Comparable<?>> vector) { int vtop = vector.size() - 1; Comparable<?> pad = vector.get(vtop); if (vtop != 4) { if (vtop == 0) { if (pad == null) return (BasicVersion) emptyVersion; if (pad == VersionVector.MAX_VALUE) return (BasicVersion) MAX_VERSION; } throw new IllegalArgumentException(); } int major = ((Integer) vector.get(0)).intValue(); int minor = ((Integer) vector.get(1)).intValue(); int micro = ((Integer) vector.get(2)).intValue(); Comparable<?> qualifier = vector.get(3); return (major == 0 && minor == 0 && micro == 0 && qualifier == VersionVector.MINS_VALUE) ? (BasicVersion) emptyVersion : new OSGiVersion(major, minor, micro, qualifier); }