List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:models.NotificationEvent.java
public static NotificationEvent afterStateChanged(CommentThread.ThreadState oldState, CommentThread thread) throws IOException, SVNException, ServletException { NotificationEvent notiEvent = createFromCurrentUser(thread); notiEvent.eventType = REVIEW_THREAD_STATE_CHANGED; notiEvent.oldValue = oldState.name() != null ? oldState.name() : null; notiEvent.newValue = thread.state.name(); // Set receivers Set<User> receivers; if (thread.isOnPullRequest()) { PullRequest pullRequest = thread.pullRequest; notiEvent.title = formatReplyTitle(pullRequest); receivers = pullRequest.getWatchers(); } else {/*from w ww . ja v a 2s . c om*/ String commitId; if (thread instanceof CodeCommentThread) { commitId = ((CodeCommentThread) thread).commitId; } else { commitId = ((NonRangedCodeCommentThread) thread).commitId; } Project project = thread.project; Commit commit = RepositoryService.getRepository(project).getCommit(commitId); notiEvent.title = formatReplyTitle(project, commit); receivers = commit.getWatchers(project); } receivers.remove(UserApp.currentUser()); notiEvent.receivers = receivers; NotificationEvent.add(notiEvent); return notiEvent; }
From source file:edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance.java
/** * Implements Dijkstra's single-source shortest-path algorithm for * weighted graphs. Uses a <code>MapBinaryHeap</code> as the priority queue, * which gives this algorithm a time complexity of O(m lg n) (m = # of edges, n = * # of vertices)./*from w ww.j a v a2 s. com*/ * This algorithm will terminate when any of the following have occurred (in order * of priority): * <ul> * <li> the distance to the specified target (if any) has been found * <li> no more vertices are reachable * <li> the specified # of distances have been found, or the maximum distance * desired has been exceeded * <li> all distances have been found * </ul> * * @param source the vertex from which distances are to be measured * @param numDests the number of distances to measure * @param targets the set of vertices to which distances are to be measured */ protected LinkedHashMap<V, Number> singleSourceShortestPath(V source, Collection<V> targets, int numDests) { SourceData sd = getSourceData(source); Set<V> to_get = new HashSet<V>(); if (targets != null) { to_get.addAll(targets); Set<V> existing_dists = sd.distances.keySet(); for (V o : targets) { if (existing_dists.contains(o)) to_get.remove(o); } } // if we've exceeded the max distance or max # of distances we're willing to calculate, or // if we already have all the distances we need, // terminate if (sd.reached_max || (targets != null && to_get.isEmpty()) || (sd.distances.size() >= numDests)) { return sd.distances; } while (!sd.unknownVertices.isEmpty() && (sd.distances.size() < numDests || !to_get.isEmpty())) { Map.Entry<V, Number> p = sd.getNextVertex(); V v = p.getKey(); double v_dist = p.getValue().doubleValue(); to_get.remove(v); if (v_dist > this.max_distance) { // we're done; put this vertex back in so that we're not including // a distance beyond what we specified sd.restoreVertex(v, v_dist); sd.reached_max = true; break; } sd.dist_reached = v_dist; if (sd.distances.size() >= this.max_targets) { sd.reached_max = true; break; } for (E e : getEdgesToCheck(v)) { for (V w : g.getIncidentVertices(e)) { if (!sd.distances.containsKey(w)) { double edge_weight = nev.transform(e).doubleValue(); if (edge_weight < 0) throw new IllegalArgumentException("Edges weights must be non-negative"); double new_dist = v_dist + edge_weight; if (!sd.estimatedDistances.containsKey(w)) { sd.createRecord(w, e, new_dist); } else { double w_dist = ((Double) sd.estimatedDistances.get(w)).doubleValue(); if (new_dist < w_dist) // update tentative distance & path for w sd.update(w, e, new_dist); } } } } } return sd.distances; }
From source file:fungus.HyphaLink.java
public MycoList get2Neighbors() { Set<MycoNode> set = new HashSet<MycoNode>(); for (MycoNode n : getHyphae()) { set.addAll(n.getHyphaLink().getNeighbors()); }//from w ww. j a v a 2 s . com set.remove(myNode); set.remove(neighbors); return new MycoList(set); }
From source file:io.confluent.kafka.connect.source.io.processing.csv.SchemaConfig.java
public Pair<ParserConfig, ParserConfig> parserConfigs(SpoolDirectoryConfig config) { Preconditions.checkNotNull(fields, "fields cannot be null."); Preconditions.checkNotNull(name, "SchemaConfig.name cannot be null"); Preconditions.checkState(!name.isEmpty(), "SchemaConfig.name cannot be null"); Preconditions.checkState(!name.equalsIgnoreCase(keyName), "SchemaConfig.name and SchemaConfig.keyName cannot be the same."); SchemaBuilder valueBuilder = SchemaBuilder.struct(); valueBuilder.name(this.name); Preconditions.checkNotNull(keys, "keys cannot be null."); SchemaBuilder keyBuilder = SchemaBuilder.struct(); if (null == this.keyName || this.keyName.isEmpty()) { String keySchemaName = (this.name == null ? "" : this.name) + "Key"; keyBuilder.name(keySchemaName);/*from w ww. j a va2 s.co m*/ } else { keyBuilder.name(this.keyName); } Set<String> keyLookup = new HashSet<>(this.keys); List<FieldMapping> valueMaps = new ArrayList<>(); List<FieldMapping> keyMaps = new ArrayList<>(); for (FieldConfig fieldConfig : this.fields) { valueBuilder.field(fieldConfig.name, fieldConfig.schema()); FieldMapping mapping = new FieldMapping(fieldConfig.index, fieldConfig.name, fieldConfig.schema()); valueMaps.add(mapping); if (keyLookup.contains(fieldConfig.name)) { keyMaps.add(mapping); keyBuilder.field(fieldConfig.name, fieldConfig.schema()); keyLookup.remove(fieldConfig.name); } } Preconditions.checkState(keyLookup.isEmpty(), "Keys specified were not found in the schema. The following key field(s) " + "were not found: %s", Joiner.on(",").join(keyLookup)); if (config.includeFileMetadata()) { FileMetadata.addFieldSchema(valueBuilder); } ParserConfig keyParserConfig = new ParserConfig(this.keys.isEmpty() ? null : keyBuilder.build(), keyMaps); ParserConfig valueParserConfig = new ParserConfig(valueBuilder.build(), valueMaps); return new ImmutablePair<>(keyParserConfig, valueParserConfig); }
From source file:org.openmrs.web.controller.person.PersonAttributeTypeFormController.java
/** * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest, * java.lang.Object, org.springframework.validation.Errors) *//*from ww w .ja va2 s . c om*/ protected Map<String, Object> referenceData(HttpServletRequest request, Object obj, Errors errors) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); List<Privilege> privileges = new ArrayList<Privilege>(); if (Context.isAuthenticated()) { privileges = Context.getUserService().getAllPrivileges(); } Set<String> formats = new TreeSet<String>( FieldGenHandlerFactory.getSingletonInstance().getHandlers().keySet()); // these formats are handled directly by the FieldGenTag.java class and so aren't in the // "handlers" list in openmrs-servlet.xml formats.add("java.lang.Character"); formats.add("java.lang.Integer"); formats.add("java.lang.Float"); formats.add("java.lang.Boolean"); // java.util.Date doesn't work as a PersonAttributeType since it gets saved in a user-date-format-specific way formats.remove("java.util.Date"); //Removing these two as per ticket: TRUNK-2460 formats.remove("org.openmrs.Patient.exitReason"); formats.remove("org.openmrs.DrugOrder.discontinuedReason"); map.put("privileges", privileges); map.put("formats", formats); return map; }
From source file:de.nava.informa.utils.PersistChanGrpMgr.java
/** * Deletes persistent group./*from ww w .j a v a 2 s . c o m*/ */ public void deleteGroup() { if (group == null) return; LOG.debug("Deleting Persistent Group: " + group.getTitle()); synchronized (builder) { try { builder.beginTransaction(); builder.reload(group); // Remove group from links with channels Channel[] chans = (Channel[]) group.getChannels().toArray(new Channel[group.getChannels().size()]); for (Channel chan : chans) { final Set<ChannelGroup> grps = chan.getGroups(); grps.remove(group); group.getChannels().remove(chan); // Delete channel if it was the last group it was assigned to if (grps.size() == 0) builder.delete(chan); } builder.delete(group); builder.endTransaction(); group = null; } catch (ChannelBuilderException e) { LOG.error("Unable to delete Persistent Group: " + e.getMessage()); builder.resetTransaction(); } } }
From source file:edu.asu.ca.kaushik.algorithms.structures.InteractionGraph.java
public int deleteInteractions(Integer[] newRandRow, InteractionGraph sampledIg, Object object) { int coverage = 0; int coverageSIG = 0; Iterator<ColGroup> colGrIt = this.graph.keySet().iterator(); while (colGrIt.hasNext()) { ColGroup colGr = colGrIt.next(); int[] indices = colGr.getCols(); int[] syms = new int[this.t]; for (int i = 0; i < this.t; i++) { syms[i] = newRandRow[indices[i]].intValue(); }/*from w w w. j av a 2 s . c o m*/ SymTuple tuple = new SymTuple(syms); Set<SymTuple> set = this.graph.get(colGr); if (set.contains(tuple)) { coverage += 1; set.remove(tuple); if (set.isEmpty()) { colGrIt.remove(); } if (sampledIg.graph.containsKey(colGr)) { Set<SymTuple> symSet = sampledIg.graph.get(colGr); if (symSet.contains(tuple)) { symSet.remove(tuple); coverageSIG += 1; if (symSet.isEmpty()) { sampledIg.graph.remove(colGr); } } } } } this.numUncovInt = this.numUncovInt - coverage; sampledIg.numUncovInt = sampledIg.numUncovInt - coverageSIG; return coverage; }
From source file:com.jsen.core.misc.MimeContentRegistryBase.java
/** * Unregisters given factory from this registry. * /*from ww w. j ava 2 s . c o m*/ * @param factoryClass Class of the MIME content factory which should be unregistered. */ public void unregisterMimeContentFactory(Class<? extends MimeContentFactory> factoryClass) { synchronized (this) { Set<Entry<String, Set<MimeContentFactory>>> factoriesEntrySet = registeredFactories.entrySet(); List<String> mimeTypesToRemove = new ArrayList<String>(); for (Entry<String, Set<MimeContentFactory>> entry : factoriesEntrySet) { Set<MimeContentFactory> factories = entry.getValue(); MimeContentFactoryBase<?> factoryToRemove = null; for (MimeContentFactory factory : factories) { if (factory.getClass().equals(factoryClass)) { factoryToRemove = factory; } } if (factories.size() == 1 && factoryToRemove != null) { mimeTypesToRemove.add(entry.getKey()); } factories.remove(factoryToRemove); } } }
From source file:com.chiorichan.site.SiteDomain.java
public void unmapDomain(String domain) { Validate.notEmpty(domain);// w ww .j a v a 2 s. c o m domain = domain.toLowerCase(); if ("root".equalsIgnoreCase(subdomain)) { Set<String> subdomains = site.domains.get(domain); if (subdomains != null && subdomains.size() == 0) { site.domains.remove(domain); site.yaml.set("site.domains." + domain.replace(".", "_"), null); } else if (subdomains != null) throw new IllegalStateException( "Can't unmap root domain from site while subdomains are maped, remove these first: " + Joiner.on(",").join(subdomains)); } else { Set<String> subdomains = site.domains.get(domain); if (subdomains != null) subdomains.remove(subdomain); if (site.yaml.has("site.domains." + domain.replace(".", "_"))) site.yaml.set("site.domains." + domain.replace(".", "_") + "." + subdomain.replace(".", "_"), null); } EventBus.instance() .callEvent(new SiteDomainChangeEvent(SiteDomainChangeEventType.REMOVE, site, domain, this)); }