List of usage examples for java.lang String compareToIgnoreCase
public int compareToIgnoreCase(String str)
From source file:org.geowebcache.config.wms.parameters.NaiveWMSDimensionFilter.java
public NaiveWMSDimensionFilter(Dimension dimension, Extent extent) { Preconditions.checkNotNull(dimension); Preconditions.checkNotNull(extent);/*from w w w . j ava 2s .c om*/ this.dimension = dimension; this.extent = extent; String keyName = dimension.getName(); if (keyName.compareToIgnoreCase("time") != 0 && keyName.compareToIgnoreCase("elevation") != 0) { keyName = "dim_" + keyName; } this.setKey(keyName); this.setDefaultValue(extent.getDefaultValue()); }
From source file:Main.java
/** * Compare two string by chuning digits and non-digits separately and compare between the two. * This way, the version strings (Ex: 10.2c.4.24546 sp1) can be properly compared. * * @param str1/*from www . j a v a 2 s . co m*/ * @param str2 * @return */ public static int alnumCompare(String str1, String str2) { // Ensure null cases are handled for both s1 and s2. if (str1 == str2) { return 0; } else if (str1 == null) { return -1; } else if (str2 == null) { return 1; } int s1Length = str1.length(); int s2Length = str2.length(); for (int s1Index = 0, s2Index = 0; s1Index < s1Length && s2Index < s2Length;) { String thisStr = getDigitOrNonDigitChunk(str1, s1Length, s1Index); s1Index += thisStr.length(); String thatStr = getDigitOrNonDigitChunk(str2, s2Length, s2Index); s2Index += thatStr.length(); // If both strs contain numeric characters, sort them numerically int result = 0; if (Character.isDigit(thisStr.charAt(0)) && Character.isDigit(thatStr.charAt(0))) { // Simple str comparison by length. int thisStrLength = thisStr.length(); result = thisStrLength - thatStr.length(); // If equal, the first different number counts if (result == 0) { for (int i = 0; i < thisStrLength; i++) { result = thisStr.charAt(i) - thatStr.charAt(i); if (result != 0) { return result; } } } } else { result = thisStr.compareToIgnoreCase(thatStr); } if (result != 0) { return result; } } return s1Length - s2Length; }
From source file:org.openmrs.module.hospitalcore.web.controller.ajax.AjaxController.java
/** * Concept search autocomplete for form/*from w w w.j av a2s.c o m*/ * * @param name * @param model * @return */ @SuppressWarnings("deprecation") @RequestMapping(value = "/module/hospitalcore/ajax/autocompleteConceptSearch.htm", method = RequestMethod.GET) public String autocompleteConceptSearch(@RequestParam(value = "q", required = false) String name, Model model) { List<ConceptWord> cws = Context.getConceptService().findConcepts(name, new Locale("en"), false); Set<String> conceptNames = new HashSet<String>(); for (ConceptWord word : cws) { String conceptName = word.getConcept().getName().getName(); conceptNames.add(conceptName); } List<String> concepts = new ArrayList<String>(); concepts.addAll(conceptNames); Collections.sort(concepts, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); model.addAttribute("conceptNames", concepts); return "/module/hospitalcore/ajax/autocompleteConceptSearch"; }
From source file:org.openmrs.module.laboratory.web.util.ParameterModel.java
public int compareTo(ParameterModel o) { if (StringUtils.isBlank(o.getId())) return 1; if (StringUtils.isBlank(this.getId())) return -1; String thisId = id; String oId = o.getId();/*from ww w .ja v a 2 s.c o m*/ return thisId.compareToIgnoreCase(oId); }
From source file:org.openmrs.util.DrugsByNameComparator.java
/** * Compare drug names ignoring numericals and other characters. Using compareToIgnoreCase() * method to prevent a capital letter getting precedence over a simple letter which comes before * it in the alphabet.//www.jav a 2 s . c om * * @param d1 the first Drug to be compared * @param d2 the second Drug to be compared * @return the int * @should return negative if name for drug1 comes before that of drug2 * @should return zero if name for drug1 comes before that of drug2 * @should return positive if name for drug1 comes before that of drug2 ignoring dashes * @should return positive if name for drug1 comes before that of drug2 ignoring numerics */ private int compareDrugNamesIgnoringNumericals(Drug d1, Drug d2) { String firstDrugName = remove(d1.getName()); String secondDrugName = remove(d2.getName()); return firstDrugName.compareToIgnoreCase(secondDrugName); }
From source file:com.github.braully.graph.BatchExecuteOperation.java
static List<File> sortFileArrayByName(File[] files) { List<File> fileList = new ArrayList<>(Arrays.asList(files)); Collections.sort(fileList, new Comparator<File>() { public int compare(File t, File t1) { int ret = 0; try { if (t != null && t1 != null) { String tname = t.getName().toLowerCase(); String t1name = t1.getName().toLowerCase(); if (tname.contains("binary") || tname.contains("-00-ref") || tname.contains("hull_number_java")) { tname = "a" + tname; }/*w ww. j ava2s . com*/ if (t1name.contains("binary") || t1name.contains("-00-ref") || t1name.contains("hull_number_java")) { t1name = "a" + t1name; } ret = tname.compareToIgnoreCase(t1name); } } catch (Exception e) { } return ret; } }); return fileList; }
From source file:org.kalypso.model.wspm.pdb.internal.connect.AbstractSettings.java
@Override public int compareTo(final IPdbSettings o) { final String n1 = getName(); final String n2 = o.getName(); return n1.compareToIgnoreCase(n2); }
From source file:org.openmrs.module.pmtct.web.view.chart.HivStatusPieChartView.java
@SuppressWarnings("static-access") @Override/*www . j av a2 s . c o m*/ protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UserContext userContext = Context.getUserContext(); ApplicationContext appContext = ContextProvider.getApplicationContext(); PmtctService pmtct = Context.getService(PmtctService.class); DefaultPieDataset pieDataset = new DefaultPieDataset(); List<Object> objects = null; PMTCTModuleTag tag = new PMTCTModuleTag(); List<String> hivOptions = new ArrayList<String>(); List<Integer> hivOptionValues = new ArrayList<Integer>(); Collection<ConceptAnswer> answers = Context.getConceptService() .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers(); try { objects = pmtct.getCurrentPatientsInPmtct(); for (ConceptAnswer str : answers) { hivOptions.add(str.getAnswerConcept().getName().getName()); hivOptionValues.add(0); } hivOptions.add("Others"); hivOptionValues.add(0); for (Object ob : objects) { int patientId = (Integer) ((Object[]) ob)[0]; String patientHivStatus = tag.lastObsValueByConceptId(patientId, PMTCTConstants.RESULT_OF_HIV_TEST); int i = 0; boolean found = false; for (String s : hivOptions) { if ((s.compareToIgnoreCase(patientHivStatus)) == 0) { hivOptionValues.set(i, hivOptionValues.get(i) + 1); found = true; } i++; } if (!found) { hivOptionValues.set(hivOptionValues.size() - 1, hivOptionValues.get(hivOptionValues.size() - 1) + 1); } } int i = 0; for (String s : hivOptions) { if (hivOptionValues.get(i) > 0) { Float percentage = new Float(100 * hivOptionValues.get(i) / objects.size()); pieDataset.setValue(s + " (" + hivOptionValues.get(i) + " , " + percentage + "%)", percentage); } i++; } } catch (Exception e) { e.printStackTrace(); } String title = appContext.getMessage("pmtct.menu.patientInPmtct", null, userContext.getLocale()); JFreeChart chart = ChartFactory.createPieChart(title + " : " + Context.getConceptService() .getConcept(PMTCTConstants.HIV_STATUS).getPreferredName(userContext.getLocale()), pieDataset, true, true, false); return chart; }
From source file:org.slc.sli.bulk.extract.files.metadata.ManifestFile.java
private String getLatestVersion(ApiNameSpace[] nameSpaces) { String latest = ""; for (ApiNameSpace nameSpace : nameSpaces) { for (String version : nameSpace.getNameSpace()) { if (version.compareToIgnoreCase(latest) > 0) { latest = version;//from w w w . j a va 2 s. co m } } } return latest; }
From source file:org.isatools.tablib.export.StringPropertyComparator.java
/** * nulls are always < non-nulls//w w w . ja v a2s .co m */ public int compare(ObjectType o1, ObjectType o2) { if (o1 == null) { return o2 == null ? 0 : -1; } if (o2 == null) { return o1 == null ? 0 : +1; } // Lexicographic order: first pair with different elements wins for (String propertyName : propertyNames) { try { String v1 = StringUtils.trimToEmpty(BeanUtils.getProperty(o1, propertyName)); int compv = v1.compareToIgnoreCase(BeanUtils.getProperty(o2, propertyName)); if (compv != 0) { return compv; } } catch (Exception ex) { throw new TabInternalErrorException("Problem while trying to get " + propertyName + " from " + o1.getClass().getSimpleName() + ": " + ex.getMessage(), ex); } } return 0; }