List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:com.datos.vfs.auth.StaticUserAuthenticator.java
private int compareStringOrNull(final String thisString, final String otherString) { if (thisString == null) { if (otherString != null) { return -1; }//from w w w. j a v a 2 s. c o m } else { if (otherString == null) { return 1; } final int result = thisString.compareTo(otherString); if (result != 0) { return result; } } return 0; }
From source file:hudson.plugins.simpleupdatesite.UpdateSite.java
private boolean isNewestPlugin(Plugin plugin) { if (!this.plugins.containsKey(plugin.getName())) { return true; }// w w w . jav a2s . c o m String existingVersion = this.plugins.get(plugin.getName()).getVersion(); String pluginVersion = plugin.getVersion(); try { // Try comparing using {@link VersionNumber} return new VersionNumber(pluginVersion).isNewerThan(new VersionNumber(existingVersion)); } catch (IllegalArgumentException e) { // In case version numbers are strange, fall back to lexical comparison return pluginVersion.compareTo(existingVersion) > 0; } }
From source file:org.openmrs.web.controller.report.PatientSearchFormController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { String success = ""; String error = ""; HttpSession httpSession = request.getSession(); String view = getSuccessView(); if (Context.isAuthenticated()) { MessageSourceAccessor msa = getMessageSourceAccessor(); String action = request.getParameter("action"); if (msa.getMessage("reportingcompatibility.PatientSearch.save").equals(action)) { PatientSearchReportObject psroBinded = (PatientSearchReportObject) obj; String hiddenName = request.getParameter("hiddenName"); String hiddenDesc = request.getParameter("hiddenDesc"); int hasXMLChanged = 0; hasXMLChanged = Integer.parseInt(request.getParameter("patientSearchXMLHasChanged")); String textAreaXML = request.getParameter("xmlStringTextArea"); Integer argumentsLength = Integer.valueOf(request.getParameter("argumentsSize")); PatientSearch ps = null;//from w w w. ja v a 2 s . c om String valueRoot = "value"; String hiddenValueRoot = "hiddenValue"; int testXMLerror = 0; List<Integer> needsUpdate = new ArrayList<Integer>(); for (int i = 0; i < argumentsLength; i++) { String hv = request.getParameter(hiddenValueRoot + i); String v = request.getParameter(valueRoot + i); if (hv.compareTo(v) != 0) needsUpdate.add(i); } String saved = msa.getMessage("reportingcompatibility.PatientSearch.saved"); String notsaved = msa.getMessage("reportingcompatibility.PatientSearch.notsaved"); String invalidXML = msa.getMessage("reportingcompatibility.PatientSearch.invalidXML"); String title = msa.getMessage("reportingcompatibility.PatientSearch.title"); boolean hasNewSearchArg = false; String newSearchArgName = (String) request.getParameter("newSearchArgName"); String newSearchArgValue = (String) request.getParameter("newSearchArgValue"); String newSearchArgClass = (String) request.getParameter("newSearchArgClass"); if (StringUtils.hasText(newSearchArgName) || StringUtils.hasText(newSearchArgValue) || StringUtils.hasText(newSearchArgClass)) { hasNewSearchArg = true; } if (hiddenName.compareTo(psroBinded.getName()) != 0 || hiddenDesc.compareTo(psroBinded.getDescription()) != 0 || needsUpdate.size() > 0 || hasXMLChanged == 1 || hasNewSearchArg) { if (needsUpdate.size() > 0) { ps = psroBinded.getPatientSearch(); List<SearchArgument> searchArguments = ps.getArguments(); for (Integer myI : needsUpdate) { SearchArgument sA = (SearchArgument) searchArguments.get(myI); SearchArgument newSA = new SearchArgument(); newSA.setName(sA.getName()); newSA.setPropertyClass(sA.getPropertyClass()); newSA.setValue(request.getParameter(valueRoot + myI)); searchArguments.set(myI, newSA); } ps.setArguments(searchArguments); psroBinded.setPatientSearch(ps); } if (hasXMLChanged == 1) { try { ReportObjectXMLDecoder roxd = new ReportObjectXMLDecoder(textAreaXML); PatientSearchReportObject psroFromXML = (PatientSearchReportObject) roxd .toAbstractReportObject(); psroBinded.setDescription(psroFromXML.getDescription()); psroBinded.setName(psroFromXML.getName()); psroBinded.setPatientSearch(psroFromXML.getPatientSearch()); psroBinded.setSubType(psroFromXML.getSubType()); psroBinded.setType(psroFromXML.getType()); } catch (Exception ex) { log.warn("Invalid Patient Search XML", ex); error += title + " " + notsaved + ", " + invalidXML; testXMLerror++; } } if (hasNewSearchArg) { if (StringUtils.hasText(newSearchArgName) && StringUtils.hasText(newSearchArgValue) && StringUtils.hasText(newSearchArgClass)) { try { psroBinded.getPatientSearch().addArgument(newSearchArgName, newSearchArgValue, Class.forName(newSearchArgClass)); } catch (Exception e) { error += msa .getMessage("reportingcompatibility.PatientSearch.invalidSearchArgument"); } } else { error += msa.getMessage("reportingcompatibility.PatientSearch.invalidSearchArgument"); } log.debug("Patient Search now has arguments: " + psroBinded.getPatientSearch().getArguments()); } if (testXMLerror != 1 || hasNewSearchArg) { ReportObjectService rs = (ReportObjectService) Context .getService(ReportObjectService.class); rs.saveReportObject(psroBinded); success = saved; } } } } if (!error.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); else if (!success.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success); return new ModelAndView(new RedirectView(view)); }
From source file:com.jkoolcloud.tnt4j.streams.format.FactPathValueFormatter.java
private Comparator<Snapshot> getSnapshotComparator() { if (snapshotComparator == null) { snapshotComparator = new Comparator<Snapshot>() { @Override/*from w w w. jav a2s . c o m*/ public int compare(Snapshot s1, Snapshot s2) { String s1Path = getSnapName(s1); String s2Path = getSnapName(s2); return s1Path.compareTo(s2Path); } }; } return snapshotComparator; }
From source file:adalid.core.Report.java
@Override public int compareTo(Report that) { if (that != null) { String thisName = StringUtils.trimToEmpty(this.getName()); String thatName = StringUtils.trimToEmpty(that.getName()); return thisName.compareTo(thatName); }//from ww w .ja v a2 s . c o m return 0; }
From source file:io.syndesis.jsondb.impl.JsonDBTest.java
@Test public void testCreateKey() { String lastkey = jsondb.createKey(); for (int i = 0; i < 20000; i++) { String key = jsondb.createKey(); assertThat(lastkey.compareTo(key) < 0).as("lastkey < key").isTrue(); lastkey = key;// w w w. ja va 2 s . c om } }
From source file:edu.cmu.tetrad.search.TimeSeriesUtils.java
/** * Creates new time series dataset from the given one (fixed to deal with mixed datasets) *//* w w w . j av a2s. co m*/ public static DataSet createLagData(DataSet data, int numLags) { List<Node> variables = data.getVariables(); int dataSize = variables.size(); int laggedRows = data.getNumRows() - numLags; IKnowledge knowledge = new Knowledge2(); Node[][] laggedNodes = new Node[numLags + 1][dataSize]; List<Node> newVariables = new ArrayList<>((numLags + 1) * dataSize + 1); for (int lag = 0; lag <= numLags; lag++) { for (int col = 0; col < dataSize; col++) { Node node = variables.get(col); String varName = node.getName(); Node laggedNode; String name = varName; if (lag != 0) { name = name + ":" + lag; } if (node instanceof ContinuousVariable) { laggedNode = new ContinuousVariable(name); } else if (node instanceof DiscreteVariable) { DiscreteVariable var = (DiscreteVariable) node; laggedNode = new DiscreteVariable(var); laggedNode.setName(name); } else { throw new IllegalStateException("Node must be either continuous or discrete"); } newVariables.add(laggedNode); laggedNode.setCenter(80 * col + 50, 80 * (numLags - lag) + 50); laggedNodes[lag][col] = laggedNode; // knowledge.addToTier(numLags - lag, laggedNode.getName()); } } // System.out.println("Variable list before the sort = " + newVariables); Collections.sort(newVariables, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { String name1 = getNameNoLag(o1); String name2 = getNameNoLag(o2); // System.out.println("name 1 = " + name1); // System.out.println("name 2 = " + name2); String prefix1 = getPrefix(name1); String prefix2 = getPrefix(name2); // System.out.println("prefix 1 = " + prefix1); // System.out.println("prefix 2 = " + prefix2); int index1 = getIndex(name1); int index2 = getIndex(name2); // System.out.println("index 1 = " + index1); // System.out.println("index 2 = " + index2); if (getLag(o1.getName()) == getLag(o2.getName())) { if (prefix1.compareTo(prefix2) == 0) { return Integer.compare(index1, index2); } else { return prefix1.compareTo(prefix2); } } else { return getLag(o1.getName()) - getLag(o2.getName()); } } }); // System.out.println("Variable list after the sort = " + newVariables); for (Node node : newVariables) { String varName = node.getName(); String tmp; int lag; if (varName.indexOf(':') == -1) { lag = 0; // laglist.add(lag); } else { tmp = varName.substring(varName.indexOf(':') + 1, varName.length()); lag = Integer.parseInt(tmp); // laglist.add(lag); } knowledge.addToTier(numLags - lag, node.getName()); } DataSet laggedData = new ColtDataSet(laggedRows, newVariables); for (int lag = 0; lag <= numLags; lag++) { for (int col = 0; col < dataSize; col++) { for (int row = 0; row < laggedRows; row++) { Node laggedNode = laggedNodes[lag][col]; if (laggedNode instanceof ContinuousVariable) { double value = data.getDouble(row + numLags - lag, col); laggedData.setDouble(row, col + lag * dataSize, value); } else { int value = data.getInt(row + numLags - lag, col); laggedData.setInt(row, col + lag * dataSize, value); } } } } knowledge.setDefaultToKnowledgeLayout(true); // knowledge.setLagged(true); laggedData.setKnowledge(knowledge); // laggedData.setName(data.getNode()); return laggedData; }
From source file:org.duracloud.snapshot.service.impl.SpaceItemWriterTest.java
/** * @param string// ww w.j a va2s .com * @return * @throws IOException */ private List<String> getLines(String filename) throws IOException { List<String> lines = Files.readAllLines(ContentDirUtils.getPath(contentDir, filename), StandardCharsets.UTF_8); Collections.sort(lines, new Comparator<String>() { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(String o1, String o2) { String path1 = getPath(o1); String path2 = getPath(o2); return path1.compareTo(path2); } private String getPath(String string) { int index = string.indexOf(" "); return string.substring(index + 1); } }); return lines; }
From source file:com.ibm.bi.dml.api.MLMatrix.java
private double getScalarBuiltinFunctionResult(String fn) throws IOException, DMLException, ParseException { if (fn.compareTo("nrow") == 0 || fn.compareTo("ncol") == 0) { ml.reset();/* ww w . ja v a 2s . c om*/ ml.registerInput("left", getRDDLazily(this), mc.getRows(), mc.getCols(), mc.getRowsPerBlock(), mc.getColsPerBlock(), mc.getNonZeros()); ml.registerOutput("output"); String script = "left = read(\"\");" + "val = " + fn + "(left); " + "output = matrix(val, rows=1, cols=1); " + writeStmt; MLOutput out = ml.executeScript(script); List<Tuple2<MatrixIndexes, MatrixBlock>> result = out.getBinaryBlockedRDD("output").collect(); if (result == null || result.size() != 1) { throw new DMLRuntimeException("Error while computing the function: " + fn); } return result.get(0)._2.getValue(0, 0); } else { throw new DMLRuntimeException("The function " + fn + " is not yet supported in MLMatrix"); } }
From source file:cs.cirg.cida.experiment.DataTableExperiment.java
public void calculateStatistics() { for (String variableName : variableNames) { List<Integer> selectedColumns = new ArrayList<Integer>(); List<String> columnNames = data.getColumnNames(); int size = columnNames.size(); for (int i = 0; i < size; i++) { String columnName = columnNames.get(i); // if necesary strip the sample number: (X) if (columnName.contains("(")) { columnName = columnName.substring(0, columnName.indexOf("(") - 1); }// w w w . jav a2 s . c o m if (columnName.compareTo(variableName) == 0) { selectedColumns.add(i); } } DescriptiveStatsCalculator calculator = new DescriptiveStatsCalculator( (StandardDataTable<Numeric>) data, selectedColumns); calculator.calculate(); variableToStatsMap.put(variableName, calculator.getIterationsDescriptiveStatistics()); } }