XFSUtils { public static int getVersion(String version) { int result = 0; int endIndex = version.indexOf('.'); if (endIndex >= 0) { String minorVersion = version.substring(endIndex + 1); if (minorVersion.length() > 0) { try { int minor = Integer.parseInt(minorVersion); if (minor < 0 || minor > 255) { throw new IllegalArgumentException("Minor version out of range. Value:\"" + minor + "\""); } minor <<= 8; result |= minor; } catch (NumberFormatException e) { e.printStackTrace(); } } } else { endIndex = version.length(); } String majorVersion = version.substring(0, endIndex); if (majorVersion.length() > 0) { int major = Integer.parseInt(majorVersion); if (major < 0 || major > 255) { throw new IllegalArgumentException("Major version out of range. Value:\"" + majorVersion + "\""); } result |= (major & 0xFF); } return result; }  static int getVersionsRequired(String lowestVersion, String highestVersion); static int getVersion(String version); static String getVersionAsString(int i);  }
@Test public void test1_11() { assertEquals(0x0B01, XFSUtils.getVersion("1.11")); }
@Test public void testGetVersion() { assertEquals(0x0001, XFSUtils.getVersion("1.0")); assertEquals(0x0001, XFSUtils.getVersion("1.")); assertEquals(0x0000, XFSUtils.getVersion("0.")); assertEquals(0x0B00, XFSUtils.getVersion(".11")); try { System.out.println(XFSUtils.getVersion("270")); fail(); } catch (IllegalArgumentException e) { } try { System.out.println(XFSUtils.getVersion("-1")); fail(); } catch (IllegalArgumentException e) { } try { System.out.println(XFSUtils.getVersion(".256")); fail(); } catch (IllegalArgumentException e) { } }