List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:Person.java
public int compare(Object person, Object anotherPerson) { String lastName1 = ((Person) person).getLastName().toUpperCase(); String firstName1 = ((Person) person).getFirstName().toUpperCase(); String lastName2 = ((Person) anotherPerson).getLastName().toUpperCase(); String firstName2 = ((Person) anotherPerson).getFirstName().toUpperCase(); if (firstName1.equals(firstName2)) { return lastName1.compareTo(lastName2); } else {/*from w ww . j a v a 2 s . c o m*/ return firstName1.compareTo(firstName2); } }
From source file:geogebra.kernel.AlgoFrequency.java
protected final void compute() { // Validate input arguments //======================================================= if (!dataList.isDefined() || dataList.size() == 0) { frequency.setUndefined();/*from w w w . jav a2 s. c om*/ return; } if (!(dataList.getElementType() == GeoElement.GEO_CLASS_TEXT || dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC)) { frequency.setUndefined(); return; } if (classList != null) { if (classList.getElementType() != GeoElement.GEO_CLASS_NUMERIC || classList.size() < 2) { frequency.setUndefined(); return; } } if (density != null) { if (density.getDouble() <= 0) { frequency.setUndefined(); return; } } frequency.setDefined(true); frequency.clear(); if (value != null) value.clear(); double numMax = 0, numMin = 0; boolean doCumulative = isCumulative != null && isCumulative.getBoolean(); // Load the data into f, an instance of Frequency class //======================================================= Frequency f = new Frequency(); for (int i = 0; i < dataList.size(); i++) { if (dataList.getElementType() == GeoElement.GEO_CLASS_TEXT) f.addValue(((GeoText) dataList.get(i)).toValueString()); if (dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC) f.addValue(((GeoNumeric) dataList.get(i)).getDouble()); } // If classList does not exist, // get the unique value list and compute frequencies for this list //======================================================= // handle string data if (dataList.getElementType() == GeoElement.GEO_CLASS_TEXT) { Iterator itr = f.valuesIterator(); String strMax = (String) itr.next(); String strMin = strMax; itr = f.valuesIterator(); while (itr.hasNext()) { String s = (String) itr.next(); if (s.compareTo(strMax) > 0) strMax = s; if (s.compareTo(strMin) < 0) strMin = s; GeoText text = new GeoText(cons); text.setTextString(s); value.add(text); if (classList == null) if (doCumulative) frequency.add(new GeoNumeric(cons, f.getCumFreq((Comparable) s))); else frequency.add(new GeoNumeric(cons, f.getCount((Comparable) s))); } } // handle numeric data else { Iterator itr = f.valuesIterator(); numMax = (Double) itr.next(); numMin = numMax; itr = f.valuesIterator(); while (itr.hasNext()) { Double n = (Double) itr.next(); if (n > numMax) numMax = n.doubleValue(); if (n < numMin) numMin = n.doubleValue(); value.add(new GeoNumeric(cons, n)); if (classList == null) if (doCumulative) frequency.add(new GeoNumeric(cons, f.getCumFreq((Comparable) n))); else frequency.add(new GeoNumeric(cons, f.getCount((Comparable) n))); } } // If classList exists, compute frequencies using the classList //======================================================= if (classList != null) { double lowerClassBound = 0; double upperClassBound = 0; double classFreq = 0; //set density conditions boolean hasDensity = false; if (useDensity != null) hasDensity = useDensity.getBoolean(); double densityValue = 1; // default density if (density != null) { densityValue = density.getDouble(); } double cumulativeClassFreq = 0; double swap; int length = classList.size(); for (int i = 1; i < length; i++) { lowerClassBound = ((GeoNumeric) classList.get(i - 1)).getDouble(); upperClassBound = ((GeoNumeric) classList.get(i)).getDouble(); boolean increasing = true; if (lowerClassBound > upperClassBound) { swap = upperClassBound; upperClassBound = lowerClassBound; lowerClassBound = swap; increasing = false; } classFreq = f.getCumFreq((Comparable) upperClassBound) - f.getCumFreq((Comparable) lowerClassBound) + f.getCount((Comparable) lowerClassBound); if ((i != length - 1 && increasing) || (i != 1 && !increasing)) classFreq -= f.getCount((Comparable) upperClassBound); // System.out.println(" ================================="); // System.out.println("class freq: " + classFreq + " " + density); if (hasDensity) { classFreq = densityValue * classFreq / (upperClassBound - lowerClassBound); } if (doCumulative) cumulativeClassFreq += classFreq; // System.out.println("class freq: " + classFreq); // add the frequency to the output GeoList frequency.add(new GeoNumeric(cons, doCumulative ? cumulativeClassFreq : classFreq)); } // handle the last (highest) class frequency specially // it must also count values equal to the highest class bound } }
From source file:utilities.GraphViewer.java
private int getSeriesNum(String series) { String s;/*from w w w .java2 s . c o m*/ for (int i = 0; i < sensors1.size(); i++) { s = sensors1.get(i).getText(); if (series.compareTo(s) == 0) { return i; } } return -1; }
From source file:com.sldeditor.test.unit.tool.ysld.YSLDToolTest.java
/** * Test sld file./* w ww.ja v a2 s . co m*/ */ @Test public void testSetSelectedItems() { YSLDTool tool = new YSLDTool(); JPanel panel = tool.getPanel(); ToolButton toSLD = null; ToolButton toYSLD = null; for (Component c : panel.getComponents()) { if (c instanceof ToolButton) { ToolButton button = (ToolButton) c; String toolTipText = button.getToolTipText(); if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToSLD")) == 0) { toSLD = button; } else if (toolTipText .compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToYSLD")) == 0) { toYSLD = button; } } } File testFile1 = null; File testFile3 = null; try { testFile1 = File.createTempFile("invalid", ".tst"); testFile1.deleteOnExit(); testFile3 = File.createTempFile("valid", ".ysld"); testFile3.deleteOnExit(); } catch (IOException e1) { e1.printStackTrace(); } // Should both be disabled assertFalse(toSLD.isEnabled()); assertFalse(toYSLD.isEnabled()); tool.setSelectedItems(null, null); // Invalid file List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>(); SLDData sldData1 = new SLDData(null, null); sldData1.setSLDFile(testFile1); sldDataList.add(sldData1); tool.setSelectedItems(null, sldDataList); // Should both be disabled assertFalse(toSLD.isEnabled()); assertFalse(toYSLD.isEnabled()); // Try with valid sld file sldDataList = new ArrayList<SLDDataInterface>(); SLDData sldData2 = getSLDDataFile("/point/sld/point_simplepoint.sld"); sldDataList.add(sldData2); tool.setSelectedItems(null, sldDataList); // YSLD should be enabled assertTrue(toYSLD.isEnabled()); assertFalse(toSLD.isEnabled()); toYSLD.doClick(); // Try with valid ysld file sldDataList = new ArrayList<SLDDataInterface>(); SLDData sldData3 = getSLDDataFile("/point/ysld/point_simplepoint.ysld"); sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList); // SLD should be enabled assertTrue(toSLD.isEnabled()); assertFalse(toYSLD.isEnabled()); toSLD.doClick(); // Try with valid sld and ysld files sldDataList = new ArrayList<SLDDataInterface>(); sldDataList.add(sldData2); sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList); // SLD and YSLD should be enabled assertTrue(toSLD.isEnabled()); assertTrue(toYSLD.isEnabled()); }
From source file:de.iteratec.iteraplan.presentation.dialog.Search.SearchController.java
private boolean isSearchValid(String searchField) { if (StringUtils.isBlank((searchField))) { LOGGER.info("User tried to search for empty String"); return false; }//from www . j av a 2 s. com // compares the searchField with a list of illegal characters else if ((searchField.compareTo("+") == 0) || (searchField.compareTo("~") == 0 || (searchField.compareTo("!") == 0)) || (searchField.compareTo("\"") == 0) || (searchField.compareTo("(") == 0) || (searchField.compareTo(")") == 0) || (searchField.compareTo("{") == 0) || (searchField.compareTo("[") == 0) || (searchField.compareTo("]") == 0) || (searchField.compareTo("}") == 0) || (searchField.compareTo("?") == 0) || (searchField.compareTo("\\") == 0) || (searchField.compareTo("-") == 0) || (searchField.compareTo(":") == 0) || (searchField.compareTo("^") == 0)) { LOGGER.info("User tried to search for forbidden character"); return false; } else { return true; } }
From source file:com.albert.javatest.JavaTestExample.java
@Test public void testCompareTo() { String year1415 = "year1415"; String year1516 = "year1516"; System.out.println("##################### compareTo result = " + year1516.compareTo(null)); Assert.assertTrue(year1516.compareTo(year1415) > 0); }
From source file:com.xiaomi.linden.core.search.MultiLindenCoreImpl.java
public synchronized LindenCore getLindenCore(String indexName) throws IOException { LindenCore lindenCore = lindenCoreMap.get(indexName); if (lindenCore == null) { lindenCore = new LindenCoreImpl(config, indexName); lindenCoreMap.put(indexName, lindenCore); if (config.getMultiIndexMaxLiveIndexNum() != -1 && config.getMultiIndexMaxLiveIndexNum() < lindenCoreMap.size()) { List<String> keys = new ArrayList<>(lindenCoreMap.keySet()); Collections.sort(keys, new Comparator<String>() { @Override/*w w w . j ava2s . co m*/ public int compare(String o1, String o2) { return o1.compareTo(o2); } }); String oldestIndexName = keys.get(0); LindenCore core = lindenCoreMap.remove(oldestIndexName); core.close(); if (config.getIndexType() != LindenConfig.IndexType.RAM) { String dir = FilenameUtils.concat(baseIndexDir, oldestIndexName); String destDir = FilenameUtils.concat(baseIndexDir, EXPIRED_INDEX_NAME_PREFIX + oldestIndexName); if (new File(dir).exists()) { FileUtils.moveDirectory(new File(dir), new File(destDir)); } } } } return lindenCore; }
From source file:org.cnbi.web.system.listener.WebApplicationInitializer.java
/** * ??//from www. j a v a2s . c o m */ private void initSubjectData() { String subKey = Constants.INIT + Constants.SUBJECT + Constants.LIST, comKey = Constants.INIT + Constants.COMPOSE + Constants.LIST, subSql = sqlMap.get(subKey), comSql = sqlMap.get(comKey);// ,dimItemDatasSql // = // sqlMap.get(Constants.INIT+Constants.ITEM); Map<String, SubjectSqlBean> subjectMap = new HashMap<String, SubjectSqlBean>(); // String filePath = realPath // +"resources"+File.separator+"json"+File.separator; try {// @SuppressWarnings("unchecked") List<Subject> subjectList = (List<Subject>) handleService.query(subSql, new Subject("0001", "", "0")); for (int i = 0, len = subjectList.size(); i < len; i++) { Subject subject = subjectList.get(i); @SuppressWarnings("unchecked") List<Compose> composeList = (List<Compose>) handleService.query(comSql, new Compose(subject.getScode())); Map<String, String> measureMap = null;// Map<String, Compose> compseMap = null; for (int j = 0, lj = composeList.size(); j < lj; j++) { Compose compose = composeList.get(j); String type = compose.getType();// if (type.equalsIgnoreCase(Constants.MEASURE)) {// ? if (null == measureMap) {// ? ??new??new measureMap = new TreeMap<String, String>(new Comparator<String>() {// // // ???obj2.compareTo(obj1); public int compare(String obj1, String obj2) { return obj1.compareTo(obj2); } }); } measureMap.put(compose.getField(), compose.getSname()); } else if (type.equalsIgnoreCase(Constants.SUB)) {// SUBJECT // } else {// if (null == compseMap) {// ?? compseMap = new HashMap<String, Compose>(); } compose.setDimDatas(dimMap.get(compose.getField())); compseMap.put(compose.getField(), compose); } } if (null != compseMap && null != measureMap) { SubjectSqlBean subjectBean = new SubjectSqlBean(subject, compseMap, measureMap); subjectMap.put(subject.getScode(), subjectBean); // logger.info(subject.getSname() + "?" + subject.getScode() // + "SQL====\n" + subjectBean.getSql()); // if (subject.getScode().equals("1010")) { // System.out.println(subjectBean.getSql(new // DisplayBean(true,true))); // querySubjectData(subjectBean,filePath+subject.getScode()+"22.json"); // } } } servletContext.setAttribute(Constants.SUBJECT + Constants.MAP, subjectMap); } catch (Exception e) { logger.error("????\n" + e); throw new RuntimeException(e.getMessage(), e.getCause()); } }
From source file:com.github.seqware.queryengine.impl.TmpFileStorage.java
/** {@inheritDoc} */ @Override//from w w w. j a v a2 s .c o m public Iterable<FeatureList> getAllFeatureListsForFeatureSet(FeatureSet fSet) { assert (fSet instanceof LazyFeatureSet); List<FeatureList> features = new ArrayList<FeatureList>(); // ignore time String substring = NonPersistentStorage.createKey(fSet.getSGID(), false); String regex = "Feature\\..*~.*" + substring + ".*"; for (File file : FileUtils.listFiles(tempDir, new RegexFileFilter(regex), null)) { try { FeatureList suspect = (FeatureList) handleFileGivenClass(file, FeatureList.class); if (suspect.getSGID().getBackendTimestamp().getTime() >= fSet.getSGID().getBackendTimestamp() .getTime()) { continue; } features.add(suspect); } catch (IOException ex) { Logger.getLogger(TmpFileStorage.class.getName()).fatal(null, ex); } } Collections.sort(features, new Comparator<FeatureList>() { @Override public int compare(FeatureList o1, FeatureList o2) { String createKey1 = NonPersistentStorage.createKey(o1.getSGID(), true); String createKey2 = NonPersistentStorage.createKey(o2.getSGID(), true); return createKey1.compareTo(createKey2); } }); return features; }
From source file:azkaban.database.AzkabanDatabaseSetup.java
private List<String> findOutOfDateTable(String table, String currentVersion) { File directory = new File(scriptPath); ArrayList<String> versions = new ArrayList<String>(); File[] createScripts = directory .listFiles(new FileIOUtils.PrefixSuffixFileFilter(UPDATE_SCRIPT_PREFIX + table, SQL_SCRIPT_SUFFIX)); if (createScripts.length == 0) { return null; }/*from w ww . j a v a2 s. c om*/ String updateFileNameVersion = UPDATE_SCRIPT_PREFIX + table + "." + currentVersion; for (File file : createScripts) { String fileName = file.getName(); if (fileName.compareTo(updateFileNameVersion) > 0) { String[] split = fileName.split("\\."); String updateScriptVersion = ""; for (int i = 2; i < split.length - 1; ++i) { try { Integer.parseInt(split[i]); updateScriptVersion += split[i] + "."; } catch (NumberFormatException e) { break; } } if (updateScriptVersion.endsWith(".")) { updateScriptVersion = updateScriptVersion.substring(0, updateScriptVersion.length() - 1); // add to update list if updateScript will update above current // version and upto targetVersion in database.properties if (updateScriptVersion.compareTo(currentVersion) > 0 && updateScriptVersion.compareTo(this.version) <= 0) { versions.add(updateScriptVersion); } } } } Collections.sort(versions); return versions; }