List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:br.bireme.ngrams.NGrams.java
private static Result createResult(final Set<String> id_id, final Parameters parameters, final String[] param, final Document doc, final NGramDistance ngDistance, final float similarity, final float score) { assert id_id != null; assert parameters != null; assert param != null; assert doc != null; assert ngDistance != null; assert similarity >= 0; assert score >= 0; final Result ret; final Collection<br.bireme.ngrams.Field> fields = parameters.nameFields.values(); int matchedFields = 0; boolean maxScore = false; for (br.bireme.ngrams.Field fld : fields) { final int val = checkField(ngDistance, fld, param, parameters.nameFields, doc); if (val == -1) { // field does not match } else if (val == -2) { maxScore = true;//from w ww . j a va2s. co m } else { matchedFields += val; } } final String id1 = param[parameters.id.pos]; final String id2 = (String) doc.get("id"); final String idb1 = id1 + "_" + Tools.normalize(param[parameters.db.pos], OCC_SEPARATOR); final String idb2 = id2 + "_" + (String) doc.get("database"); final String id1id2 = (idb1.compareTo(idb2) <= 0) ? (idb1 + "_" + idb2) : (idb2 + "_" + idb1); if (matchedFields == 0) { ret = null; // document is reject (no field passed the check) } else { if (checkScore(parameters, similarity, matchedFields, maxScore)) { //ret = new NGrams.Result(param, doc, similarity, score); if (id_id.contains(id1id2)) { ret = null; } else { id_id.add(id1id2); ret = new NGrams.Result(param, doc, similarity, score); } } else { ret = null; } } return ret; }
From source file:com.thetechwarriors.cidrutils.Subnet.java
public boolean isAfter(Subnet other) { String thisAddress = getNext().getFirstIPAddressForComparison(); String otherAddress = other.getNext().getFirstIPAddressForComparison(); return thisAddress.compareTo(otherAddress) > 0; }
From source file:fr.itinerennes.bundler.tasks.ScheduleForStopTask.java
private void generateScheduleForStop(File output, Stop s, ServiceDate sd) { final StopSchedule sched = new StopSchedule(); sched.setDate(sd.getAsDate());/*w w w. j a v a2s . c om*/ sched.setStop(toStop(s)); for (final StopTime st : xGtfs.getStopTimes(s, sd)) { sched.getStopTimes().add(toScheduledStopTime(st, sd)); final fr.itinerennes.api.client.model.Route route = toRoute(st.getTrip().getRoute()); if (!sched.getRoutes().contains(route)) { sched.getRoutes().add(route); } } Collections.sort(sched.getStopTimes(), new Comparator<ScheduleStopTime>() { @Override public int compare(ScheduleStopTime st1, ScheduleStopTime st2) { return st1.getDepartureTime().compareTo(st2.getDepartureTime()); } }); Collections.sort(sched.getRoutes(), new Comparator<fr.itinerennes.api.client.model.Route>() { @Override public int compare(fr.itinerennes.api.client.model.Route r1, fr.itinerennes.api.client.model.Route r2) { final String id1 = r1.getAgencyId() + r1.getId(); final String id2 = r2.getAgencyId() + r2.getId(); return id1.compareTo(id2); } }); write(new File(output, String.format("%s.json", s.getId())), sched); }
From source file:edu.cwru.apo.Directory.java
public void onRestRequestComplete(Methods method, JSONObject result) { if (method == Methods.phone) { if (result != null) { try { String requestStatus = result.getString("requestStatus"); if (requestStatus.compareTo("success") == 0) { SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE) .edit();/*w w w. ja va 2 s. c om*/ editor.putLong("updateTime", result.getLong("updateTime")); editor.commit(); int numbros = result.getInt("numBros"); JSONArray caseID = result.getJSONArray("caseID"); JSONArray first = result.getJSONArray("first"); JSONArray last = result.getJSONArray("last"); JSONArray phone = result.getJSONArray("phone"); JSONArray family = result.getJSONArray("family"); ContentValues values; for (int i = 0; i < numbros; i++) { values = new ContentValues(); values.put("_id", caseID.getString(i)); values.put("first", first.getString(i)); values.put("last", last.getString(i)); values.put("phone", phone.getString(i)); values.put("family", family.getString(i)); database.replace("phoneDB", null, values); } loadTable(); } else if (requestStatus.compareTo("timestamp invalid") == 0) { Toast msg = Toast.makeText(this, "Invalid timestamp. Please try again.", Toast.LENGTH_LONG); msg.show(); } else if (requestStatus.compareTo("HMAC invalid") == 0) { Auth.loggedIn = false; Toast msg = Toast.makeText(this, "You have been logged out by the server. Please log in again.", Toast.LENGTH_LONG); msg.show(); finish(); } else { Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG); msg.show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:cn.vlabs.duckling.vwb.service.config.impl.DomainServiceImpl.java
@Override public String[] getUsedDomain(int siteId) { Map<String, String> keys = siteConfig.getInteranlPeopertyStartWith(siteId, KeyConstants.SITE_DOMAIN_KEY); LinkedList<String> keyList = new LinkedList<String>(); keyList.addAll(keys.keySet());/*from www . j a v a 2 s . c o m*/ Collections.sort(keyList, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareTo(o2); } }); String[] domains = new String[keys.size()]; int index = 0; for (String key : keyList) { domains[index] = keys.get(key); index++; } return domains; }
From source file:org.jenkinsci.plugins.saml.SamlUserDetailsService.java
public SamlUserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { // try to obtain user details from current authentication details Authentication auth = Jenkins.getAuthentication(); if (auth != null && username.compareTo(auth.getName()) == 0 && auth instanceof SamlAuthenticationToken) { return (SamlUserDetails) auth.getDetails(); }/* w w w. j av a 2 s. com*/ // try to rebuild authentication details based on data stored in user storage User user = User.get(username); if (user == null) { throw new UsernameNotFoundException(username); } List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY); if (username.compareTo(user.getId()) == 0) { LastGrantedAuthoritiesProperty lastGranted = user.getProperty(LastGrantedAuthoritiesProperty.class); if (lastGranted != null) { for (GrantedAuthority a : lastGranted.getAuthorities()) { if (a != SecurityRealm.AUTHENTICATED_AUTHORITY) { SamlGroupAuthority ga = new SamlGroupAuthority(a.getAuthority()); authorities.add(ga); } } } } SamlUserDetails userDetails = new SamlUserDetails(user.getId(), authorities.toArray(new GrantedAuthority[0])); return userDetails; }
From source file:com.appeligo.search.actions.ProgramRemindersPageAction.java
public String execute() throws Exception { //sort programs alphabetically and by programId programAlerts = new LinkedList<ProgramAlert>(getUser().getLiveProgramAlerts()); Collections.sort(programAlerts, new Comparator<ProgramAlert>() { public int compare(ProgramAlert left, ProgramAlert right) { String leftStr = left.getProgram().getLabel(); String rightStr = right.getProgram().getLabel(); int rtn = leftStr.compareTo(rightStr); if (rtn == 0 && left.getProgramId() != null && right.getProgramId() != null) { rtn = left.getProgramId().compareTo(right.getProgramId()); }// w ww . j a v a 2 s . c o m return rtn; } }); //ensure that programAlerts on matching programs are clustered together LinkedList<ProgramAlert> newlist = new LinkedList<ProgramAlert>(); while (programAlerts.size() > 0) { ProgramAlert alert = programAlerts.remove(0); newlist.add(alert); String targetId = alert.getProgramId(); int j = 0; while (j < programAlerts.size()) { if (programAlerts.get(j).getProgramId().equals(targetId)) { newlist.add(programAlerts.remove(j)); } else { j++; } } } programAlerts = newlist; AlertManager alertManager = AlertManager.getInstance(); EPGProvider epgProvider = alertManager.getEpg(); String lineup = getUser().getLineupId(); nextAiringList = new LinkedList<ScheduledProgram>(); String previousTargetId = null; for (ProgramAlert programAlert : programAlerts) { String targetId = programAlert.getProgramId(); if (!targetId.equals(previousTargetId)) { ScheduledProgram nextAiring = null; if (programAlert.isNewEpisodes()) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), true, true); } if (nextAiring == null) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), false, true); } nextAiringList.add(nextAiring); previousTargetId = targetId; } else { nextAiringList.add(null); } } return SUCCESS; }
From source file:io.wcm.config.core.impl.ParameterProviderBridge.java
@SuppressWarnings("unchecked") private ConfigurationMetadata toConfigMetadata(List<Parameter<?>> parameters) { SortedSet<PropertyMetadata<?>> properties = new TreeSet<>(new Comparator<PropertyMetadata<?>>() { @Override/*from ww w . j av a 2 s .com*/ public int compare(PropertyMetadata<?> o1, PropertyMetadata<?> o2) { String sort1 = StringUtils.defaultString(o1.getLabel(), o1.getName()); String sort2 = StringUtils.defaultString(o2.getLabel(), o2.getName()); return sort1.compareTo(sort2); } }); for (Parameter<?> parameter : parameters) { PropertyMetadata<?> property; if (parameter.getType().equals(Map.class)) { property = toPropertyStringArray((Parameter<Map>) parameter); } else { property = toProperty(parameter); } String label = (String) parameter.getProperties().get(EditorProperties.LABEL); String description = (String) parameter.getProperties().get(EditorProperties.DESCRIPTION); String group = (String) parameter.getProperties().get(EditorProperties.GROUP); if (group != null) { label = group + ": " + StringUtils.defaultString(label, parameter.getName()); } properties.add(property.label(label).description(description)); } return new ConfigurationMetadata(DEFAULT_CONFIG_NAME, properties, false) .label("wcm.io Configuration Parameters"); }
From source file:com.sldeditor.test.unit.tool.mapbox.MapBoxToolTest.java
/** * Test method for {@link com.sldeditor.tool.mapbox.MapBoxTool#getToolName()}. *//*ww w. j a va 2s.c om*/ @Test public void testGetToolName() { MapBoxTool tool = new MapBoxTool(); String toolName = tool.getToolName(); assertTrue(toolName.compareTo("com.sldeditor.tool.mapbox.MapBoxTool") == 0); }
From source file:me.crime.loader.DataBaseLoader.java
@Override public void endElement(String uri, String localName, String name) throws SAXException { if (name.compareTo(XmlTags.ELEMENT) == 0) { saveData(current_, buffer_.toString().trim(), curObject_); buffer_.delete(0, buffer_.length()); } else if (name.compareTo(XmlTags.CLASS) == 0) { if (stack_.empty()) { //( curObject_ instanceof me.crime.database.Crime ) { // Crime cr = Crime.class.cast(curObject_); //}/* www. j a v a 2 s .c o m*/ try { curObject_.save(); } catch (SQLException e) { e.printStackTrace(); } count_++; curObject_ = null; } else { XmlReadable tmp = curObject_; curObject_ = stack_.pop(); try { curObject_.handleObject(tmp); } catch (SQLException e) { e.printStackTrace(); } } } }