List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:org.apache.syncope.client.console.commons.PropertyList.java
@Override public boolean retainAll(final Collection<?> c) { final List<String> list = getEnumValuesAsList(getValues()); final boolean res = list.retainAll(c); setValues(list);//from www . j a v a 2s . co m return res; }
From source file:ubic.pubmedgate.interactions.NormalizePairs.java
private static NormalizeResult runNormalization(String testSet, AirolaXMLReader XMLReader, SLOutputReader SLReader, boolean doAll, boolean usePredictions, boolean year1987Split, boolean notInBAMS) throws Exception { Map<String, String> results; boolean writeOut = true; if (doAll)//w ww .j a va 2 s. c o m testSet += ".all"; if (year1987Split) testSet += ".yearSplit"; if (usePredictions) testSet += ".predictions"; if (doAll && year1987Split) throw new Exception("Year split and do all options are incompatable"); String excelOutFilename = Config.config.getString("whitetext.iteractions.results.folder") + testSet + ".xml.normalized.xls"; NormalizePairs normPairs = new NormalizePairs(); List<String> positives; List<String> negatives; if (usePredictions) { positives = SLReader.getPositivePredictions(); negatives = SLReader.getNegativePredictions(); } else { positives = SLReader.getPositives(); negatives = SLReader.getNegatives(); } ParamKeeper keeper = new ParamKeeper(); String name; NormalizeResult normResult = null; if (notInBAMS) { List<String> ratPairs = getRatPairs(XMLReader, SLReader.getAll()); // negatives.retainAll( ratPairs ); log.info("Retaining rat pairs:" + ratPairs.size()); positives.retainAll(ratPairs); // normalize name = "NotInBAMS.rat.positives"; normResult = normPairs.normalizePairsToMatrix(XMLReader, positives, SLReader, writeOut, name); keeper.addParamInstance(normResult.statisticMap); } else if (year1987Split) { int yearSplit1 = 1986; int yearSplit2 = 2001; log.info("Doing year based split"); List<String> ratPairs = getRatPairs(XMLReader, SLReader.getAll()); // negatives.retainAll( ratPairs ); log.info("Retaining rat pairs"); positives.retainAll(ratPairs); log.info("Done retaining rat pairs"); // split rat positives into years Model modelLoad = ModelFactory.createDefaultModel(); String fileProperty; fileProperty = "resolve.Lexicon.resolution.RDF.allComp"; modelLoad.read(new FileInputStream(Config.config.getString(fileProperty)), null); fileProperty = "resolve.Lexicon.resolution.RDF"; modelLoad.read(new FileInputStream(Config.config.getString(fileProperty)), null); boolean reason = true; EvaluationRDFModel model = new EvaluationRDFModel(modelLoad, reason); Map<String, Integer> pmidToYearMap = model.getPMIDStringtoYearMap(); // filter pairs based on date List<String> positivesAfter2002 = new LinkedList<String>(); List<String> positivesAfter1987 = new LinkedList<String>(); List<String> positivesBefore1986 = new LinkedList<String>(); Map<String, String> pairToPMID = XMLReader.getPairIDToPMID(); for (String pair : positives) { String pmid = pairToPMID.get(pair); log.info("PMID:" + pmid); int year = pmidToYearMap.get(pmid); log.info(pmid + "->" + year); if (year <= yearSplit1) { positivesBefore1986.add(pair); } else if (year <= yearSplit2) { positivesAfter1987.add(pair); } else { positivesAfter2002.add(pair); } } log.info("All positives:" + positives.size()); log.info("All positivesBefore1986:" + positivesBefore1986.size()); log.info("All positivesAfter1987:" + positivesAfter1987.size()); name = "Positives.rat.before1986" + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, positivesBefore1986, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); name = "Positives.rat.1987to2002" + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, positivesAfter1987, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); name = "Positives.rat.after2002" + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, positivesAfter2002, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); } else if (!doAll) { name = "Positives." + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, positives, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); name = "Negatives." + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, negatives, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); // filter rats List<String> ratPairs = getRatPairs(XMLReader, SLReader.getAll()); negatives.retainAll(ratPairs); positives.retainAll(ratPairs); name = "Positives.rat." + testSet; normResult = normPairs.normalizePairsToMatrix(XMLReader, positives, SLReader, writeOut, name); results = normResult.statisticMap; keeper.addParamInstance(results); // return the rat positive results name = "Negatives.rat." + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, negatives, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); } else { name = "all." + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, SLReader.getAll(), SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); List<String> ratPairs = getRatPairs(XMLReader, SLReader.getAll()); name = "all.rat" + testSet; results = normPairs.normalizePairsToMatrix(XMLReader, ratPairs, SLReader, writeOut, name).statisticMap; keeper.addParamInstance(results); } keeper.writeExcel(excelOutFilename); log.info("Wrote to:" + excelOutFilename); // only returned for not in bams setting return normResult; }
From source file:edu.cmu.tetrad.graph.LayeredDrawing.java
private void placeNodes(Node node, Map<Node, Integer> tiers, Graph graph) { if (tiers.keySet().contains(node)) { return;/*from w ww . j a v a 2 s. co m*/ } Set<Node> keySet = tiers.keySet(); List<Node> parents = graph.getParents(node); parents.retainAll(keySet); List<Node> children = graph.getChildren(node); children.retainAll(keySet); if (parents.isEmpty() && children.isEmpty()) { tiers.put(node, 0); } else if (parents.isEmpty()) { int cMin = getCMin(children, tiers); tiers.put(node, cMin - 1); placeChildren(node, tiers, graph); return; } else { int pMax = getPMax(parents, tiers); int cMin = getCMin(children, tiers); tiers.put(node, pMax + 1); if (!children.isEmpty() && cMin < pMax + 2) { int diff = (pMax + 2) - cMin; List<Node> descendants = graph.getDescendants(Collections.singletonList(node)); descendants.retainAll(keySet); descendants.remove(node); for (Node descendant : descendants) { Integer index = tiers.get(descendant); tiers.put(descendant, index + diff); } } } placeChildren(node, tiers, graph); }
From source file:opennlp.tools.similarity.apps.taxo_builder.DomainTaxonomyExtender.java
private List<String> assessKeywordOverlap(String snapshot1, String snapshot2) { List<String> results = new ArrayList<String>(); List<String> firstList = TextProcessor.fastTokenize(snapshot1, false), secondList = TextProcessor.fastTokenize(snapshot2, false); firstList.retainAll(secondList); for (String s : firstList) { if (s.length() < 4) continue; if (!StringUtils.isAlpha(s)) continue; results.add(s);/*w ww . j a v a2 s . c o m*/ } return results; }
From source file:org.languagetool.rules.uk.SimpleReplaceSoftRule.java
@Override public String getMessage(String tokenStr, List<String> replacements) { ContextRepl repl = findContext(replacements); String replaceText = StringUtils.join(repl.replacements, ", "); // this is a bit ugly as we're modifying original list replacements.retainAll(repl.replacements); if (repl.contexts.size() > 0) { return "" + tokenStr + " ?? ?: " + StringUtils.join(repl.contexts, ", ") + ", , : " + replaceText + "?"; }//w w w . j a va 2 s . c o m return tokenStr + " ?, : " + replaceText + "."; }
From source file:org.beangle.emsapp.security.action.RestrictionAction.java
/** * ??<br>/*from www.j av a 2s . c om*/ */ public String edit() { // ??? Restriction restriction = getRestriction(); boolean isAdmin = isAdmin(); Map<String, Object> mngFields = CollectUtils.newHashMap(); Map<String, Object> aoFields = CollectUtils.newHashMap(); List<Restriction> myRestricitons = getMyRestrictions(restriction.getPattern(), restriction.getHolder()); Set<RestrictField> ignores = getIgnoreFields(myRestricitons); put("ignoreFields", ignores); Set<RestrictField> holderIgnoreFields = CollectUtils.newHashSet(); put("holderIgnoreFields", holderIgnoreFields); for (RestrictField field : restriction.getPattern().getEntity().getFields()) { List<?> mngField = restrictionService.getFieldValues(field.getName()); if (!isAdmin) { mngField.retainAll(getMyRestrictionValues(myRestricitons, field.getName())); } else { ignores.add(field); } String fieldValue = restriction.getItem(field); if ("*".equals(fieldValue)) { holderIgnoreFields.add(field); } mngFields.put(field.getName(), mngField); if (null == field.getSource()) { aoFields.put(field.getName(), fieldValue); } else { aoFields.put(field.getName(), restrictionService.getFieldValue(field, restriction)); } } put("mngFields", mngFields); put("aoFields", aoFields); put("restriction", restriction); return forward(); }
From source file:au.org.ala.delta.intkey.ui.TaxonKeywordSelectionDialog.java
@Override protected void okBtnPressed() { _selectedTaxa = new ArrayList<Item>(); HashSet<Item> selectedTaxaSet = new HashSet<Item>(); for (Object o : _list.getSelectedValues()) { String keyword = (String) o; _selectedKeywords.add(keyword);//from ww w.j a v a2 s. co m if (keyword.equals(IntkeyContext.SPECIMEN_KEYWORD)) { _specimenSelectedReturnValue.setValue(true); } else { List<Item> taxa = _context.getTaxaForKeyword(keyword); if (_selectFromIncluded) { taxa.retainAll(_includedTaxa); } selectedTaxaSet.addAll(taxa); } } _selectedTaxa.addAll(selectedTaxaSet); Collections.sort(_selectedTaxa); this.setVisible(false); }
From source file:com.romeikat.datamessie.core.base.util.CollectionUtil.java
public <T extends Comparable<? super T>> List<T> getCommonElementsSorted(final Collection<T> elements1, final Collection<T> elements2) { final List<T> commonElements = new ArrayList<T>(elements1); commonElements.retainAll(elements2); Collections.sort(commonElements); return commonElements; }
From source file:au.org.ala.delta.intkey.ui.TaxonKeywordSelectionDialog.java
@Override protected void imagesBtnPressed() { List<Image> taxonKeywordImages = _context.getDataset().getTaxonKeywordImages(); if (taxonKeywordImages != null && !taxonKeywordImages.isEmpty()) { ImageDialog dlg = new ImageDialog(this, _context.getImageSettings(), true, _context.displayScaled()); dlg.setImages(taxonKeywordImages); dlg.showImage(0);/*ww w. ja v a 2 s . c o m*/ dlg.setVisible(true); if (dlg.okButtonPressed() && !dlg.getSelectedKeywords().isEmpty()) { Set<String> selectedKeywords = dlg.getSelectedKeywords(); for (String keyword : selectedKeywords) { List<Item> taxa = _context.getTaxaForKeyword(keyword); if (_selectFromIncluded) { taxa.retainAll(_includedTaxa); } _selectedTaxa.addAll(taxa); } Collections.sort(_selectedTaxa); this.setVisible(false); } } }
From source file:nl.strohalm.cyclos.webservices.accounts.AccountWebServiceImpl.java
@Override public List<TransferTypeVO> searchTransferTypes(final TransferTypeSearchParameters params) { // Get the allowed transfer types final ServiceClient client = WebServiceContext.getClient(); final Collection<TransferType> allowedTTs = new ArrayList<TransferType>(); allowedTTs.addAll(client.getDoPaymentTypes()); allowedTTs.addAll(client.getReceivePaymentTypes()); if (allowedTTs.isEmpty()) { return Collections.emptyList(); }//from w w w.j a va2 s .com // Search according to the query final TransferTypeQuery query = accountHelper.toQuery(params); final List<TransferType> transferTypes = transferTypeServiceLocal.search(query); // Ensure only the allowed are returned transferTypes.retainAll(allowedTTs); return accountHelper.toTransferTypeVOs(transferTypes); }