List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Creates a new MorphDynaBean from a JSONObject. The MorphDynaBean will have * all the properties of the original JSONObject with the most accurate type. * Values of properties are not copied./*from w w w.ja va 2s . c o m*/ */ public static DynaBean newDynaBean(JSONObject jsonObject, JsonConfig jsonConfig) { Map props = getProperties(jsonObject); for (Iterator entries = props.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Map.Entry) entries.next(); String key = (String) entry.getKey(); if (!JSONUtils.isJavaIdentifier(key)) { String parsedKey = JSONUtils.convertToJavaIdentifier(key, jsonConfig); if (parsedKey.compareTo(key) != 0) { props.put(parsedKey, props.remove(key)); } } } MorphDynaClass dynaClass = new MorphDynaClass(props); MorphDynaBean dynaBean = null; try { dynaBean = (MorphDynaBean) dynaClass.newInstance(); dynaBean.setDynaBeanClass(dynaClass); } catch (Exception e) { throw new JSONException(e); } return dynaBean; }
From source file:com.clustercontrol.repository.util.RepositoryValidator.java
/** * ??/* ww w . j a v a 2 s.com*/ * * @param scopeInfo * @throws InvalidSetting * @throws InvalidRole */ public static void validateScopeInfo(String parentFacilityId, ScopeInfo scopeInfo, boolean parentCheck) throws InvalidSetting, InvalidRole { validateFacilityInfo(scopeInfo); // parentFacilityId if (parentCheck) { if (parentFacilityId != null && parentFacilityId.compareTo("") != 0) { try { QueryUtil.getFacilityPK(parentFacilityId, ObjectPrivilegeMode.MODIFY); } catch (FacilityNotFound e) { InvalidSetting e1 = new InvalidSetting( "Scope does not exist! facilityId = " + parentFacilityId); m_log.info("validateScopeInfo() : " + e1.getClass().getSimpleName() + ", " + e1.getMessage()); throw e1; } catch (InvalidRole e) { throw e; } } } // facilityType if (scopeInfo.getFacilityType() != FacilityConstant.TYPE_SCOPE) { InvalidSetting e = new InvalidSetting("Scope FacilityType is " + scopeInfo.getFacilityType()); m_log.info("validateScopeInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } }
From source file:integratedtoolkit.util.OptimisComponents.java
public static String getScheduler() { String schedulerComponent = System.getProperty(ITConstants.IT_SCHEDULER_COMPONENT); try {// w w w .j a va 2s . c o m LinkedList<InfrastructureProvider> ips = serviceManager.getProvidersData(serviceId); for (InfrastructureProvider ip : ips) { for (Vm vm : ip.getVms().getVmArray()) { String instanceName = vm.getType(); String VMtype = instanceName.substring( instanceName.indexOf(OPTIMIS_PREFIX) + OPTIMIS_PREFIX.length(), instanceName.lastIndexOf(OPTIMIS_SUFFIX)); if (VMtype.compareTo(schedulerComponent) == 0) { int instanceId = Integer.parseInt(instanceName .substring(instanceName.lastIndexOf(OPTIMIS_SUFFIX) + OPTIMIS_SUFFIX.length())); if (instanceId == 1) { return vm.getId(); } } } } } catch (Exception e) { return "127.0.0.1"; } return "127.0.0.1"; }
From source file:integratedtoolkit.util.OptimisComponents.java
public static boolean isScheduler(String appHost) { String ownComponent = System.getProperty(ITConstants.IT_COMPONENT); String schedulerComponent = System.getProperty(ITConstants.IT_SCHEDULER_COMPONENT); if (ownComponent == null || schedulerComponent == null || ownComponent.compareTo(schedulerComponent) == 0) { try {//ww w. ja va 2 s . co m int schedComponents = 0; LinkedList<InfrastructureProvider> ips = serviceManager.getProvidersData(serviceId); for (InfrastructureProvider ip : ips) { for (Vm vm : ip.getVms().getVmArray()) { String instanceName = vm.getType(); String VMtype = instanceName.substring( instanceName.indexOf(OPTIMIS_PREFIX) + OPTIMIS_PREFIX.length(), instanceName.lastIndexOf(OPTIMIS_SUFFIX)); if (VMtype.compareTo(schedulerComponent) == 0) { schedComponents++; } } } if (schedComponents < 2) { return true; } else { return false; } } catch (Exception e) { return true; } } else { return false; } }
From source file:com.krawler.esp.portalmsg.forummsgcomm.java
public static String getDetails(Connection cn, String id, int type, String flag, String userId) throws ServiceException { String query = null;/*from w w w . j a v a 2s .co m*/ String query1 = null; String query2 = null; Object[] params = { null }; String treeString = null; JSONStringer j = new JSONStringer(); JSONObject jobj = new JSONObject(); DbResults rs = null; DbResults rs1 = null; DbResults rs2 = null; try { String ptext = ""; String attachnent = getAttachment(cn, id); if (flag.compareTo("forum") == 0) { if (type == 1) { query = "SELECT post_text FROM krawlerforum_topics where topic_id=?"; rs = DbUtil.executeQuery(cn, query, id); //treeString = "{'data':["; while (rs.next()) { com.krawler.utils.json.base.JSONObject jtemp = new com.krawler.utils.json.base.JSONObject(); ptext = java.net.URLEncoder.encode(rs.getString(1)); // ptext += (!StringUtil.isNullOrEmpty(attachnent))?attachnent:""; jtemp.put("Details", ptext); jtemp.put("Attachment", java.net.URLEncoder.encode(attachnent)); //jtemp.put("Details", java.net.URLEncoder.encode(rs.getString(1))); jtemp.put("ID", id); jtemp.put("flag", "Forum"); jobj.append("data", jtemp); //treeString += j.object().key("Details").value( //rs.getString(1)).key("ID").value("topic" + id) //.key("flag").value("Forum").endObject() //.toString(); } //treeString += "]}"; } else if (type == 2) { query = "SELECT post_text FROM krawlerforum_posts where post_id=?"; rs = DbUtil.executeQuery(cn, query, id); //treeString = "{'data':["; while (rs.next()) { com.krawler.utils.json.base.JSONObject jtemp = new com.krawler.utils.json.base.JSONObject(); ptext = java.net.URLEncoder.encode(rs.getString(1)); //ptext += (!StringUtil.isNullOrEmpty(attachnent))?attachnent:""; jtemp.put("Details", ptext); jtemp.put("Attachment", java.net.URLEncoder.encode(attachnent)); // jtemp.put("Details", java.net.URLEncoder.encode(rs.getString(1))); jtemp.put("ID", id); jtemp.put("flag", "Forum"); jobj.append("data", jtemp); //treeString += j.object().key("Details").value( //rs.getString(1)).key("ID").value(id) //.key("flag").value("Forum").endObject() //.toString(); } //treeString += "]}"; } query1 = "Select ifread from userForumPostRead where post_id =? and userid=? "; rs1 = DbUtil.executeQuery(cn, query1, new Object[] { id, userId }); if (rs1.next()) { } else { query2 = "INSERT INTO userForumPostRead(post_id, userid, ifread) VALUES (?, ?, ?)"; DbUtil.executeUpdate(cn, query2, new Object[] { id, userId, true }); } } else if (flag.compareTo("mail") == 0) { query = "SELECT post_text,readflag FROM mailmessages where post_id=?"; rs2 = DbUtil.executeQuery(cn, query, id); boolean readFlag = false; //treeString = "{'data':["; while (rs2.next()) { com.krawler.utils.json.base.JSONObject jtemp = new com.krawler.utils.json.base.JSONObject(); jtemp.put("Details", java.net.URLEncoder.encode(rs2.getString(1))); jtemp.put("ID", id); jtemp.put("flag", "Forum"); jtemp.put("Attachment", java.net.URLEncoder.encode(attachnent)); jobj.append("data", jtemp); readFlag = rs2.getBoolean("readflag"); //treeString += j.object().key("Details").value( //rs2.getString(1)).key("ID").value(id).key("flag") //.value("Mail").endObject().toString(); } if (!readFlag) { query2 = "update mailmessages set readflag=true where post_id = ?"; int rows = DbUtil.executeUpdate(cn, query2, new Object[] { id }); } //treeString += "]}"; } } catch (ServiceException ex) { DbPool.quietRollback(cn); } catch (JSONException e) { throw ServiceException.FAILURE("course.gradeBook", e); } return jobj.toString(); }
From source file:org.fao.geonet.util.XslUtil.java
public static String getMax(Object values) { String[] strings = values.toString().split(" "); String max = ""; for (int i = 0; i < strings.length; i++) { String val = strings[i]; if (val.compareTo(max) > 0) { max = val; }/*from w ww. ja v a2s .c o m*/ } return max; }
From source file:com.google.gwt.core.ext.typeinfo.TypeOracle.java
/** * Convenience method to sort class types in a consistent way. Note that the * order is subject to change and is intended to generate an "aesthetically * pleasing" order rather than a computationally reliable order. *//*from w w w . ja v a 2 s.com*/ public static void sort(JClassType[] types) { Arrays.sort(types, new Comparator<JClassType>() { public int compare(JClassType type1, JClassType type2) { String name1 = type1.getQualifiedSourceName(); String name2 = type2.getQualifiedSourceName(); return name1.compareTo(name2); } }); }
From source file:com.orange.oidc.tim.service.SDCardStorage.java
static boolean compareStrings(String a, String b) { if (a == null && b == null) return true; if (a == null && b != null && b.length() == 0) return true; if (b == null && a != null && a.length() == 0) return true; try {//from ww w . j a v a2 s .c o m return a.compareTo(b) == 0; } catch (Exception e) { } return false; }
From source file:adalid.commons.util.ObjUtils.java
public static boolean between(Object object, Object minimum, Object maximum) { if (object == null) { return false; } else if (object instanceof String) { String val = StrUtils.toString(object); String min = StrUtils.toString(minimum); String max = StrUtils.toString(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Byte) { Byte val = NumUtils.toByte(object); Byte min = NumUtils.toByte(minimum); Byte max = NumUtils.toByte(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Short) { Short val = NumUtils.toShort(object); Short min = NumUtils.toShort(minimum); Short max = NumUtils.toShort(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Integer) { Integer val = NumUtils.toInteger(object); Integer min = NumUtils.toInteger(minimum); Integer max = NumUtils.toInteger(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Long) { Long val = NumUtils.toLong(object); Long min = NumUtils.toLong(minimum); Long max = NumUtils.toLong(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Float) { Float val = NumUtils.toFloat(object); Float min = NumUtils.toFloat(minimum); Float max = NumUtils.toFloat(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof Double) { Double val = NumUtils.toDouble(object); Double min = NumUtils.toDouble(minimum); Double max = NumUtils.toDouble(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof BigInteger) { BigInteger val = NumUtils.toBigInteger(object); BigInteger min = NumUtils.toBigInteger(minimum); BigInteger max = NumUtils.toBigInteger(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof BigDecimal) { BigDecimal val = NumUtils.toBigDecimal(object); BigDecimal min = NumUtils.toBigDecimal(minimum); BigDecimal max = NumUtils.toBigDecimal(maximum); return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else if (object instanceof java.util.Date) { java.util.Date val = (java.util.Date) object; java.util.Date min = (java.util.Date) minimum; java.util.Date max = (java.util.Date) maximum; return (min == null || val.compareTo(min) >= 0) && (max == null || val.compareTo(max) <= 0); } else {/*from ww w . j a v a 2s .c om*/ return false; } }
From source file:com.nokia.carbide.installpackages.InstallPackages.java
private static Comparator<String> getOrderListStringComparator(final List<String> orderList) { return new Comparator<String>() { public int compare(String o1, String o2) { if (o1.equals(o2)) return 0; // EJS HACK: I tried using the ';' separator in the sdkFamily but it // sorted to the bottom and also showed up in the UI...? if (o1.equals("Symbian")) return -1; for (String orderString : orderList) { if (o1.equals(orderString)) return -1; else if (o2.equals(orderString)) return 1; }/*from www.j av a 2 s .co m*/ return o1.compareTo(o2); } }; }