Here you can find the source of versionStringToNumber(String versionStr)
Parameter | Description |
---|---|
versionStr | A string of type "X.Y.Z suffix". The suffix is ignored, Y and Z are optional. Y and Z must not be larger than 99. |
public static int versionStringToNumber(String versionStr)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww.ja va 2s .c o m * Converts a version string, such as "1.12.5 alpha" to a number. * @param versionStr A string of type "X.Y.Z suffix". The suffix is ignored, * Y and Z are optional. Y and Z must not be larger than 99. * @return A number. For the example string "1.12.5 alpha", this is * 1 * 100 * 100 + 12 * 100 + 5; */ public static int versionStringToNumber(String versionStr) { // remove " alpha" at the end of the string String[] strs = versionStr.trim().split(" "); // split into numbers strs = strs[0].split("."); // the following could be a little more elegant... if (strs.length == 1) { return Integer.parseInt(strs[0]) * 100 * 100; } if (strs.length == 2) { if (Integer.parseInt(strs[1]) > 99) { throw new IllegalArgumentException("subversion too large"); } return Integer.parseInt(strs[0]) * 100 * 100 + Integer.parseInt(strs[1]) * 100; } if (strs.length == 3) { if (Integer.parseInt(strs[1]) > 99 || Integer.parseInt(strs[2]) > 99) { throw new IllegalArgumentException("subversion too large"); } return Integer.parseInt(strs[0]) * 100 * 100 + Integer.parseInt(strs[1]) * 100 + Integer.parseInt(strs[2]); } return 0; } }