List of usage examples for java.util HashSet removeAll
boolean removeAll(Collection<?> c);
From source file:com.clustercontrol.jobmanagement.factory.ModifyJob.java
public Long replaceJobunit(List<JobInfo> oldList, List<JobInfo> newList, String userId) throws JobInvalid, JobMasterNotFound, EntityExistsException, HinemosUnknown, JobMasterDuplicate, InvalidSetting, InvalidRole {/* ww w . ja v a 2 s . c o m*/ //?ID? String jobunitId = newList.get(0).getJobunitId(); // long start = HinemosTime.currentTimeMillis(); HashSet<JobInfo> delJobs = new HashSet<JobInfo>(oldList); HashSet<JobInfo> newJobs = new HashSet<JobInfo>(newList); delJobs.removeAll(newJobs); long timeJobToDelete = HinemosTime.currentTimeMillis(); m_log.info("Find jobs to delete " + (timeJobToDelete - start) + "ms"); HashSet<JobInfo> addJobs = newJobs; addJobs.removeAll(new HashSet<JobInfo>(oldList)); long timeJobToAdd = HinemosTime.currentTimeMillis(); m_log.info("Find jobs to add " + (timeJobToAdd - timeJobToDelete) + "ms"); m_log.info("oldList=" + oldList.size() + ", newList=" + newList.size() + ", delJobs=" + delJobs.size() + ", addJobs=" + addJobs.size()); JpaTransactionManager jtm = new JpaTransactionManager(); for (JobInfo delJob : delJobs) { JobMstEntity entity = QueryUtil.getJobMstPK(delJob.getJobunitId(), delJob.getId()); deleteJob(entity); } jtm.flush(); long timestamp = HinemosTime.currentTimeMillis(); // ???????? for (JobInfo addJob : addJobs) { int type = addJob.getType(); if (type == JobConstant.TYPE_JOBUNIT) { String jobId = addJob.getId(); String parentJobId = addJob.getParentId(); if (jobunitId.equals(jobId)) { parentJobId = CreateJobSession.TOP_JOB_ID; } createJobMasterData(addJob, jobunitId, parentJobId, userId, timestamp); addJobs.remove(addJob); break; } } for (JobInfo addJob : addJobs) { String jobId = addJob.getId(); String parentJobId = addJob.getParentId(); if (jobunitId.equals(jobId)) { parentJobId = CreateJobSession.TOP_JOB_ID; } createJobMasterData(addJob, jobunitId, parentJobId, userId, timestamp); } // ?? String jobId = newList.get(0).getId(); JobMstEntity entity = QueryUtil.getJobMstPK(jobunitId, jobId); entity.setUpdateDate(timestamp); m_log.info("Left tasks in replaceJobunit " + (HinemosTime.currentTimeMillis() - timeJobToAdd) + "ms"); // ?? return timestamp; }
From source file:org.fusesource.meshkeeper.distribution.LaunchClient.java
/** * Releases previously reserved ports at the launcher. *//*from w ww. j a v a 2s . com*/ public synchronized void releasePorts(String agentName, Collection<Integer> ports) throws Exception { agentName = agentName.toUpperCase(); HashSet<Integer> reserved = reservedPorts.get(agentName); if (reserved != null) { reserved.removeAll(ports); if (reserved.isEmpty()) { reservedPorts.remove(agentName); } } LaunchAgentService agent = getAgent(agentName); agent.releaseTcpPorts(ports); }
From source file:net.bluehornreader.service.FeedCrawlerService.java
/** * If there's any change, it deletes all previous feeds. Whould be nicer to keep what already exists but not sure it's worth it * * @throws Exception/*w w w.j a va 2s . c o m*/ */ private void updateFeedList() throws Exception { int feedIdsSeq = crawlerDb.getFeedIdsSeq(crawler.crawlerId); if (crawler.feedIdsSeq == feedIdsSeq) { return; } LOG.info("Feed list changed"); HashMap<String, FeedInfo> newFeedMap = new HashMap<>(); Crawler newCrawler = crawlerDb.getCrawler(crawler.crawlerId); synchronized (this) { // Some feeds might be being crawled at this time; we don't want to end up with 2 entries for them in availableFeeds, so we don't add them HashSet<String> crawlingFeedIds = new HashSet<>(feedMap.keySet()); { HashSet<String> availableFeedIds = new HashSet<>(); for (FeedInfo feedInfo : availableFeeds) { availableFeedIds.add(feedInfo.feed.feedId); } crawlingFeedIds.removeAll(availableFeedIds); } availableFeeds = new PriorityQueue<>(newFeedMap.size() + 1, feedInfoComparator); for (String feedId : newCrawler.feedIds) { Feed feed = feedDb.get(feedId); if (feed == null) { LOG.warn(String.format( "FeedCrawlerService %s was asked to crawl feed %s but couldn't find such a feed", IP, feedId)); } else { FeedInfo feedInfo = feedMap.get(feedId); if (feedInfo == null) { feedInfo = new FeedInfo(feed, getSeq()); LOG.info("New feed to crawl: " + feedInfo); } newFeedMap.put(feedId, feedInfo); if (crawlingFeedIds.contains(feedId)) { LOG.info(String.format( "Feed %s is being currently crawled, so it's not going to be added to the list with available feeds", feedInfo)); } else { availableFeeds.add(feedInfo); } } } feedMap = newFeedMap; crawler.feedIdsSeq = feedIdsSeq; LOG.info("Feeds to crawl: " + feedMap); } }
From source file:fr.openbike.android.database.OpenBikeDBAdapter.java
public boolean syncStations(JSONArray jsonBikes) throws SQLiteException, JSONException { if ("".equals(jsonBikes)) return false; boolean needUpdate = false; final int size = jsonBikes.length(); JSONObject jsonStation;/*from w ww.j a va 2 s.co m*/ try { mDb.beginTransaction(); ContentValues contentValues = new ContentValues(); final int networkId = jsonBikes.getJSONObject(0).getInt(Station.NETWORK); HashSet<Integer> ids = new HashSet<Integer>(size); for (int i = 0; i < size; i++) { jsonStation = jsonBikes.getJSONObject(i); int id = jsonStation.getInt("id"); ids.add(id); contentValues.put(OpenBikeDBAdapter.KEY_BIKES, jsonStation.getInt(Station.BIKES)); contentValues.put(OpenBikeDBAdapter.KEY_SLOTS, jsonStation.getInt(Station.SLOTS)); contentValues.put(OpenBikeDBAdapter.KEY_OPEN, jsonStation.getBoolean(Station.OPEN)); if (mDb.update(STATIONS_TABLE, contentValues, BaseColumns._ID + " = " + id + " AND " + KEY_NETWORK + " = " + networkId, null) == 0) { needUpdate = true; break; } } if (!needUpdate) { Cursor cursorIds = mDb.query(STATIONS_TABLE, new String[] { BaseColumns._ID }, KEY_NETWORK + " = " + networkId, null, null, null, null); HashSet<Integer> oldIds = new HashSet<Integer>(cursorIds.getCount()); if (cursorIds.moveToFirst()) { do { oldIds.add(cursorIds.getInt(0)); } while (cursorIds.moveToNext()); } oldIds.removeAll(ids); for (Integer id : oldIds) { mDb.delete(STATIONS_TABLE, BaseColumns._ID + " = " + id + " AND " + KEY_NETWORK + " = " + networkId, null); } } } catch (SQLiteException e) { mDb.endTransaction(); throw e; } catch (JSONException e) { mDb.endTransaction(); throw e; } mDb.setTransactionSuccessful(); mDb.endTransaction(); return needUpdate; }
From source file:pathwaynet.PathwayCalculator.java
private <E> TestResultForList testForGivenListWilcoxBased(Graph<E, String> graph, Collection<E> componentsInGroup, Collection<E> componentsConsidered, boolean onlyFromSource) { double p = Double.NaN; double meanInGroup = Double.NaN; double meanOutGroup = Double.NaN; // calculate and cache all distances DijkstraDistance<E, String> distances = new DijkstraDistance<>(graph); HashMap<E, Map<E, Number>> distancesMap = new HashMap<>(); graph.getVertices().stream().forEach((component) -> { Map<E, Number> distancesFromThis = distances.getDistanceMap(component); distancesMap.put(component, distancesFromThis); });/* ww w . j a v a2s .c o m*/ // generate in-group list and out-group list HashSet<E> componentsInGroupAvailable = new HashSet<>(); HashSet<E> componentsOutGroupAvailable = new HashSet<>(); componentsInGroupAvailable.addAll(graph.getVertices()); componentsOutGroupAvailable.addAll(graph.getVertices()); componentsInGroupAvailable.retainAll(componentsConsidered); componentsOutGroupAvailable.retainAll(componentsConsidered); componentsInGroupAvailable.retainAll(componentsInGroup); componentsOutGroupAvailable.removeAll(componentsInGroup); // store within-group distances for the given list, as well as distances between components in the list and ones out of the list ArrayList<Double> distInGroup = new ArrayList<>(); ArrayList<Double> distOutGroup = new ArrayList<>(); componentsInGroupAvailable.forEach((component1) -> { componentsInGroupAvailable.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distInGroup.add(minDist.doubleValue()); } }); componentsOutGroupAvailable.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distOutGroup.add(minDist.doubleValue()); } }); }); if (distInGroup.size() >= 2 && distOutGroup.size() >= 2) { double[] distInGroupVector = new double[distInGroup.size()]; double[] distOutGroupVector = new double[distOutGroup.size()]; for (int i = 0; i < distInGroup.size(); i++) distInGroupVector[i] = distInGroup.get(i); for (int i = 0; i < distOutGroup.size(); i++) distOutGroupVector[i] = distOutGroup.get(i); p = new MannWhitneyUTest().mannWhitneyUTest(distInGroupVector, distOutGroupVector); //System.err.println(distInGroup+"\t"+distOutGroup); meanInGroup = new Mean().evaluate(distInGroupVector); meanOutGroup = new Mean().evaluate(distOutGroupVector); } else { System.err.println("Error: please check your list: too few components involving in the pathway"); } return new TestResultForList(p, meanInGroup, meanOutGroup); }
From source file:org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserModel.java
/** * Implemented as specified by the {@link Browser} interface. * @see Browser#setNodesSelection(Collection) *//*from w w w . j a va 2 s . c om*/ public void setNodesSelection(Collection<ImageDisplay> nodes) { if (nodes == null) return; setNodesColor(nodes, getSelectedDisplays()); final HashSet<ImageDisplay> previouslySelectedDisplays = new HashSet<ImageDisplay>(this.selectedDisplays); previouslySelectedDisplays.removeAll(nodes); Colors colors = Colors.getInstance(); for (final ImageDisplay node : previouslySelectedDisplays) { node.setHighlight(colors.getDeselectedHighLight(node)); selectedDisplays.remove(node); } boolean multiSelection = false; Set<ImageDisplay> oldValue = new HashSet<ImageDisplay>(selectedDisplays); for (final ImageDisplay node : nodes) { setSelectedDisplay(node, multiSelection, false); multiSelection = true; } firePropertyChange(SELECTED_DATA_BROWSER_NODES_DISPLAY_PROPERTY, oldValue, selectedDisplays); }
From source file:de.dfki.km.perspecting.obie.model.Document.java
/** * //from w w w . j a v a 2 s . c o m * @param clusters * @return */ public List<TokenSequence<SemanticEntity>> getUnambiguoslyTypedEntities(Map<Integer, Integer> clusters, Set<Integer> rootLabels) { TIntObjectHashMap<List<TokenSequence<SemanticEntity>>> m = new TIntObjectHashMap<List<TokenSequence<SemanticEntity>>>(); List<TokenSequence<SemanticEntity>> out = new ArrayList<TokenSequence<SemanticEntity>>(); // aggregate equally positioned TokenSequence on different // SemanticEntities for (TokenSequence<SemanticEntity> e : getResolvedSubjects()) { List<TokenSequence<SemanticEntity>> se = m.get(e.getStart()); if (se == null) { se = new ArrayList<TokenSequence<SemanticEntity>>(); m.put(e.getStart(), se); } se.add(e); } // filter unambiguous entities for (int key : m.keys()) { HashSet<Integer> types = new HashSet<Integer>(); TokenSequence<SemanticEntity> phrase = null; for (TokenSequence<SemanticEntity> se : m.get(key)) { phrase = se; for (TIntDoubleTuple t : se.getValue().getTypeIndex()) { types.add(t.key); } } types.removeAll(rootLabels); Integer label = getClusterLabel(clusters, types); if (label != null) { SemanticEntity semEnt = new SemanticEntity(); semEnt.addTypeIndex(label, 1.0); TokenSequence<SemanticEntity> ts = new TokenSequence<SemanticEntity>(semEnt); // copy tokens of phrase for (Token t : phrase.getTokens()) { ts.addToken(t); } out.add(ts); } } return out; }
From source file:org.apache.accumulo.server.gc.SimpleGarbageCollector.java
private void cleanUpDeletedTableDirs(SortedSet<String> candidates) throws Exception { HashSet<String> tableIdsWithDeletes = new HashSet<String>(); // find the table ids that had dirs deleted for (String delete : candidates) { if (isDir(delete)) { String tableId = delete.split("/")[1]; tableIdsWithDeletes.add(tableId); }//from www. j a v a 2 s .co m } Tables.clearCache(instance); Set<String> tableIdsInZookeeper = Tables.getIdToNameMap(instance).keySet(); tableIdsWithDeletes.removeAll(tableIdsInZookeeper); // tableIdsWithDeletes should now contain the set of deleted tables that had dirs deleted for (String delTableId : tableIdsWithDeletes) { // if dir exist and is empty, then empty list is returned... if dir does not exist // then null is returned FileStatus[] tabletDirs = fs.listStatus(new Path(ServerConstants.getTablesDir() + "/" + delTableId)); if (tabletDirs == null) continue; if (tabletDirs.length == 0) fs.delete(new Path(ServerConstants.getTablesDir() + "/" + delTableId), false); } }
From source file:it.polimi.tower4clouds.manager.MonitoringManager.java
/** * //from w w w . ja va 2s . c om * @return the metrics required by one or more installed rule that are not * provided as output metric of other rules */ @Override public Set<String> getRequiredMetrics() { HashSet<String> requiredMetrics = new HashSet<String>(streamsByMetric.keySet()); requiredMetrics.removeAll(ruleIdByObservableMetric.keySet()); return requiredMetrics; }
From source file:org.paxle.core.monitorable.observer.impl.MonitorableObserver.java
/** * @param reference/*from w ww. j a v a 2 s.com*/ * @param eventType */ private void serviceChanged(ServiceReference reference, int eventType) { if (reference == null) return; if (eventType == ServiceEvent.MODIFIED) return; // ignoring unknown services String pid = (String) reference.getProperty(Constants.SERVICE_PID); if (!variableTree.containsKey(pid)) return; // getting currently monitored variables final HashSet<String> currentVariableNames = new HashSet<String>(); if (this.currentMonitorJob != null) { String[] temp = this.currentMonitorJob.getStatusVariableNames(); if (temp != null) currentVariableNames.addAll(Arrays.asList(temp)); // stopping old monitoring-job this.currentMonitorJob.stop(); this.currentMonitorJob = null; } // getting variables of changed service final HashSet<String> diffVariableNames = new HashSet<String>(); this.addVariables4Monitor(reference, diffVariableNames, eventType == ServiceEvent.REGISTERED); if (eventType == ServiceEvent.REGISTERED) { // adding new variable currentVariableNames.addAll(diffVariableNames); } else if (eventType == ServiceEvent.UNREGISTERING) { currentVariableNames.removeAll(diffVariableNames); // deleting old values from status map for (String varName : diffVariableNames) { this.currentState.remove(varName); } } // restarting monitoring job this.startScheduledJob(currentVariableNames); }