List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:act.installer.bing.BingSearchResults.java
/** Heuristic to find the best name for a given InChI, based on the total number of search results * @param namesOfMolecule (NamesOfMolecule) Java object containing Brenda, MetaCyc, ChEBI and DrugBank names for a given * InChI.//from ww w . j ava 2 s .c o m * @return the name with the highest total number of search results, called Best Name * @throws IOException */ public String findBestMoleculeName(NamesOfMolecule namesOfMolecule) throws IOException { Long maxCount = -1L; String bestName = ""; String inchi = namesOfMolecule.getInchi(); String[] splittedInchi = inchi.split("/"); String formulaFromInchi = null; if (splittedInchi.length >= 2) { formulaFromInchi = inchi.split("/")[1]; } LOGGER.debug("Formula %s extracted from %s", formulaFromInchi, inchi); String wikipediaName = namesOfMolecule.getWikipediaName(); if (wikipediaName != null) { bestName = wikipediaName; } else { Set<String> names = namesOfMolecule.getAllNames(); names.remove(formulaFromInchi); for (String name : names) { // Ignore name if <= 4 characters if (name.length() <= 4) { continue; } LOGGER.debug("Getting search hits for %s", name); Long count = (cacheOnly) ? getTotalCountSearchResultsFromCache(name) : getAndCacheTotalCountSearchResults(name); // Ignore name if there was a previous better candidate if (count <= maxCount) { continue; } maxCount = count; bestName = name; } } // Note we don't use ChEBI or DrugBank names to keep this function simple. // If Brenda and MetaCyc names are not populated, it is very rare that ChEBI or DrugBank would be. LOGGER.debug("Best name found for %s is %s", namesOfMolecule.getInchi(), bestName); return bestName; }
From source file:com.almende.demo.conferenceApp.ConferenceAgent.java
public Info getMyInfo() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); final String myName = prefs.getString(ctx.getString(R.string.myName_key), "person:" + getId()); final Info myInfo = new Info(getId()); myInfo.setName(myName);//from www .j a v a 2s.c o m final String paperTitle = prefs.getString(ctx.getString(R.string.paperTitle_key), "---"); myInfo.setTitle(paperTitle); myInfo.setKnownNames(getKnownNames()); final String phoneNumberPref = prefs.getString(ctx.getString(R.string.phoneNumbers_key), ""); final Set<String> phoneNumberSet = new HashSet<String>(); final String[] phoneNumbers = phoneNumberPref.split(","); phoneNumberSet.addAll(Arrays.asList(phoneNumbers)); phoneNumberSet.remove(null); myInfo.setPhonenumbers(phoneNumberSet); System.err.println("Sending myInfo:" + JOM.getInstance().valueToTree(myInfo)); return myInfo; }
From source file:io.tilt.minka.spectator.Spectator.java
protected void remove(final String name, final UserInstanceObject uio) { Set<UserInstanceObject> set = mapObjects.get(name); if (set != null) { set.remove(uio); }/*from www . java2 s . co m*/ }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ClientDetailsAdapter.java
/** * Fill in the DB object with the properties of {@link ClientAppBasic} instance. In case of problem, return null. * @param client/*from w w w. j a va 2 s. c o m*/ * @param data * @return * @throws Exception */ public ClientDetailsEntity convertFromClientApp(ClientDetailsEntity client, ClientAppBasic data) { try { ClientAppInfo info = null; if (client.getAdditionalInformation() == null) { info = new ClientAppInfo(); } else { info = ClientAppInfo.convert(client.getAdditionalInformation()); } info.setName(data.getName()); info.setNativeAppsAccess(data.isNativeAppsAccess()); Set<String> types = new HashSet<String>(client.getAuthorizedGrantTypes()); if (data.isBrowserAccess()) { types.add(GT_IMPLICIT); } else { types.remove(GT_IMPLICIT); } if (data.isServerSideAccess() || data.isNativeAppsAccess()) { types.add(GT_AUTHORIZATION_CODE); types.add(GT_REFRESH_TOKEN); } else { types.remove(GT_AUTHORIZATION_CODE); types.remove(GT_REFRESH_TOKEN); } client.setAuthorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(types)); if (info.getIdentityProviders() == null) { info.setIdentityProviders(new HashMap<String, Integer>()); } for (String key : attributesAdapter.getAuthorityUrls().keySet()) { if (data.getIdentityProviders().get(key)) { Integer value = info.getIdentityProviders().get(key); AuthorityMapping a = attributesAdapter.getAuthority(key); if (value == null || value == ClientAppInfo.UNKNOWN) { info.getIdentityProviders().put(key, a.isPublic() ? ClientAppInfo.APPROVED : ClientAppInfo.REQUESTED); } } else { info.getIdentityProviders().remove(key); } } client.setAdditionalInformation(info.toJson()); client.setRedirectUri(data.getRedirectUris()); } catch (Exception e) { log.error("failed to convert an object: " + e.getMessage(), e); return null; } return client; }
From source file:org.openmrs.web.controller.patient.ShortPatientFormValidatorTest.java
/** * @see ShortPatientFormValidator#validate(Object,Errors) *//*from w w w. j a va 2 s .com*/ @Test @Verifies(value = "should fail if no identifiers are added", method = "validate(Object,Errors)") public void validate_shouldFailIfNoIdentifiersAreAdded() throws Exception { Patient p = ps.getPatient(2); List<PatientIdentifier> activeIdentifiers = p.getActiveIdentifiers(); Set<PatientIdentifier> patientIdentifiers = p.getIdentifiers(); //remove all the active identifiers for (PatientIdentifier activeIdentifier : activeIdentifiers) patientIdentifiers.remove(activeIdentifier); p.setIdentifiers(patientIdentifiers); ShortPatientModel model = new ShortPatientModel(p); Errors errors = new BindException(model, "patientModel"); validator.validate(model, errors); Assert.assertEquals(true, errors.hasGlobalErrors()); }
From source file:com.mirth.connect.client.ui.ChannelTagDialog.java
@Override public void setVisible(boolean visible) { if (visible) { Dimension dlgSize = getPreferredSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { setLocationRelativeTo(null); } else {//from ww w . j a va 2 s. c om setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } Set<String> availableTags = new LinkedHashSet<String>(parent.getChannelTagInfo(false).getTags()); DefaultTableModel model = (DefaultTableModel) tagTable.getModel(); int rowCount = model.getRowCount(); for (int i = 0; i < rowCount; i++) { availableTags.remove(model.getValueAt(i, 0)); } tagComboBox.setModel(new DefaultComboBoxModel(availableTags.toArray())); if (availableTags.size() > 0) { tagComboBox.setSelectedIndex(0); } tagComboBox.requestFocusInWindow(); } super.setVisible(visible); }
From source file:com.kuprowski.redis.security.core.session.RedisSessionRegistry.java
@Override public void removeSessionInformation(String sessionId) { Assert.hasText(sessionId, "SessionId required as per interface contract"); SessionInformation info = getSessionInformation(sessionId); if (info == null) { return;/* w ww. ja v a 2 s . co m*/ } if (logger.isTraceEnabled()) { logger.debug("Removing session " + sessionId + " from set of registered sessions"); } sessionIdsTemplate.delete(buildSessionIdsKey(sessionId)); Set<String> sessionsUsedByPrincipal = getSessionsUsedByPrincipal(info.getPrincipal()); if (sessionsUsedByPrincipal == null) { return; } if (logger.isDebugEnabled()) { logger.debug("Removing session " + sessionId + " from principal's set of registered sessions"); } sessionsUsedByPrincipal.remove(sessionId); principalsTemplate.opsForSet().remove(buildPrincipalKey(info.getPrincipal()), sessionId); if (sessionsUsedByPrincipal.isEmpty()) { // No need to keep object in principals Map anymore if (logger.isDebugEnabled()) { logger.debug("Removing principal " + info.getPrincipal() + " from registry"); } //TODO REMOVE //principalsTemplate.Ops.remove(info.getPrincipal()); } if (logger.isTraceEnabled()) { logger.trace("Sessions used by '" + info.getPrincipal() + "' : " + sessionsUsedByPrincipal); } }
From source file:dk.netarkivet.monitor.registry.MonitorRegistry.java
/** * Register a new JMX host entry.//from w ww. j av a 2 s . c o m * @param hostEntry The entry to add * * @throws ArgumentNotValid if hostEntry is null. */ public synchronized void register(HostEntry hostEntry) { ArgumentNotValid.checkNotNull(hostEntry, "HostEntry hostEntry"); Set<HostEntry> set = hostEntries.get(hostEntry.getName()); if (set == null) { set = Collections.synchronizedSet(new HashSet<HostEntry>()); hostEntries.put(hostEntry.getName(), set); } if (set.add(hostEntry)) { log.info("Added host '" + hostEntry.getName() + "' port " + hostEntry.getJmxPort() + "/" + hostEntry.getRmiPort()); } else { set.remove(hostEntry); set.add(hostEntry); log.trace("Updated time for '" + hostEntry.getName() + "' port " + hostEntry.getJmxPort() + "/" + hostEntry.getRmiPort() + " to " + hostEntry.getTime()); } }
From source file:ar.edu.famaf.nlp.alusivo.GraphAlgorithm.java
private boolean matchHelper(Map<Resource, Resource> bijection, // pi Set<Resource> neighbors, // Y DirectedPseudograph<Resource, Edge> fullGraph, // G DirectedPseudograph<Resource, Edge> candidate, // H long startTime) throws ReferringExpressionException { if (bijection.keySet().size() == candidate.vertexSet().size()) { return true; }/* w w w. j ava 2s . c om*/ if (neighbors.isEmpty()) { return false; } if (System.currentTimeMillis() - startTime > maxTime) throw new ReferringExpressionException("Time-out"); for (Resource toMap : neighbors) { // y if (bijection.containsKey(toMap)) continue; // find valid matches Z for (Resource extension : fullGraph.vertexSet()) { // z if (bijection.values().contains(extension) || bijection.keySet().contains(extension)) continue; if (!containedPropertiesInSubgraph(toMap, candidate, extension, fullGraph)) continue; Set<Resource> toCheck = neighbors(candidate, toMap); toCheck.retainAll(bijection.keySet()); boolean good = true; for (Resource other : toCheck) { // h // (toMap -> other) y->h Set<Edge> outgoing = candidate.getAllEdges(toMap, other); if (!fullGraph.getAllEdges(extension, bijection.get(other)).containsAll(outgoing)) { good = false; break; } // (other -> toMap) y->h Set<Edge> incoming = candidate.getAllEdges(other, toMap); if (!fullGraph.getAllEdges(bijection.get(other), extension).containsAll(incoming)) { good = false; break; } } if (!good) continue; Map<Resource, Resource> bijectionRec = new HashMap<>(); bijectionRec.putAll(bijection); bijectionRec.put(toMap, extension); Set<Resource> neighborsRec = new HashSet<Resource>(neighbors); neighborsRec.remove(toMap); // not in Figure 8 if (matchHelper(bijectionRec, neighborsRec, fullGraph, candidate, startTime)) return true; } } return false; }
From source file:com.capstone.giveout.controllers.GiftsController.java
@PreAuthorize("hasRole(mobile)") @RequestMapping(value = Routes.GIFTS_INAPPROPRIATE_PATH, method = RequestMethod.PUT) public @ResponseBody Gift markOrUnmarkAsInappropiate(@PathVariable("id") long id, @RequestParam(value = Routes.REGRET_PARAMETER, required = false, defaultValue = "false") boolean regret, Principal p, HttpServletResponse response) { Gift gift = gifts.findOne(id);// w ww . j av a2 s .c o m if (gift == null) { response.setStatus(404); return null; } gift.allowAccessToGiftChain = true; long userId = users.findByUsername(p.getName()).getId(); Set<Long> markedAsInappropriateBy = gift.getMarkedInappropriateByUserIds(); // Mark or unmark as inappropriate more than once will have no effect. if (regret) { markedAsInappropriateBy.remove(userId); } else { markedAsInappropriateBy.add(userId); } gifts.save(gift); return gift; }