List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:Main.java
private static String mixStep(String str) { if (str == null || str.isEmpty()) { return ""; }//from w w w . j av a2 s . c om if (str.length() == 1) { return str; } if (str.length() == 2) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } StringBuilder sb = new StringBuilder(); String char1 = String.valueOf(str.charAt(0)); String char2 = String.valueOf(str.charAt(1)); String char3 = String.valueOf(str.charAt(2)); if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) < 0)) { return sb.append(mixStep(str.substring(2))).append(str.charAt(1)).append(str.charAt(0)).toString(); } else if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) > 0)) { String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString(); return sb.append(str.charAt(1)).append(mixReverse).append(str.charAt(0)).toString(); } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) > 0)) { return sb.append(str.charAt(0)).append(mixStep(str.substring(2))).append(str.charAt(1)).toString(); } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) < 0)) { String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString(); return sb.append(str.charAt(0)).append(mixReverse).append(str.charAt(1)).toString(); } return sb.append(str.charAt(1)).append(str.charAt(0)).append(mixStep(str.substring(2))).toString(); }
From source file:com.newlandframework.avatarmq.consumer.ConsumerContext.java
public static int getClustersStat(String clusters) { Predicate predicate = new Predicate() { public boolean evaluate(Object object) { String clustersId = ((ClustersState) object).getClusters(); return clustersId.compareTo(clusters) == 0; }/*from w w w .ja va 2 s .c om*/ }; Iterator iterator = new FilterIterator(stateArray.iterator(), predicate); ClustersState state = null; while (iterator.hasNext()) { state = (ClustersState) iterator.next(); break; } return (state != null) ? state.getState() : 0; }
From source file:Main.java
public static Comparator<String> createFuzzyKeyComparator() { return new Comparator<String>() { @Override//from w w w.j a v a 2 s .c o m public int compare(String key1, String key2) { String imageUri1 = key1.substring(0, key1.lastIndexOf(URI_AND_SIZE_SEPARATOR)); String imageUri2 = key2.substring(0, key2.lastIndexOf(URI_AND_SIZE_SEPARATOR)); return imageUri1.compareTo(imageUri2); } }; }
From source file:Main.java
public static int safeCompare(String f1, String f2) { if (f1 == null && f2 == null) return 0; if (f1 == null && f2 != null) return -1; if (f1 != null && f2 == null) return 1; return f1.compareTo(f2); }
From source file:com.clustercontrol.accesscontrol.factory.LoginUserSelector.java
/** * ???<BR>/*from w w w . j ava 2 s . c om*/ * * @return * @throws HinemosUnknown */ public static UserInfo getUserInfo(String userId) throws HinemosUnknown, UserNotFound { UserInfo info = null; if (userId != null && userId.compareTo("") != 0) { try { // ? info = QueryUtil.getUserPK(userId); } catch (UserNotFound e) { throw e; } catch (Exception e) { m_log.warn("getUserInfo() failure to get user. : userId = " + userId, e); throw new HinemosUnknown(e.getMessage() + " : failure to get user.", e); } } return info; }
From source file:jp.co.opentone.bsol.framework.core.util.ArgumentValidator.java
/** * ?????????.//from w w w . j av a2 s. c om * ???????????IllegalArgumentException??. * ??????null??IllegalArgumentException??. * @param arg ? * @param compValue ? * @param name ??? */ public static void validateEquals(String arg, String compValue, String name) { validateNotNull(arg); validateNotNull(compValue); if (0 != arg.compareTo(compValue)) { String n = getName(name); throw new IllegalArgumentException(n + " should be equal to compare value"); } }
From source file:com.groupon.odo.proxylib.Utils.java
/** * Returns the port as configured by the system variables, fallback is the default port value * * @param portIdentifier - SYS_*_PORT defined in Constants * @return//w w w .j av a2 s . c o m */ public static int getSystemPort(String portIdentifier) { int defaultPort = 0; if (portIdentifier.compareTo(Constants.SYS_API_PORT) == 0) { defaultPort = Constants.DEFAULT_API_PORT; } else if (portIdentifier.compareTo(Constants.SYS_DB_PORT) == 0) { defaultPort = Constants.DEFAULT_DB_PORT; } else if (portIdentifier.compareTo(Constants.SYS_FWD_PORT) == 0) { defaultPort = Constants.DEFAULT_FWD_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTP_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTP_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTPS_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTPS_PORT; } else { return defaultPort; } String portStr = System.getenv(portIdentifier); return (portStr == null || portStr.isEmpty()) ? defaultPort : Integer.valueOf(portStr); }
From source file:loci.plugins.util.LibraryChecker.java
/** * Returns true the current ImageJ version is greater than or equal to the * specified version. Displays the given warning message with the specified * title if the current version is too old. *//*from w w w .j av a 2 s . co m*/ public static boolean checkImageJ(String target, String msg, String title) { boolean success; try { String current = IJ.getVersion(); success = current != null && current.compareTo(target) >= 0; } catch (NoSuchMethodError err) { success = false; } if (!success) IJ.error(title, msg); return success; }
From source file:com.github.ipaas.ideploy.plugin.core.Comparetor.java
/** * ??,?//from w ww.j ava 2 s .c om * * @param pathInfo * @param userInfo * @return */ public static String doAtion(PathInfo pathInfo, UserInfo userInfo) { if (userInfo.getUrl() == null || userInfo.getUrl().equals("")) { ConsoleHandler.error("??"); return null; } else if (userInfo.getEmail() == null || userInfo.getEmail().equals("")) { ConsoleHandler.error("????"); return null; } else if (userInfo.getPassword() == null || userInfo.getPassword().equals("")) { ConsoleHandler.error("???"); return null; } ConsoleHandler.info(":" + userInfo.getEmail()); ConsoleHandler.info("?:" + pathInfo.getGroupId()); TreeNode srcRoot = getSrcTree(pathInfo); TreeNode targetRoot = getTargetTree(userInfo, pathInfo); if (srcRoot != null && targetRoot != null) { List<String> result = null; if (targetRoot.getChildSet() == null || targetRoot.getChildSet().size() == 0) { result = new ArrayList<String>(); result.add("all"); } else { result = FileTreeNodeComparetor.compare(srcRoot, targetRoot); } Collections.sort(result, new Comparator<String>() { public int compare(String str1, String str2) { return str1.compareTo(str2); } }); if (result != null && result.size() > 0) { ConfigFileFilter filter = new ConfigFileFilter(userInfo.getPatternJsonList()); result = filter.filterResult(result); } if (result != null && result.size() > 0) { String path = genZipPackage(result, pathInfo); ConsoleHandler.info("? " + path + " ?!"); return path; } else { ConsoleHandler.info("?!"); } } else { ConsoleHandler.info("???!"); } return null; }
From source file:org.onosproject.tvue.TopologyResource.java
static String key(Link link) { String s = id(link.src()); String d = id(link.dst()); return s.compareTo(d) > 0 ? d + s : s + d; }