@Test void compareVersions() { assertEquals(0, Utils.compareVersions("12.2.1.3.0", "12.2.1.3.0")); assertTrue(Utils.compareVersions("1.0", "1.1") < 0); assertTrue(Utils.compareVersions("1.1", "1.0") > 0); }
public static int compareVersions(String thisVersion, String otherVersion) { int result = 0; if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } String[] tmp = thisVersion.split("-"); String strippedThisVersion = tmp[0]; String[] thisVersionElements = strippedThisVersion.split("\\."); tmp = otherVersion.split("-"); String strippedOtherVersion = tmp[0]; String[] otherVersionElements = strippedOtherVersion.split("\\."); int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); if (thisVersionNumber > otherVersionNumber) { result = 1; break; } else if (thisVersionNumber < otherVersionNumber) { result = -1; break; } } if (result == 0 && thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { result = -1; } } if (result == 0) { int useCase = 0; if (thisVersion.indexOf('-') != -1) { useCase += 1; } if (otherVersion.indexOf('-') != -1) { useCase += 2; } switch (useCase) { case 0: break; case 1: result = -1; break; case 2: result = 1; break; case 3: String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); result = thisQualifier.compareTo(otherQualifier); break; default: break; } } return result; }
Utils { public static int compareVersions(String thisVersion, String otherVersion) { int result = 0; if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } String[] tmp = thisVersion.split("-"); String strippedThisVersion = tmp[0]; String[] thisVersionElements = strippedThisVersion.split("\\."); tmp = otherVersion.split("-"); String strippedOtherVersion = tmp[0]; String[] otherVersionElements = strippedOtherVersion.split("\\."); int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); if (thisVersionNumber > otherVersionNumber) { result = 1; break; } else if (thisVersionNumber < otherVersionNumber) { result = -1; break; } } if (result == 0 && thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { result = -1; } } if (result == 0) { int useCase = 0; if (thisVersion.indexOf('-') != -1) { useCase += 1; } if (otherVersion.indexOf('-') != -1) { useCase += 2; } switch (useCase) { case 0: break; case 1: result = -1; break; case 2: result = 1; break; case 3: String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); result = thisQualifier.compareTo(otherQualifier); break; default: break; } } return result; } }
Utils { public static int compareVersions(String thisVersion, String otherVersion) { int result = 0; if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } String[] tmp = thisVersion.split("-"); String strippedThisVersion = tmp[0]; String[] thisVersionElements = strippedThisVersion.split("\\."); tmp = otherVersion.split("-"); String strippedOtherVersion = tmp[0]; String[] otherVersionElements = strippedOtherVersion.split("\\."); int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); if (thisVersionNumber > otherVersionNumber) { result = 1; break; } else if (thisVersionNumber < otherVersionNumber) { result = -1; break; } } if (result == 0 && thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { result = -1; } } if (result == 0) { int useCase = 0; if (thisVersion.indexOf('-') != -1) { useCase += 1; } if (otherVersion.indexOf('-') != -1) { useCase += 2; } switch (useCase) { case 0: break; case 1: result = -1; break; case 2: result = 1; break; case 3: String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); result = thisQualifier.compareTo(otherQualifier); break; default: break; } } return result; } private  Utils(); }
Utils { public static int compareVersions(String thisVersion, String otherVersion) { int result = 0; if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } String[] tmp = thisVersion.split("-"); String strippedThisVersion = tmp[0]; String[] thisVersionElements = strippedThisVersion.split("\\."); tmp = otherVersion.split("-"); String strippedOtherVersion = tmp[0]; String[] otherVersionElements = strippedOtherVersion.split("\\."); int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); if (thisVersionNumber > otherVersionNumber) { result = 1; break; } else if (thisVersionNumber < otherVersionNumber) { result = -1; break; } } if (result == 0 && thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { result = -1; } } if (result == 0) { int useCase = 0; if (thisVersion.indexOf('-') != -1) { useCase += 1; } if (otherVersion.indexOf('-') != -1) { useCase += 2; } switch (useCase) { case 0: break; case 1: result = -1; break; case 2: result = 1; break; case 3: String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); result = thisQualifier.compareTo(otherQualifier); break; default: break; } } return result; } private  Utils(); static void copyResourceAsFile(String resourcePath, String destPath, boolean markExec); static void copyLocalFile(Path sourcePath, Path destPath, boolean markExec); static void copyLocalDirectory(Path sourcePath, Path destPath, boolean markExec); static void setProxyIfRequired(String httpProxyUrl, String httpsProxyUrl, String nonProxyHosts); static String writeDockerfile(String destPath, String template, DockerfileOptions options, boolean dryRun); static void writeResolvedFiles(List<Path> paths, List<Object> options); static void deleteFilesRecursively(String pathDir); static int compareVersions(String thisVersion, String otherVersion); static boolean isEmptyString(String s); static Properties getBaseImageProperties(String dockerImage, String tmpDir); static String findProxyUrl(String proxyUrl, String protocol); static String getPasswordFromInputs(String passwordStr, Path passwordFile, String passwordEnv); static String getEnvironmentProperty(String name); static String getBuildWorkingDir(); static String getOpatchVersionFromZip(String fileName); static boolean validatePatchIds(List<String> patches, boolean rigid); static void setOracleHome(List<Path> responseFiles, DockerfileOptions options); static void setInventoryLocation(String inventoryLocFile, DockerfileOptions options); static String getMessage(@PropertyKey(resourceBundle = "ImageTool") String key, Object... params); static void removeIntermediateDockerImages(String buildId); static String getPsuVersion(String lsInventory); @SafeVarargs static List<T> list(Collection<? extends T> start, T... elements); }
Utils { public static int compareVersions(String thisVersion, String otherVersion) { int result = 0; if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } String[] tmp = thisVersion.split("-"); String strippedThisVersion = tmp[0]; String[] thisVersionElements = strippedThisVersion.split("\\."); tmp = otherVersion.split("-"); String strippedOtherVersion = tmp[0]; String[] otherVersionElements = strippedOtherVersion.split("\\."); int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); if (thisVersionNumber > otherVersionNumber) { result = 1; break; } else if (thisVersionNumber < otherVersionNumber) { result = -1; break; } } if (result == 0 && thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { result = -1; } } if (result == 0) { int useCase = 0; if (thisVersion.indexOf('-') != -1) { useCase += 1; } if (otherVersion.indexOf('-') != -1) { useCase += 2; } switch (useCase) { case 0: break; case 1: result = -1; break; case 2: result = 1; break; case 3: String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); result = thisQualifier.compareTo(otherQualifier); break; default: break; } } return result; } private  Utils(); static void copyResourceAsFile(String resourcePath, String destPath, boolean markExec); static void copyLocalFile(Path sourcePath, Path destPath, boolean markExec); static void copyLocalDirectory(Path sourcePath, Path destPath, boolean markExec); static void setProxyIfRequired(String httpProxyUrl, String httpsProxyUrl, String nonProxyHosts); static String writeDockerfile(String destPath, String template, DockerfileOptions options, boolean dryRun); static void writeResolvedFiles(List<Path> paths, List<Object> options); static void deleteFilesRecursively(String pathDir); static int compareVersions(String thisVersion, String otherVersion); static boolean isEmptyString(String s); static Properties getBaseImageProperties(String dockerImage, String tmpDir); static String findProxyUrl(String proxyUrl, String protocol); static String getPasswordFromInputs(String passwordStr, Path passwordFile, String passwordEnv); static String getEnvironmentProperty(String name); static String getBuildWorkingDir(); static String getOpatchVersionFromZip(String fileName); static boolean validatePatchIds(List<String> patches, boolean rigid); static void setOracleHome(List<Path> responseFiles, DockerfileOptions options); static void setInventoryLocation(String inventoryLocFile, DockerfileOptions options); static String getMessage(@PropertyKey(resourceBundle = "ImageTool") String key, Object... params); static void removeIntermediateDockerImages(String buildId); static String getPsuVersion(String lsInventory); @SafeVarargs static List<T> list(Collection<? extends T> start, T... elements);  }