private Object readResolve() { VersionVector vv = this; // Preserve the emptyString singleton int idx = vector.length; while (--idx >= 0) if (MINS_VALUE.equals(vector[idx])) vector[idx] = MINS_VALUE; if (MINS_VALUE.equals(padValue)) vv = new VersionVector(vector, MINS_VALUE); return vv; } }
public int compareTo(VersionVector ov) { if (ov == this) return 0; return compare(vector, padValue, ov.vector, ov.padValue); }
static int compare(Comparable<?>[] vectorA, Comparable<?> padA, Comparable<?>[] vectorB, Comparable<?> padB) { int top = vectorA.length; if (top > vectorB.length) top = vectorB.length; for (int idx = 0; idx < top; ++idx) { int cmp = compareSegments(vectorA[idx], vectorB[idx]); if (cmp != 0) return cmp; } // All elements compared equal up to this point. Check // pad values if (top < vectorA.length) return (padB == null) ? 1 : compareReminder(top, vectorA, padA, padB); if (top < vectorB.length) return (padA == null) ? -1 : -compareReminder(top, vectorB, padB, padA); // Lengths are equal. Compare pad values return padA == null ? (padB == null ? 0 : -1) : (padB == null ? 1 : compareSegments(padA, padB)); }
/** * Append the string representation of this instance to the * <code>sb</code> buffer. * @param sb The buffer to append to */ public void toString(StringBuffer sb) { toString(sb, vector, padValue, false); }
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 boolean equals(Object o) { if (o == this) return true; if (!(o instanceof VersionVector)) return false; VersionVector ov = (VersionVector) o; return equals(vector, padValue, ov.vector, ov.padValue); }
public int hashCode() { return hashCode(vector, padValue); }
private static int compareReminder(int idx, Comparable<?>[] vector, Comparable<?> padValue, Comparable<?> othersPad) { int cmp; for (cmp = 0; idx < vector.length && cmp == 0; ++idx) cmp = compareSegments(vector[idx], othersPad); if (cmp == 0) cmp = (padValue == null) ? -1 : compareSegments(padValue, othersPad); return cmp; }
static int compareSegments(Comparable<?> a, Comparable<?> b) { if (a == b) return 0; if (a instanceof Integer && b instanceof Integer) { int ai = ((Integer) a).intValue(); int bi = ((Integer) b).intValue(); return ai > bi ? 1 : (ai < bi ? -1 : 0); } if (a instanceof String && b instanceof String) return ((String) a).compareTo((String) b); if (a == MAX_VALUE || a == MIN_VALUE || a == MAXS_VALUE) return ((MinMaxComparable) a).compareTo(b); if (b == MAX_VALUE || b == MIN_VALUE || b == MAXS_VALUE) return -((MinMaxComparable) b).compareTo(a); if (a instanceof Integer) return 1; if (b instanceof Integer) return -1; if (a instanceof VersionVector) return (b instanceof VersionVector) ? ((VersionVector) a).compareTo((VersionVector) b) : 1; if (b instanceof VersionVector) return -1; if (a instanceof EnumDefinition.EnumSegment) return (b instanceof EnumDefinition.EnumSegment) ? ((EnumDefinition.EnumSegment) a).compareTo((EnumDefinition.EnumSegment) b) : 1; if (b instanceof EnumDefinition.EnumSegment) return -1; throw new IllegalArgumentException(); }
/** * Append the string representation of this instance to the * <code>sb</code> buffer. * @param sb The buffer to append to * @param rangeSafe If <code>true</code>, the range delimiters will be escaped * with backslash. */ void toString(StringBuffer sb, boolean rangeSafe) { toString(sb, vector, padValue, rangeSafe); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof BasicVersion)) return false; BasicVersion ov = (BasicVersion) o; return VersionVector.equals(vector, padValue, ov.getVector(), ov.getPad()); }
public int hashCode() { return VersionVector.hashCode(vector, padValue); }
/** * Appends the raw format for this version onto the <code>sb</code> StringBuffer. * @param sb The buffer that will receive the raw string format * @param rangeSafe Set to <code>true</code> if range delimiters should be escaped */ public void rawToString(StringBuffer sb, boolean rangeSafe) { VersionVector.toString(sb, vector, padValue, rangeSafe); }
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); }
return new VersionVector(rawList.toArray(new Comparable[rawList.size()]), pad);
public int compareTo(Version v) { BasicVersion ov = (BasicVersion) v; return VersionVector.compare(vector, padValue, ov.getVector(), ov.getPad()); } }
public String toString() { StringBuffer sb = new StringBuffer(); toString(sb); return sb.toString(); }
boolean parseOne(List<Comparable<?>> segments, String version, int maxPos, TreeInfo info) { if (array) { ArrayList<Comparable<?>> subSegs = new ArrayList<Comparable<?>>(); boolean success = fragments[0].getQualifier().parse(fragments, 0, subSegs, version, maxPos, info); if (!success || subSegs.isEmpty()) return false; Comparable<?> padValue = info.getPadValue(); if (padValue != null) info.setPadValue(null); // Prevent outer group from getting this. else padValue = getPadValue(); padValue = VersionParser.removeRedundantTrail(segments, padValue); segments.add(new VersionVector(subSegs.toArray(new Comparable[subSegs.size()]), padValue)); return true; } if (fragments[0].getQualifier().parse(fragments, 0, segments, version, maxPos, info)) { Comparable<?> padValue = getPadValue(); if (padValue != null) info.setPadValue(padValue); return true; } return false; }
static void rawToString(StringBuffer sb, boolean forRange, Comparable<?> e) { if (e instanceof String) { writeQuotedString(sb, forRange, (String) e, '\'', 0, false); } else if (e instanceof VersionVector) { sb.append('<'); ((VersionVector) e).toString(sb, forRange); sb.append('>'); } else if (e instanceof EnumDefinition.EnumSegment) ((EnumDefinition.EnumSegment) e).toString(sb); else sb.append(e); }
/** * Appends the string representation of this version onto the * <code>sb</code> StringBuffer. * @param sb The buffer that will receive the version string */ public void toString(StringBuffer sb) { if (this == emptyVersion) sb.append("0.0.0"); //$NON-NLS-1$ else { sb.append(RAW_PREFIX); VersionVector.toString(sb, vector, padValue, false); if (format != null || original != null) { sb.append('/'); if (format != null) format.toString(sb); if (original != null) { sb.append(':'); originalToString(sb, false); } } } }