ODPSConsoleUtils { public static int compareVersion(String left, String right) { if (left.equals(right)) { return 0; } String pattern = "[\\\\.\\\\_\\\\-]"; String[] leftArray = left.split(pattern); String[] rightArray = right.split(pattern); int length = leftArray.length < rightArray.length ? leftArray.length : rightArray.length; for (int i = 0; i < length; i++) { if (rightArray[i].equalsIgnoreCase(leftArray[i])) { continue; } if (org.apache.commons.lang.StringUtils.isNumeric(rightArray[i]) && org.apache.commons.lang.StringUtils.isNumeric(leftArray[i])) { if (Integer.parseInt(rightArray[i]) > Integer.parseInt(leftArray[i])) { return -1; } else if (Integer.parseInt(rightArray[i]) < Integer.parseInt(leftArray[i])) { return 1; } } else { int res = leftArray[i].compareToIgnoreCase(rightArray[i]); return res > 0 ? 1 : res; } } if (leftArray.length == rightArray.length) { return 0; } else { return leftArray.length < rightArray.length ? -1 : 1; } }  static String formatDate(Date date); @SuppressWarnings("resource") static void formaterTable(List<String[]> contentList, int[] columnPercent, int width); static void formaterTableRow(String[] str, int[] columnPercent, int width); static int getConsoleWidth(); static boolean isWindows(); static String getConfigFilePath(); static String getMvnVersion(); static String getUserAgent(); static boolean containsHanBlock(String s); static String shiftOption(List<String> optionList, String option); static TablePart getTablePart(String cmd); static TablePart getTablePartFromPubCommand(String cmd); static String[] parseTableSpec(String str); static String generateLogView(Odps odps, Instance instance, ExecutionContext context); static String[] translateCommandline(String line); synchronized static String runCommand(AbstractCommand command); static void checkThreadInterrupted(); static ODPSConsoleReader getOdpsConsoleReader(); static String safeGetString(LazyLoad resource, String methodName); static String safeGetDateString(LazyLoad resource, String methodName); static Object safeGetObject(LazyLoad resource, String methodName); static int compareVersion(String left, String right); static Map<String, Integer> getDisplayWidth(List<Column> columns,
                                                     List<Column> partitionsColumns,
                                                     List<String> selectColumns); static String makeOutputFrame(Map<String, Integer> displayWidth); static String makeTitle(List<Column> columns, Map<String, Integer> displayWidth); static final SimpleDateFormat DATE_FORMAT; }
@Test public void testCompareVersion() throws Exception { Assert.assertEquals(0, ODPSConsoleUtils.compareVersion("0.24.0", "0.24.0")); Assert.assertEquals(-1, ODPSConsoleUtils.compareVersion("0.24.0", "0.24.1")); Assert.assertEquals(1, ODPSConsoleUtils.compareVersion("0.24.1", "0.24.0")); Assert.assertEquals(-1, ODPSConsoleUtils.compareVersion("0_24-0", "0.24.1")); Assert.assertEquals(0, ODPSConsoleUtils.compareVersion("0.24.0-snapshot", "0.24.0-SNAPSHOT")); Assert.assertEquals(-1, ODPSConsoleUtils.compareVersion("0.24.0-snapshot", "0.24.0-SNAPSHOT_big")); Assert.assertEquals(1, ODPSConsoleUtils.compareVersion("0.24.0-snapshot", "0.24.0")); Assert.assertEquals(1, ODPSConsoleUtils.compareVersion("0.24.0-snapshot", "0.24.0_p")); Assert.assertEquals(-1, ODPSConsoleUtils.compareVersion("0.24.0-snapshot", "0.24-0_t")); }