List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:com.sfs.whichdoctor.dao.WhichDoctorFinancialObjectDAOImpl.java
/** * Check number.// ww w .j a v a 2s .c om * * @param type the type * @param existingNumber the existing number * @param issuedDate the issued date * @return the string */ protected String checkNumber(final String type, final String existingNumber, final Date issuedDate) { String number = ""; /* Does a receipt number need to be generated */ Date issued = Calendar.getInstance().getTime(); if (issuedDate != null) { issued = issuedDate; } boolean generateNumber = true; if (existingNumber != null) { if (existingNumber.compareTo("") != 0) { generateNumber = false; } } if (generateNumber) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy"); int intNumber = 0; String strNumber = ""; try { strNumber = (String) this.getJdbcTemplateReader().queryForObject( this.getSQL().getValue(type + "/findMaxNumber"), new Object[] { simpleDateFormat.format(issued) + "%" }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(1); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search } if (strNumber != null) { strNumber = strNumber.substring(2); intNumber = Integer.parseInt(strNumber); } else { intNumber = 0; } strNumber = String.valueOf(intNumber + 1); while (strNumber.length() < 4) { strNumber = "0" + strNumber; } number = simpleDateFormat.format(issued) + strNumber; } else { number = existingNumber; } return number; }
From source file:com.quinsoft.zeidon.domains.StringDomain.java
/** * StringDomain needs to override compare() because it potentially needs to convert empty strings ("") to * null before doing the comparison.//from www . ja va2s. c o m */ @Override public int compare(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef, Object internalValue, Object externalValue) { Object value = convertExternalValue(task, attributeInstance, attributeDef, null, externalValue); String s1 = checkNullString(internalValue); String s2 = checkNullString(value); Integer rc = compareNull(task, attributeDef, s1, s2); if (rc != null) return rc; int c = 0; if (attributeDef.isCaseSensitive()) c = s1.compareTo(s2); else c = s1.compareToIgnoreCase(s2); if (c < 0) return -1; if (c > 0) return 1; return 0; }
From source file:edu.harvard.i2b2.analysis.dataModel.PDORequestMessageModel.java
public GetPDOFromInputListRequestType getPDOFromInputListRequestType(ArrayList<PDOItem> items, String patientSetRefId, Integer min, Integer max, boolean fromFact) { PatientListType patientListType = new PatientListType(); if (patientSetRefId.compareTo("-1") == 0) { patientListType.setPatientSetCollId(null); patientListType.setEntirePatientSet(true); } else {//from w w w. ja va2s.co m patientListType.setPatientSetCollId(patientSetRefId); } patientListType.setMin(min); patientListType.setMax(max); // patientListType.setEntirePatientSet(); // PatientListType.PatientNum patientNum = new // PatientListType.PatientNum(); // patientNum.setIndex(1); // patientNum.setValue(344); // patientListType.getPatientNum().add(patientNum); // VisitListType visitListType = new VisitListType(); // visitListType.setPatientEncCollId(100); FilterListType filterListType = new FilterListType(); // set up concept path list for (int i = 0; i < items.size(); i++) { PDOItem item = items.get(i); // for(int j=0;j<=item.valDisplayProperties.size();j++) { PanelType panelType = new PanelType(); panelType.setName(item.fullPath);// +(j>0?""+j:"")); ItemType itemType = new ItemType(); itemType.setItemKey(item.fullPath); itemType.setDimDimcode(item.dimcode); itemType.setDimTablename(item.tableType); for (int j = 0; j < item.valDisplayProperties.size(); j++) { PDOValueData valdp = item.valDisplayProperties.get(j); itemType.getConstrainByValue().add(valdp.writeValueConstrain()); } ConstrainByDate timeConstrain = new ConstrainByDate(); DTOFactory dtoFactory = new DTOFactory(); if (item.queryModel().startTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); constraindateType.setValue(dtoFactory.getXMLGregorianCalendarDate(item.queryModel().startYear(), item.queryModel().startMonth(), item.queryModel().startDay())); timeConstrain.setDateFrom(constraindateType); } if (item.queryModel().endTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); constraindateType.setValue(dtoFactory.getXMLGregorianCalendarDate(item.queryModel().endYear(), item.queryModel().endMonth(), item.queryModel().endDay())); timeConstrain.setDateTo(constraindateType); } itemType.getConstrainByDate().add(timeConstrain); panelType.getItem().add(itemType); filterListType.getPanel().add(panelType); // } } OutputOptionType patientOutputOptionType = new OutputOptionType(); if (fromFact) { patientOutputOptionType.setSelect(OutputOptionSelectType.USING_FILTER_LIST); } else { patientOutputOptionType.setSelect(OutputOptionSelectType.USING_INPUT_LIST); } patientOutputOptionType.setOnlykeys(false); FactOutputOptionType factOutputOptionType = new FactOutputOptionType(); factOutputOptionType.setOnlykeys(false); factOutputOptionType.setBlob(false); OutputOptionType visitOutputOptionType = new OutputOptionType(); // if(fromFact) { visitOutputOptionType.setSelect(OutputOptionSelectType.USING_FILTER_LIST); // } // else { // visitOutputOptionType.setSelect("from_input"); // } visitOutputOptionType.setOnlykeys(false); OutputOptionListType outputOptionListType = new OutputOptionListType(); outputOptionListType.setPatientSet(patientOutputOptionType); // outputOptionListType.setVisitDimension(visitOutputOptionType); outputOptionListType.setObservationSet(factOutputOptionType); /* * GetPDOFromPatientSetRequestType requestType = new * GetPDOFromPatientSetRequestType(); * requestType.setPatientList(patientListType); * requestType.setFilterList(filterListType); * requestType.setOuputOptionList(outputOptionListType); */ InputOptionListType inputOptionListType = new InputOptionListType(); inputOptionListType.setPatientList(patientListType); // inputOptionListType.setVisitList(visitListType); GetPDOFromInputListRequestType inputListRequestType = new GetPDOFromInputListRequestType(); inputListRequestType.setFilterList(filterListType); inputListRequestType.setOutputOption(outputOptionListType); inputListRequestType.setInputList(inputOptionListType); return inputListRequestType; }
From source file:org.gvnix.service.roo.addon.addon.converters.JavaTypeListConverter.java
/** * Converts the input String from the shell to a Prefix to the completions. * //from w w w .j a v a 2s.c o m * @param existingData String value from the command attribute. * @return {@link String} completePrefix to add for completions. */ private String convertInputIntoPrefixCompletion(String existingData) { String[] existingDataList; String completeExistingDataList = ""; existingDataList = StringUtils.split(existingData, ","); for (int i = 0; i < existingDataList.length - 1; i++) { if (completeExistingDataList.compareTo("") == 0) { completeExistingDataList = completeExistingDataList.concat(existingDataList[i]); } else { completeExistingDataList = completeExistingDataList.concat(",").concat(existingDataList[i]); } } if (existingDataList.length > 1) { completeExistingDataList = completeExistingDataList.concat(","); } return completeExistingDataList; }
From source file:Main.java
/** * Returns the ordered keys of the given map * /* www. j a v a 2 s . c om*/ * @param map * the map * @return the ordered keys */ public final static List<String> getOrderedKeys(final Map<String, Object> map) { List<String> keys = new LinkedList<String>(); if (!map.isEmpty()) { keys.addAll(map.keySet()); Collections.sort(keys, new Comparator<String>() { /** * {@inheritDoc} */ public int compare(String o1, String o2) { if (o1 == o2) { return 0; } int n1 = -1; int n2 = -1; try { n1 = Integer.parseInt(o1.substring(1)); } catch (NumberFormatException e) { // IGNORE } try { n2 = Integer.parseInt(o2.substring(1)); } catch (NumberFormatException e) { // IGNORE } /* * n1 is a number */ if (n1 != -1) { /* * n2 is a number */ if (n2 != -1) { return n1 - n2; } /* * n2 is a string literal */ return -1; } /* * n1 is a literal and n2 is a number */ if (n2 != -1) { return -1; } /* * both are literals */ return o1.compareTo(o2); } }); } return keys; }
From source file:com.aliyun.odps.flume.sink.OdpsSink.java
private OdpsEventSerializer createSerializer(String serializerType) { if (serializerType.compareToIgnoreCase(OdpsDelimitedTextSerializer.ALIAS) == 0 || serializerType.compareTo(OdpsDelimitedTextSerializer.class.getName()) == 0) { return new OdpsDelimitedTextSerializer(); }/*from w w w . j ava 2 s. c o m*/ try { return (OdpsEventSerializer) Class.forName(serializerType).newInstance(); } catch (Exception e) { throw new IllegalArgumentException( "Unable to instantiate serializer: " + serializerType + " on sink: " + getName(), e); } }
From source file:marytts.tools.install.ComponentDescription.java
/** * Determine whether oneVersion is newer than otherVersion. * This performs a lexicographic comparison with the exception that a version with suffix "-SNAPSHOT" * is treated as older than the version without that suffix. * A version is not newer than itself. * @param oneVersion/*from w w w . j a va 2 s.c o m*/ * @param otherVersion * @return true if oneVersion is newer than otherVersion, false if they are equal or otherVersion is newer. */ public static boolean isVersionNewerThan(String oneVersion, String otherVersion) { if (oneVersion == null || otherVersion == null) { return false; } // The only special cases we need to consider is when otherVersion is oneVersion suffixed with "-SNAPSHOT", // or the other way round: in this case the one with the suffix is newer. // All other cases are covered by lexicographic comparison. if (otherVersion.equals(oneVersion + "-SNAPSHOT")) { return true; } if (oneVersion.equals(otherVersion + "-SNAPSHOT")) { return false; } return oneVersion.compareTo(otherVersion) > 0; }
From source file:StocksTable4.java
public int compare(Object o1, Object o2) { if (!(o1 instanceof StockData) || !(o2 instanceof StockData)) return 0; StockData s1 = (StockData) o1;/*from ww w . ja va 2s.co m*/ StockData s2 = (StockData) o2; int result = 0; double d1, d2; switch (m_sortCol) { case 0: // symbol String str1 = (String) s1.m_symbol.m_data; String str2 = (String) s2.m_symbol.m_data; result = str1.compareTo(str2); break; case 1: // name result = s1.m_name.compareTo(s2.m_name); break; case 2: // last d1 = s1.m_last.doubleValue(); d2 = s2.m_last.doubleValue(); result = d1 < d2 ? -1 : (d1 > d2 ? 1 : 0); break; case 3: // open d1 = s1.m_open.doubleValue(); d2 = s2.m_open.doubleValue(); result = d1 < d2 ? -1 : (d1 > d2 ? 1 : 0); break; case 4: // change d1 = ((Fraction) s1.m_change.m_data).doubleValue(); d2 = ((Fraction) s2.m_change.m_data).doubleValue(); result = d1 < d2 ? -1 : (d1 > d2 ? 1 : 0); break; case 5: // change % d1 = ((Double) s1.m_changePr.m_data).doubleValue(); d2 = ((Double) s2.m_changePr.m_data).doubleValue(); result = d1 < d2 ? -1 : (d1 > d2 ? 1 : 0); break; case 6: // volume long l1 = s1.m_volume.longValue(); long l2 = s2.m_volume.longValue(); result = l1 < l2 ? -1 : (l1 > l2 ? 1 : 0); break; } if (!m_sortAsc) result = -result; return result; }
From source file:ListProperties.java
public int compareRowsByColumn(int row1, int row2, int column) { Class type = model.getColumnClass(column); TableModel data = model;// w w w .ja v a2s. com // Check for nulls Object o1 = data.getValueAt(row1, column); Object o2 = data.getValueAt(row2, column); // If both values are null return 0 if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { // Define null less than everything. return -1; } else if (o2 == null) { return 1; } if (type.getSuperclass() == Number.class) { Number n1 = (Number) data.getValueAt(row1, column); double d1 = n1.doubleValue(); Number n2 = (Number) data.getValueAt(row2, column); double d2 = n2.doubleValue(); if (d1 < d2) return -1; else if (d1 > d2) return 1; else return 0; } else if (type == String.class) { String s1 = (String) data.getValueAt(row1, column); String s2 = (String) data.getValueAt(row2, column); int result = s1.compareTo(s2); if (result < 0) return -1; else if (result > 0) return 1; else return 0; } else if (type == java.util.Date.class) { Date d1 = (Date) data.getValueAt(row1, column); long n1 = d1.getTime(); Date d2 = (Date) data.getValueAt(row2, column); long n2 = d2.getTime(); if (n1 < n2) return -1; else if (n1 > n2) return 1; else return 0; } else if (type == Boolean.class) { Boolean bool1 = (Boolean) data.getValueAt(row1, column); boolean b1 = bool1.booleanValue(); Boolean bool2 = (Boolean) data.getValueAt(row2, column); boolean b2 = bool2.booleanValue(); if (b1 == b2) return 0; else if (b1) // Define false < true return 1; else return -1; } else { Object v1 = data.getValueAt(row1, column); String s1 = v1.toString(); Object v2 = data.getValueAt(row2, column); String s2 = v2.toString(); int result = s1.compareTo(s2); if (result < 0) return -1; else if (result > 0) return 1; else return 0; } }
From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java
private Criteria createNotificationSearchWithTypeCriteria(String user, String capp, Long since, NotificationFilter filter) { Criteria criteria = new Criteria(); // user is obligatory // criteria.and("user").is(user); // only non-deleted criteria = criteria.and("deleted").is(false); if (capp != null && capp.compareTo("") != 0) { criteria = criteria.and("content.type").is(capp); }/*from ww w . ja v a2 s.c o m*/ // if (user != null && user.compareTo("") != 0) { criteria = criteria.and("content.user").is(user); // } if (since != null) { criteria = criteria.and("content.timestamp").gte(since); } if (filter.isReaded() != null) { criteria = criteria.and("content.readed").is(filter.isReaded()); } if (filter.isStarred() != null) { criteria = criteria.and("content.starred").is(filter.isStarred()); } if (filter.getSourceType() != null) { criteria = criteria.and("content.type").is(filter.getSourceType()); } if (filter.getLabelId() != null) { criteria = criteria.and("content.labelIds").is(filter.getLabelId()); } if (filter.getSearchText() != null) { criteria = criteria.orOperator(new Criteria().and("content.title").regex(filter.getSearchText(), "i"), new Criteria().and("content.description").regex(filter.getSearchText(), "i")); } return criteria; }