List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:com.clustercontrol.plugin.impl.OsScopeInitializerPlugin.java
@Override public void activate() { Set<String> builtinScopeFacilityIdSet = FacilityTreeAttributeConstant.getBuiltinScopeFacilityIdSet(); Map<String, CollectorPlatformMstEntity> platformMap = new ConcurrentHashMap<String, CollectorPlatformMstEntity>(); Set<String> platformIdSet = new HashSet<String>(); Set<String> osFacilityIdSet = new HashSet<String>(); String osParentFacilityId = FacilityTreeAttributeConstant.OS_PARENT_SCOPE; try {//from ww w.j a va2 s .c om for (CollectorPlatformMstEntity platformMstEntity : QueryUtil.getAllCollectorPlatformMst()) { String platformId = platformMstEntity.getPlatformId(); platformIdSet.add(platformId); platformMap.put(platformId, platformMstEntity); } for (FacilityInfo facilityEntity : QueryUtil.getChildFacilityEntity(osParentFacilityId)) { osFacilityIdSet.add(facilityEntity.getFacilityId()); } builtinScopeFacilityIdSet.addAll(osFacilityIdSet); osScopeIdSet.addAll(osFacilityIdSet); } catch (Exception e) { log.error(e); return; } //setting.cc_collector_platform_mst???setting.cc_cfg_facility??? //OSOS? JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); //osFacilityId?platformId??? Set<String> facilityIdToAddSet = new HashSet<String>(platformIdSet); facilityIdToAddSet.removeAll(osFacilityIdSet); HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); long now = HinemosTime.currentTimeMillis(); FacilityInfo osParentFacilityEntity = QueryUtil.getFacilityPK_NONE(osParentFacilityId); for (String facilityIdToAdd : facilityIdToAddSet) { CollectorPlatformMstEntity platformMstEntity = platformMap.get(facilityIdToAdd); ScopeInfo facilityEntityToAdd = new ScopeInfo(facilityIdToAdd); facilityEntityToAdd.setFacilityName(platformMstEntity.getPlatformName()); facilityEntityToAdd.setDescription(platformMstEntity.getPlatformName()); facilityEntityToAdd.setDisplaySortOrder(platformMstEntity.getOrderNo()); facilityEntityToAdd.setFacilityType(osParentFacilityEntity.getFacilityType()); facilityEntityToAdd.setIconImage(osParentFacilityEntity.getIconImage()); facilityEntityToAdd.setValid(osParentFacilityEntity.getValid()); facilityEntityToAdd.setOwnerRoleId(osParentFacilityEntity.getOwnerRoleId()); facilityEntityToAdd.setCreateUserId(osParentFacilityEntity.getCreateUserId()); facilityEntityToAdd.setCreateDatetime(now); facilityEntityToAdd.setModifyUserId(osParentFacilityEntity.getModifyUserId()); facilityEntityToAdd.setModifyDatetime(now); facilityEntityToAdd.persistSelf(em); em.flush(); log.info(String.format("The OS scope %s will be added.", facilityIdToAdd)); FacilityRelationEntity relation = new FacilityRelationEntity(osParentFacilityId, facilityIdToAdd); em.persist(relation); } jtm.commit(); if (!facilityIdToAddSet.isEmpty()) { builtinScopeFacilityIdSet.addAll(facilityIdToAddSet); osScopeIdSet.addAll(facilityIdToAddSet); } } catch (Exception e) { log.error(e); if (jtm != null) { jtm.rollback(); } return; } finally { if (jtm != null) { jtm.close(); } } //setting.cc_collector_platform_mst????setting.cc_cfg_facility?? //OSOS? try { jtm = new JpaTransactionManager(); jtm.begin(); HinemosEntityManager em = jtm.getEntityManager(); Set<String> facilityIdToRemoveSet = new HashSet<String>(osFacilityIdSet); facilityIdToRemoveSet.removeAll(platformIdSet); for (String facilityIdToRemove : facilityIdToRemoveSet) { FacilityRelationEntity facilityRelationEntityToRemove = QueryUtil .getFacilityRelationPk(osParentFacilityId, facilityIdToRemove); em.remove(facilityRelationEntityToRemove); FacilityInfo facilityEntityToRemove = QueryUtil.getFacilityPK_NONE(facilityIdToRemove); log.info(String.format("The OS scope %s will be removed.", facilityIdToRemove)); em.remove(facilityEntityToRemove); } jtm.commit(); if (!facilityIdToRemoveSet.isEmpty()) { builtinScopeFacilityIdSet.removeAll(facilityIdToRemoveSet); osScopeIdSet.removeAll(facilityIdToRemoveSet); } } catch (Exception e) { log.error(e); if (jtm != null) { jtm.rollback(); } } finally { if (jtm != null) { jtm.close(); } } }
From source file:jef.tools.ArrayUtils.java
/** * ????? ? /*from w w w .j a v a 2 s.c o m*/ * * @param ls * @param ls2 * @return */ public static Object[] xor(Object[] ls, Object[] ls2) { // Set<Object> setAll = new HashSet<Object>(Arrays.asList(ls)); for (Object o : ls2) { setAll.add(o); } // HashSet<Object> setInter = new HashSet<Object>(Arrays.asList(ls)); setInter.retainAll(Arrays.asList(ls2)); // ? setAll.removeAll(setInter); return setAll.toArray(); }
From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesWarningDialog.java
private void initComponents(final ChannelTask task, Set<ChannelDependency> dependencies, final Set<String> selectedChannelIds, Set<String> additionalChannelIds) throws ChannelDependencyException { additionalChannelIds.removeAll(selectedChannelIds); final OrderedChannels orderedChannels = ChannelDependencyUtil.getOrderedChannels(dependencies, new HashSet<String>(CollectionUtils.union(selectedChannelIds, additionalChannelIds))); final List<Set<String>> orderedChannelIds = orderedChannels.getOrderedIds(); if (task.isForwardOrder()) { Collections.reverse(orderedChannelIds); }/* w ww .ja v a 2 s .c o m*/ descriptionLabel = new JLabel( "<html>There are additional channels in the dependency chain.<br/><b>Bolded</b> channels will be " + task.getFuturePassive() + " in the following order:</html>"); channelsPane = new JTextPane(); channelsPane.setContentType("text/html"); HTMLEditorKit editorKit = new HTMLEditorKit(); StyleSheet styleSheet = editorKit.getStyleSheet(); styleSheet.addRule("div {font-family:\"Tahoma\";font-size:11;text-align:top}"); channelsPane.setEditorKit(editorKit); channelsPane.setEditable(false); channelsPane.setBackground(getBackground()); setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, false); descriptionScrollPane = new JScrollPane(channelsPane); includeCheckBox = new JCheckBox(WordUtils.capitalize(task.toString()) + " " + additionalChannelIds.size() + " additional channel" + (additionalChannelIds.size() == 1 ? "" : "s")); includeCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, includeCheckBox.isSelected()); } }); okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.OK_OPTION; dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.CANCEL_OPTION; dispose(); } }); }
From source file:main.java.spelementex.Evaluator.java
/** * given result file, gets the true and false positive entity counts. * please note: this function is mainly intended for development purposes; * it will not work if the result file does not have gold annotation labels * in the second to the last column./*from w ww. j a v a 2s . co m*/ * * @param result * @return double[] of size 2 with true positive count at index 0 and * false positive count at index 1. */ public static double[] getTpFp(String[] result) { double[] tpFp = new double[2]; Set<String> goldAnnotations = new HashSet<>(); Set<Integer> visitedTokens = new HashSet<>(); Set<String> predictedAnnotations = new HashSet<>(); Set<Integer> predictedTokens = new HashSet<>(); int tokenNum = 0; int length = result.length; for (int i = 0; i < length; i++) { String line = result[i].trim(); if (line.equals("")) continue; String[] lineTokens = line.split("\\s+"); if (lineTokens.length == 3) { tokenNum = 0; //# 0 0.076469 if (lineTokens[1].equals("0") && !goldAnnotations.isEmpty()) { goldAnnotations.retainAll(predictedAnnotations); tpFp[0] += goldAnnotations.size(); predictedAnnotations.removeAll(goldAnnotations); tpFp[1] += predictedAnnotations.size(); goldAnnotations = new HashSet<>(); visitedTokens = new HashSet<>(); predictedAnnotations = new HashSet<>(); predictedTokens = new HashSet<>(); } continue; } String goldTag = lineTokens[lineTokens.length - 2]; if (goldTag.matches("B\\-.*") && !visitedTokens.contains(tokenNum)) { int[] tokenOffsets = getTokenOffset(result, i, tokenNum); goldAnnotations.add(tokenOffsets[0] + "-" + tokenOffsets[1] + "-" + goldTag); visitedTokens.add(tokenNum); } String predictedTag = lineTokens[lineTokens.length - 1]; if (predictedTag.matches("B\\-.*") && !predictedTokens.contains(tokenNum)) { if (lineTokens[0].matches("[^a-zA-Z0-9]+") || lineTokens[0].equals("-lrb-") || lineTokens[0].equals("-rrb-")) { if (i + 1 == result.length) { tokenNum++; continue; } line = result[i + 1].trim(); lineTokens = line.split("\\s+"); if (line.equals("") || lineTokens.length == 3 || lineTokens[lineTokens.length - 1].equals("O") || lineTokens[lineTokens.length - 1].matches("B\\-.*")) { tokenNum++; continue; } } int[] tokenOffsets = getTokenOffset(result, i, tokenNum); Set<Integer> tempPredictedTokens = new HashSet<>(); for (int j = tokenOffsets[0]; j <= tokenOffsets[1]; j++) tempPredictedTokens.add(j); int before = tempPredictedTokens.size(); tempPredictedTokens.removeAll(predictedTokens); int after = tempPredictedTokens.size(); if (before == after) { predictedTokens.addAll(tempPredictedTokens); predictedAnnotations.add(tokenOffsets[0] + "-" + tokenOffsets[1] + "-" + predictedTag); } } tokenNum++; } goldAnnotations.retainAll(predictedAnnotations); tpFp[0] += goldAnnotations.size(); predictedAnnotations.removeAll(goldAnnotations); tpFp[1] += predictedAnnotations.size(); return tpFp; }
From source file:main.java.spelementex.Evaluator.java
/** * given result file, gets the true and false positive entity counts. * please note: this function is mainly intended for development purposes; * it will not work if the result file does not have gold annotation labels * in the second to the last column./*from www . j av a 2 s . c o m*/ * * @param result * @param tagType * @return double[] of size 2 with true positive count at index 0 and * false positive count at index 1. */ public static double[] getTpFp(String[] result, String tagType) { double[] tpFp = new double[2]; Set<String> goldAnnotations = new HashSet<>(); Set<Integer> visitedTokens = new HashSet<>(); Set<String> predictedAnnotations = new HashSet<>(); Set<Integer> predictedTokens = new HashSet<>(); int tokenNum = 0; int length = result.length; for (int i = 0; i < length; i++) { String line = result[i].trim(); if (line.equals("")) continue; String[] lineTokens = line.split("\\s+"); if (lineTokens.length == 3) { tokenNum = 0; //# 0 0.076469 if (lineTokens[1].equals("0") && !goldAnnotations.isEmpty()) { goldAnnotations.retainAll(predictedAnnotations); tpFp[0] += goldAnnotations.size(); predictedAnnotations.removeAll(goldAnnotations); tpFp[1] += predictedAnnotations.size(); goldAnnotations = new HashSet<>(); visitedTokens = new HashSet<>(); predictedAnnotations = new HashSet<>(); predictedTokens = new HashSet<>(); } continue; } String goldTag = lineTokens[lineTokens.length - 2]; if (goldTag.matches("B\\-" + tagType) && !visitedTokens.contains(tokenNum)) { int[] tokenOffsets = getTokenOffset(result, i, tokenNum); goldAnnotations.add(tokenOffsets[0] + "-" + tokenOffsets[1] + "-" + goldTag); visitedTokens.add(tokenNum); } String predictedTag = lineTokens[lineTokens.length - 1]; if (predictedTag.matches("B\\-" + tagType) && !predictedTokens.contains(tokenNum)) { if (lineTokens[0].matches("[^a-zA-Z0-9]+") || lineTokens[0].equals("-lrb-") || lineTokens[0].equals("-rrb-")) { if (i + 1 == result.length) { tokenNum++; continue; } line = result[i + 1].trim(); lineTokens = line.split("\\s+"); if (line.equals("") || lineTokens.length == 3 || lineTokens[lineTokens.length - 1].equals("O") || lineTokens[lineTokens.length - 1].matches("B\\-.*")) { tokenNum++; continue; } } int[] tokenOffsets = getTokenOffset(result, i, tokenNum); Set<Integer> tempPredictedTokens = new HashSet<>(); for (int j = tokenOffsets[0]; j <= tokenOffsets[1]; j++) tempPredictedTokens.add(j); int before = tempPredictedTokens.size(); tempPredictedTokens.removeAll(predictedTokens); int after = tempPredictedTokens.size(); if (before == after) { predictedTokens.addAll(tempPredictedTokens); predictedAnnotations.add(tokenOffsets[0] + "-" + tokenOffsets[1] + "-" + predictedTag); } } tokenNum++; } goldAnnotations.retainAll(predictedAnnotations); tpFp[0] += goldAnnotations.size(); predictedAnnotations.removeAll(goldAnnotations); tpFp[1] += predictedAnnotations.size(); return tpFp; }
From source file:edu.ucsd.library.xdre.web.StatsCollectionsReportController.java
public synchronized static void generateReport() throws Exception { DAMSClient damsClient = null;/*from w w w . ja v a 2s .c o m*/ StringBuilder strBuf = new StringBuilder(); strBuf.append("UCSD Library DAMS Collections Report - " + ReportFormater.getCurrentTimestamp() + "\n"); strBuf.append( "Collection\tType\tUnit\tSearchable Items\tItems Count\tSize(MB)\tView\tPublic\tUCSD\tCurator\tRestricted\tCulturally Sensitive\tNotes" + "\n"); Map<String, String> unitsMap = null; Map<String, Set<String>> unitsRecordsMap = new HashMap<String, Set<String>>(); Map<String, String> colRows = new TreeMap<String, String>(); try { String colId = null; String colTitle = null; List<String> values = null; String visibility = ""; String unit = ""; String colType = ""; String rowVal = null; Document doc = null; damsClient = DAMSClient.getInstance(); Map<String, String> colMap = damsClient.listCollections(); CollectionHandler colHandler = null; unitsMap = DAMSClient.reverseMap(damsClient.listUnits()); for (Iterator<String> it = unitsMap.keySet().iterator(); it.hasNext();) { String unitId = it.next(); Set<String> uRecords = new HashSet<String>(); uRecords.addAll(damsClient.listUnitObjects(unitId)); unitsRecordsMap.put(unitId, uRecords); } for (Iterator<String> iter = colMap.keySet().iterator(); iter.hasNext();) { visibility = ""; unit = ""; colTitle = iter.next(); colId = colMap.get(colTitle); // Remove records from all units try { colHandler = new StatsCollectionQuantityHandler(damsClient, colId); if (unitsRecordsMap.size() > 0) { for (Iterator<Set<String>> uit = unitsRecordsMap.values().iterator(); uit.hasNext();) { Set<String> uRecords = uit.next(); uRecords.remove(colId); uRecords.removeAll(colHandler.getItems()); } } } finally { if (colHandler != null) { colHandler.release(); colHandler = null; } } colId = colId.substring(colId.lastIndexOf("/") + 1); int idx = colTitle.lastIndexOf("["); if (idx > 0) { colType = colTitle.substring(idx + 1, colTitle.lastIndexOf("]")); colTitle = colTitle.substring(0, idx).trim(); } doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8")); values = getValues(doc, "//*[@name='visibility_tesim']/str"); for (Iterator<String> it = values.iterator(); it.hasNext();) visibility += (visibility.length() > 0 ? " " : "") + it.next(); values = getValues(doc, "//*[@name='unit_code_tesim']/str"); for (Iterator<String> it = values.iterator(); it.hasNext();) unit += (unit.length() > 0 ? " " : "") + it.next(); rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, null); if (rowVal != null && rowVal.length() > 0) colRows.put(colTitle, rowVal + "\n"); } // Orphans in each unit for (Iterator<String> uit = unitsRecordsMap.keySet().iterator(); uit.hasNext();) { colId = uit.next(); colTitle = unitsMap.get(colId); Set<String> uRecords = unitsRecordsMap.get(colId); List<String> items = new ArrayList<String>(); items.addAll(uRecords); colType = "Unit"; colId = colId.substring(colId.lastIndexOf("/") + 1); doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8")); visibility = ""; values = getValues(doc, "//*[@name='visibility_tesim']/str"); for (Iterator<String> it = values.iterator(); it.hasNext();) visibility += (visibility.length() > 0 ? " " : "") + it.next(); unit = ""; values = getValues(doc, "//*[@name='unit_code_tesim']/str"); for (Iterator<String> it = values.iterator(); it.hasNext();) unit += (unit.length() > 0 ? " " : "") + it.next(); rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, items); if (rowVal != null && rowVal.length() > 0) colRows.put(colTitle, rowVal + "\n"); } for (Iterator<String> iter = colRows.values().iterator(); iter.hasNext();) { strBuf.append(iter.next()); } STATUSREPORT = strBuf.toString(); } finally { if (damsClient != null) { damsClient.close(); damsClient = null; } } }
From source file:org.solmix.runtime.support.spring.SpringBeanProvider.java
/** * {@inheritDoc}// w ww.j a v a 2 s . co m * * @see org.solmix.api.bean.ConfiguredBeanProvider#getBeansOfType(java.lang.Class) */ @Override public <T> Collection<? extends T> getBeansOfType(Class<T> type) { Set<String> s = new LinkedHashSet<String>(Arrays.asList(context.getBeanNamesForType(type, false, false))); s.removeAll(passThroughs); List<T> lst = new LinkedList<T>(); for (String n : s) { lst.add(type.cast(context.getBean(n, type))); } if (context.getParent() != null) { lst.addAll(_doGetBeansOfType(context.getParent(), type)); } if (original != null) { Collection<? extends T> origs = original.getBeansOfType(type); if (origs != null) lst.addAll(origs); } return lst; }
From source file:de.tuberlin.uebb.jdae.llmsl.ExecutableDAE.java
public int lastBlock(final Collection<GlobalVariable> vars) { final Set<GlobalVariable> left = Sets.newTreeSet(vars); left.removeAll(states); int i = 0;/*w ww . j a va 2s. com*/ while (!left.isEmpty() && i < blocks.length) { for (GlobalVariable gv : blocks[i].variables()) left.remove(gv); i++; } if (!left.isEmpty()) throw new RuntimeException("The following variables are not computed: " + left.toString()); return i; }
From source file:com.alibaba.jstorm.task.master.GrayUpgradeHandler.java
private void pickWorkersToUpgrade(GrayUpgradeConfig grayUpgradeConf, Set<String> upgradedWorkers) throws Exception { Set<String> remainingSlots = new HashSet<>(); remainingSlots.addAll(this.totalWorkers); remainingSlots.removeAll(upgradedWorkers); int workerNum = grayUpgradeConf.getWorkerNum(); String component = grayUpgradeConf.getComponent(); Set<String> workers = grayUpgradeConf.getWorkers(); TopologyContext topologyContext = tmContext.getContext(); if (workers.size() > 0) { LOG.info("Upgrading specified workers:{}", workers); for (String worker : workers) { if (remainingSlots.contains(worker)) { addUpgradingSlot(worker); } else { LOG.warn("Worker {} is not in topology worker list or has been upgraded already, skip.", worker);//ww w .j av a 2 s. com } } // reset workers workers.clear(); } else if (!StringUtils.isBlank(component)) { LOG.info("Upgrading workers of component:{}", component); List<Integer> tasks = topologyContext.getComponentTasks(component); if (tasks == null) { LOG.error("Failed to get tasks for component {}, maybe it's a wrong component name.", component); return; } Set<String> slots = new HashSet<>(); for (Integer task : tasks) { String worker = this.taskToHostPort.get(task); if (worker != null && remainingSlots.contains(worker)) { slots.add(worker); } } LOG.info("Available workers of component {}: {}", component, slots); pickUpgradingSlots(slots, workerNum > 0 ? workerNum : slots.size()); // reset component if (workerNum == 0 || workerNum >= slots.size()) { grayUpgradeConf.setComponent(null); } } else if (workerNum > 0) { LOG.info("Upgrading workers at random"); pickUpgradingSlots(remainingSlots, workerNum); } }
From source file:com.github.aptd.simulation.TestCLanguageLabels.java
/** * check package translation configuration versus property items *//*from ww w . ja v a 2 s.c o m*/ @Test public void testTranslation() { assumeTrue("no languages are defined for checking", !LANGUAGEPROPERY.isEmpty()); // --- read language definitions from the configuration final Set<String> l_translation = Collections.unmodifiableSet( Arrays.stream(CCommon.configuration().getObject("translation").toString().split(",")) .map(i -> i.trim().toLowerCase()).collect(Collectors.toSet())); // --- check if a test (language resource) exists for each definied language final Set<String> l_translationtesting = new HashSet<>(l_translation); l_translationtesting.removeAll(LANGUAGEPROPERY.keySet()); assertFalse(MessageFormat.format( "configuration defines {1,choice,1#translation|1<translations} {0} that {1,choice,1#is|1<are} not tested", l_translationtesting, l_translationtesting.size()), !l_translationtesting.isEmpty()); // --- check unused language resource files final Set<String> l_translationusing = new HashSet<>(LANGUAGEPROPERY.keySet()); l_translationusing.removeAll(l_translation); assertFalse(MessageFormat.format( "{1,choice,1#translation|1<translations} {0} {1,choice,1#is|1<are} checked, which will not be used within the package configuration", l_translationusing, l_translationusing.size()), !l_translationusing.isEmpty()); }