/** * Compile a version format string into a compiled format. This method is * shorthand for:<pre>CompiledFormat.compile(format, 0, format.length())</pre>. * * @param format The format to compile. * @return The compiled format * @throws VersionFormatException If the format could not be compiled */ public static IVersionFormat compile(String format) throws VersionFormatException { return compile(format, 0, format.length()); }
static void toString(StringBuffer sb, Comparable<?>[] vector, Comparable<?> padValue, boolean rangeSafe) { int top = vector.length; if (top == 0) // Write one pad value as explicit. It will be considered // redundant and removed by the parser but the raw format // does not allow zero elements VersionFormat.rawToString(sb, rangeSafe, padValue == null ? MIN_VALUE : padValue); else { for (int idx = 0; idx < top; ++idx) { if (idx > 0) sb.append('.'); VersionFormat.rawToString(sb, rangeSafe, vector[idx]); } } if (padValue != null) { sb.append('p'); VersionFormat.rawToString(sb, rangeSafe, padValue); } }
/** * Returns the string representation of this compiled format */ public synchronized String toString() { if (fmtString == null) { StringBuffer sb = new StringBuffer(); toString(sb); } return fmtString; }
char c = version.charAt(pos); if (isDigit(c)) { return OSGiVersion.fromVector(VersionFormat.OSGI_FORMAT.parse(version, pos, maxPos)); vector = rawFmt.parse(version, pos, end); pos = end; if (pos == maxPos) fmt = VersionFormat.compile(version, pos, end); pos = end + 1; } catch (VersionFormatException e) { vector = fmt.parse(version, pos, maxPos);
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); }
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); }
/** * Compile a version format string into a compiled format. The parsing starts * at position start and ends at position end. The returned format is cached so * subsequent calls to this method using the same format string will yield the * same compiled format instance. * * @param format The format string to compile. * @param start Start position in the format string * @param end End position in the format string * @return The compiled format * @throws VersionFormatException If the format could not be compiled */ public static VersionFormat compile(String format, int start, int end) throws VersionFormatException { String fmtString = format.substring(start, end).intern(); synchronized (fmtString) { VersionFormat fmt = formatCache.get(fmtString); if (fmt == null) { VersionFormatParser parser = new VersionFormatParser(); fmt = new VersionFormat(parser.compile(format, start, end)); formatCache.put(fmtString, fmt); } return fmt; } }
writeQuotedString(sb, rangeSafe, s, otherQuote, idx, true); return;
/** * 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 int hashCode() { return 11 * toString().hashCode(); }
/** * Compile a version format string into a compiled format.. * * @param format The format to compile. * @return The compiled format * @throws VersionFormatException If the format could not be compiled */ public static IVersionFormat compile(String format) throws VersionFormatException { return VersionFormat.compile(format, 0, format.length()); }
void toString(StringBuffer sb) { if (ignored) { sb.append('='); sb.append('!'); sb.append(';'); } if (defaultValue != null) { sb.append('='); VersionFormat.rawToString(sb, false, defaultValue); sb.append(';'); } if (padValue != null) { sb.append('='); sb.append('p'); VersionFormat.rawToString(sb, false, padValue); sb.append(';'); } super.toString(sb); } }
public boolean equals(Object o) { return this == o || o instanceof VersionFormat && toString().equals(o.toString()); }
private static IVersionFormat parseFormat(String versionRange, int[] position) { int pos = VersionParser.skipWhite(versionRange, position[0]); if (!versionRange.startsWith("format(", pos)) //$NON-NLS-1$ return null; pos += 7; int end = VersionParser.findEndOfFormat(versionRange, pos, versionRange.length()); try { position[0] = end + 1; return VersionFormat.compile(versionRange, pos, end); } catch (VersionFormatException e) { throw new IllegalArgumentException(e.getMessage()); } }
private Object readResolve() { synchronized (formatCache) { String string = toString(); string = string.substring(7, string.length() - 1); // Strip of "format(" and ")" VersionFormat fmt = formatCache.get(string); if (fmt == null) { fmt = this; formatCache.put(string, fmt); } return fmt; } }