+ /**
+ * Returns the version component with the given index.
+ *
+ * @param index
+ * The index of the version component
+ * @return The version component
+ */
+ public int getComponent(int index) {
+ return components[index];
+ }
+
+ /**
+ * Parses a version from the given string.
+ *
+ * @param versionString
+ * The version string to parse
+ * @return The parsed version, or <code>null</code> if the string could not
+ * be parsed
+ */
+ public static Version parse(String versionString) {
+ String[] componentStrings = versionString.split("\\.");
+ int[] components = new int[componentStrings.length];
+ int index = -1;
+ for (String componentString : componentStrings) {
+ try {
+ components[++index] = Integer.parseInt(componentString);
+ } catch (NumberFormatException nfe1) {
+ return null;
+ }
+ }
+ return new Version(components);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuilder versionString = new StringBuilder();
+ for (int component : components) {
+ if (versionString.length() != 0) {
+ versionString.append('.');
+ }
+ versionString.append(component);
+ }
+ return versionString.toString();
+ }