List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:com.clustercontrol.accesscontrol.factory.LoginUserModifier.java
/** * ??<BR>//from w w w . j av a2 s . c o m * * @param userInfo ?? * @param modifyUserId ID * @param isNew true:??false: * @throws UserDuplicate * @throws UserNotFound * @throws UnEditableUser * @throws HinemosUnknown */ public static void modifyUserInfo(UserInfo userInfo, String modifyUserId, boolean isNew) throws UserDuplicate, UserNotFound, UnEditableUser, HinemosUnknown { if (userInfo == null || modifyUserId == null || modifyUserId.compareTo("") == 0) { return; } m_log.debug("modifyUserInfo() start (roleId = " + userInfo.getUserId() + ", modifyUserId = " + modifyUserId + ", isNew = " + isNew + ")"); try { long currentTimeMillis = HinemosTime.currentTimeMillis(); JpaTransactionManager jtm = new JpaTransactionManager(); UserInfo userInfoEntity = null; if (isNew) { // ? // ?? jtm.checkEntityExists(UserInfo.class, userInfo.getUserId()); // userInfo.setCreateUserId(modifyUserId); userInfo.setCreateDate(currentTimeMillis); // ALL_USERS RoleInfo roleInfo = QueryUtil.getRolePK(RoleIdConstant.ALL_USERS); List<UserInfo> userList = roleInfo.getUserInfoList(); userList.add(userInfo); roleInfo.setUserInfoList(userList); userInfo.setRoleList(new ArrayList<RoleInfo>()); userInfo.getRoleList().add(roleInfo); userInfo.setUserType(UserTypeConstant.LOGIN_USER); // ?? userInfo.setModifyUserId(modifyUserId); userInfo.setModifyDate(HinemosTime.currentTimeMillis()); jtm.getEntityManager().persist(userInfo); // ? if (userInfo.getRoleList() != null) { for (RoleInfo role : userInfo.getRoleList()) { m_log.info("userInfo.getRoleList(): userid=" + userInfo.getUserId() + ", roleid=" + role.getRoleId()); } } } else { // // ?? userInfoEntity = QueryUtil.getUserPK(userInfo.getUserId()); UserInfo modifyUserInfoEntity = QueryUtil.getUserPK(modifyUserId); // ???(???? if (userInfoEntity.getUserType().equals(UserTypeConstant.SYSTEM_USER) && !modifyUserInfoEntity.getUserType().equals(UserTypeConstant.SYSTEM_USER)) { throw new UnEditableUser(); } else if (userInfoEntity.getUserType().equals(UserTypeConstant.INTERNAL_USER)) { throw new UnEditableUser(); } // userInfoEntity.setUserName(userInfo.getUserName()); userInfoEntity.setDescription(userInfo.getDescription()); userInfoEntity.setMailAddress(userInfo.getMailAddress()); userInfoEntity.setModifyUserId(modifyUserId); userInfoEntity.setModifyDate(HinemosTime.currentTimeMillis()); // ? if (userInfoEntity.getRoleList() != null) { for (RoleInfo role : userInfoEntity.getRoleList()) { m_log.info("userInfo.getRoleList(): userid=" + userInfo.getUserId() + ", roleid=" + role.getRoleId()); } } } m_log.info("successful in modifing a user. (userId = " + userInfo.getUserId() + ")"); } catch (UserNotFound | UnEditableUser e) { throw e; } catch (EntityExistsException e) { m_log.info("modifyUserInfo() failure to add a user. a user'id is duplicated. (userId = " + userInfo.getUserId() + ")"); throw new UserDuplicate(e.getMessage(), e); } catch (Exception e) { m_log.warn("modifyUserInfo() failure to modify a user. (userId = " + userInfo.getUserId() + ")", e); throw new HinemosUnknown("failure to modify a user. (userId = " + userInfo.getUserId() + ")", e); } }
From source file:com.clustercontrol.accesscontrol.factory.LoginUserModifier.java
/** * ?<BR>// w w w . j a v a 2 s. c o m * * @param userId ?ID * @param modifyUserId ID * @throws UserNotFound * @throws UnEditableUser * @throws UsedUser * @throws HinemosUnknown */ public static void deleteUserInfo(String userId, String modifyUserId) throws UserNotFound, UsedUser, UnEditableUser, HinemosUnknown { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); if (userId != null && userId.compareTo("") != 0 && modifyUserId != null && modifyUserId.compareTo("") != 0) { try { // ???????????? if (userId.compareTo(modifyUserId) == 0) { throw new UsedUser("a user will be deleted is equal to current login user."); } // ???? UserInfo user = QueryUtil.getUserPK(userId); // ???? if (user != null && !user.getUserType().equals(UserTypeConstant.LOGIN_USER)) { throw new UnEditableUser(); } // ? user.unchainRoleInfoList(); // ? em.remove(user); } catch (UserNotFound | UnEditableUser e) { throw e; } catch (UsedUser e) { m_log.info("deleteUserInfo() failure to delete a user. (userId = " + userId + ") : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } catch (Exception e) { m_log.warn("deleteUserInfo() failure to delete a user. (userId = " + userId + ")", e); throw new HinemosUnknown(e.getMessage(), e); } m_log.info("successful in deleting a user. (userId = " + userId + ")"); } }
From source file:dk.netarkivet.common.utils.cdx.BinSearch.java
/** Our own comparison function. Right now just does prefix match. * * @param line A line to find the prefix of * @param pattern The prefix to find.//w w w . jav a 2 s .com * @return A result equivalent to String.compareTo, but only for a prefix. */ private static int compare(String line, String pattern) { String start = line.substring(0, Math.min(pattern.length(), line.length())); int cmp = start.compareTo(pattern); return cmp; }
From source file:com.jaeksoft.searchlib.util.StringUtils.java
public final static int compareNullString(final String v1, final String v2) { if (v1 == null) { if (v2 == null) return 0; return -1; }/*from www.ja va2s.co m*/ if (v2 == null) return 1; return v1.compareTo(v2); }
From source file:com.p5solutions.core.utils.Comparison.java
/** * Compare to./* w w w . j av a2 s. c o m*/ * * @param a * the a * @param b * the b * @return the int */ public static int compareTo(String a, String b) { // if both values are not null then compare them if (a != null && b != null) { return a.compareTo(b); } // if 'b' == null then 'a' must be greater than b if (a != null && b == null) { return 1; } // if 'a' == null then 'b' must be greater than a if (b != null && a == null) { return -1; } // otherwise they are equal return 0; }
From source file:fr.gouv.culture.thesaurus.util.TextUtils.java
/** * Compare deux chanes de caractres, en tolrant les pointeurs * <code>null</code>. La comparaison s'effectue sur l'ordre lexicographique * des chanes. <code>null</code> est plus petit que n'importe quelle autre * chane, l'exception d'un autre <code>null</code> (avec lequel il est * gal).// w w w. j a va2 s .c o m * * @param firstString * Premire chane, ou <code>null</code> * @param secondString * Seconde chane, ou <code>null</code> * @return <code>-1</code> si la premire chane est prioritaire sur la * seconde, <code>1</code> si c'est la seconde qui est prioritaire * sur la premire, <code>0</code> si les chanes sont gales */ public static int compareStrings(final String firstString, final String secondString) { int comparison; if (firstString == null) { comparison = (secondString == null) ? 0 : -1; } else { comparison = (secondString == null) ? 1 : firstString.compareTo(secondString); } return comparison; }
From source file:control.Functions.java
public static int compareSampleCodes(String c1, String c2) { if (!c1.startsWith("Q") || c1.contains("ENTITY") || !c2.startsWith("Q") || c2.contains("ENTITY")) return c1.compareTo(c2); try {// www. j av a2s . c o m // compares sample codes by projects, ending letters (999A --> 001B) and numbers (001A --> // 002A) int projCompare = c1.substring(0, 5).compareTo(c2.substring(0, 5)); int numCompare = c1.substring(5, 8).compareTo(c2.substring(5, 8)); int letterCompare = c1.substring(8, 9).compareTo(c2.substring(8, 9)); if (projCompare != 0) return projCompare; else { if (letterCompare != 0) return letterCompare; else return numCompare; } } catch (Exception e) { logger.warn("Could not split code " + c1 + " or " + c2 + ". Falling back to primitive lexicographical comparison."); } return c1.compareTo(c2); }
From source file:net.sourceforge.eclipsetrader.trading.internal.watchlist.ColumnRegistry.java
public static IConfigurationElement[] getProviders() { List list = new ArrayList(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { String s1 = ""; String s2 = ""; if (((IConfigurationElement) o1).getAttribute("name") != null) s1 = ((IConfigurationElement) o1).getAttribute("name"); if (((IConfigurationElement) o2).getAttribute("name") != null) s2 = ((IConfigurationElement) o2).getAttribute("name"); return s1.compareTo(s2); }//from w w w .j a v a 2 s . com }); return (IConfigurationElement[]) list.toArray(new IConfigurationElement[list.size()]); }
From source file:com.ebay.erl.mobius.core.model.TupleColumnComparator.java
private static int compare(String v1, String v2) { return v1.compareTo(v2); }
From source file:IrqaQuery.java
public static void get_sentence_from_json(JSONArray raw_list, String question, String docid, BufferedWriter out) throws Exception { for (Object o : raw_list) { JSONObject rl = (JSONObject) o;// w ww. ja v a 2s. co m String query = (String) rl.get("question"); String pid = (String) rl.get("paragraph_id"); if (query.compareTo(question) == 0) { } if (pid.compareTo(docid) == 0 && query.compareTo(question) == 0) { // if docid is matched // get candidate index List<Integer> candidate_list = new ArrayList<Integer>(); // if (rl.get("candidates").toString().length()>1){ // System.out.println(rl.get("candidates").toString()); String[] candidates = rl.get("candidates").toString().split(","); for (String cand : candidates) { // System.out.println(cand); // System.out.println(rl.get("candidates").toString()); candidate_list.add(Integer.parseInt(cand.replace(" ", "")) - 1); } // } // print with candidate 0/1 int index_of_sen = 0; for (Object sen : (JSONArray) rl.get("sentences")) { int zero_one = 0; for (int cand : candidate_list) { if (index_of_sen == cand) zero_one = 1; } String out_format = String.format("%s\t%s\t%d\n", question, sen, zero_one); out.write(out_format); index_of_sen++; } } else { // print with candidate 0 for (Object sen : (JSONArray) rl.get("sentences")) { // System.out.format("%s\t%s\t%d\n", question, sen, 0); String out_format = String.format("%s\t%s\t%d\n", question, sen, 0); out.write(out_format); } } } }