List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:com.cloud.network.router.VpcNetworkHelperImpl.java
@Override protected void filterSupportedHypervisors(final List<HypervisorType> hypervisors) { hypervisors.retainAll(vpcMgr.getSupportedVpcHypervisors()); }
From source file:org.openmrs.module.reporting.query.person.evaluator.SqlPersonQueryEvaluator.java
/** * @see PersonQueryEvaluator#evaluate(PersonQuery, EvaluationContext) * @should evaluate a SQL query into an PersonQuery * @should filter results given a base Person Query Result in an EvaluationContext * @should filter results given a base cohort in an EvaluationContext *///from w w w. ja va 2 s .c o m public PersonQueryResult evaluate(PersonQuery definition, EvaluationContext context) throws EvaluationException { context = ObjectUtil.nvl(context, new EvaluationContext()); SqlPersonQuery sqlPersonQuery = (SqlPersonQuery) definition; PersonQueryResult queryResult = new PersonQueryResult(sqlPersonQuery, context); PersonIdSet personIds = new PersonIdSet(PersonDataUtil.getPersonIdsForContext(context, false)); if (personIds.getSize() == 0) { return queryResult; } SqlQueryBuilder qb = new SqlQueryBuilder(); qb.append(sqlPersonQuery.getQuery()); qb.setParameters(context.getParameterValues()); if (sqlPersonQuery.getQuery().contains(":personIds")) { qb.addParameter("personIds", personIds); } if (sqlPersonQuery.getQuery().contains(":patientIds")) { qb.addParameter("patientIds", personIds); } List<Integer> l = evaluationService.evaluateToList(qb, Integer.class, context); if (personIds != null) { l.retainAll(personIds.getMemberIds()); } queryResult.addAll(l); return queryResult; }
From source file:jease.cmf.web.node.tree.container.ContainerTable.java
private void dropPerformed(DropEvent dropEvent) { getListbox().renderAll();// w w w. j a va 2 s. co m Component target = dropEvent.getTarget(); Component dragged = dropEvent.getDragged(); if (dragged instanceof Listitem) { Set<Listitem> itemSet = new HashSet<>(getListbox().getSelectedItems()); itemSet.add((Listitem) dragged); List<Listitem> itemList = new ArrayList<>(getListbox().getItems()); itemList.retainAll(itemSet); for (Listitem listitem : itemList) { if (listitem != target) { listitem.getParent().removeChild(listitem); target.getParent().insertBefore(listitem, target); } } getListbox().clearSelection(); } if (dragged instanceof Treerow) { Treeitem treeitem = (Treeitem) dragged.getParent(); Listitem listitem = new Listitem(""); listitem.setValue(treeitem.getValue()); dragged.getParent().removeChild(dragged); target.getParent().insertBefore(listitem, target); } try { getListbox().getValues(); @SuppressWarnings("unchecked") Set<Node> children = new TreeSet<>(getListbox().getValues()); nodes.append(nodeService.get(JeaseSession.getContainerId()), children); } catch (NodeException e) { Modal.error(e.getMessage()); } finally { fireChangeEvent(); } }
From source file:opennlp.tools.similarity.apps.GoogleAutoCompleteQueryRunner.java
public List<String> getAutoCompleteExpression(String rawExpr) { // insert spaces into camel cases rawExpr = rawExpr.replaceAll("([a-z][a-z])([A-Z][a-z])", "$1 $2"); String query = rawExpr.replace(' ', '+'); try {/*from w ww. j a va2 s .c om*/ query = URLEncoder.encode(query, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String pageOrigHTML = pageFetcher.fetchOrigHTML(searchRequest + query + suffix); String[] results = StringUtils.substringsBetween(pageOrigHTML, "<CompleteSuggestion>", "</CompleteSuggestion>"); List<List<String>> accum = new ArrayList<List<String>>(); if (results == null) return null; for (String wrapped : results) { List<String> accumCase = new ArrayList<String>(); String[] words = null; try { words = StringUtils.substringBetween(wrapped, "\"").split(" "); } catch (Exception e) { } if (words == null || words.length < 1) continue; accumCase = Arrays.asList(words); accum.add(accumCase); } //TODO make more noise-resistant algo if (accum.size() > 1) { List<String> first = new ArrayList<String>(accum.get(0)); List<String> second = new ArrayList<String>(accum.get(1)); first.retainAll(second); if (first.size() > 0) return first; else return accum.get(0); } if (accum.size() == 1) return accum.get(0); return null; }
From source file:edu.cornell.mannlib.vitro.webapp.auth.policy.specialrelationships.RelationshipChecker.java
/** * Are there any URIs that appear in both of these lists? *//*from ww w. j ava 2 s . c o m*/ public boolean anyUrisInCommon(List<String> list1, List<String> list2) { List<String> urisInCommon = new ArrayList<String>(list1); urisInCommon.retainAll(list2); return !urisInCommon.isEmpty(); }
From source file:ch.systemsx.cisd.openbis.generic.server.authorization.DefaultAccessController.java
public final Status isAuthorized(final IAuthSession session, final Method method, final Argument<?>[] arguments) throws UserFailureException { assert session != null : "Unspecified session"; assert method != null : "Unspecified method"; assert arguments != null : "Unspecified method arguments"; final StopWatch stopWatch = new StopWatch(); stopWatch.start();// w ww . j a v a 2s. c om try { final Set<Role> methodRoles = getMethodRoles(method); if (methodRoles.size() == 0) { // TODO 2008-08-07, Tomasz Pylak: why this is not a programming error? What a user // can do if a programmer does not put an authorization annotation for a method? final String msg = String.format(METHOD_ROLES_NOT_FOUND_TEMPLATE, MethodUtils.describeMethod(method)); return Status.createError(msg); } PersonPE person = session.tryGetPerson(); if (person == null || person.getAllPersonRoles().size() == 0) { final String msg = String.format(USER_ROLE_ASSIGNMENTS_NOT_FOUND_TEMPLATE, session.getUserName()); return Status.createError(msg); } final List<RoleWithIdentifier> userRoles = getUserRoles(person); userRoles.retainAll(methodRoles); if (userRoles.size() == 0) { final String msg = String.format(MATCHING_ROLE_NOT_FOUND_TEMPLATE, methodRoles, session.getUserName()); return Status.createError(msg); } if (arguments.length > 0) { for (final Argument<?> argument : arguments) { final Status status = PredicateExecutor.evaluate(person, userRoles, argument); if (status.getFlag().equals(StatusFlag.OK) == false) { return status; } } } return Status.OK; } finally { logTimeTaken(stopWatch, method); } }
From source file:dkpro.similarity.algorithms.structure.TokenPairDistanceMeasure.java
@Override public double getSimilarity(Collection<String> stringList1, Collection<String> stringList2) throws SimilarityException { // Transform input lists into lowercase string lists List<String> sl1 = new ArrayList<String>(); for (String s : stringList1) { sl1.add(s.toLowerCase());/*from w w w . ja v a 2 s. c o m*/ } List<String> sl2 = new ArrayList<String>(); for (String s : stringList2) { sl2.add(s.toLowerCase()); } // Get word sets Set<String> strings1 = new HashSet<String>(sl1); Set<String> strings2 = new HashSet<String>(sl2); // Get a common word list List<String> commonStrings = new ArrayList<String>(strings1); commonStrings.retainAll(strings2); // Build up pairs (ignoring order, i.e. a-b or b-a) Set<Pair> pairs = new HashSet<Pair>(); for (String s1 : commonStrings) { for (String s2 : commonStrings) { if (!s1.equals(s2)) { Pair p = new Pair(s1, s2); pairs.add(p); } } } if (pairs.size() > 1) { double[] v1 = new double[pairs.size()]; double[] v2 = new double[pairs.size()]; List<Pair> pairList = new ArrayList<Pair>(pairs); for (int i = 0; i < pairList.size(); i++) { Pair p = pairList.get(i); int idx1a = sl1.indexOf(p.getString1()); int idx1b = sl1.indexOf(p.getString2()); int idx1diff = transform(idx1a - idx1b); int idx2a = sl2.indexOf(p.getString1()); int idx2b = sl2.indexOf(p.getString2()); int idx2diff = transform(idx2a - idx2b); v1[i] = idx1diff; v2[i] = idx2diff; } PearsonsCorrelation pearson = new PearsonsCorrelation(); return pearson.correlation(v1, v2); } return 0.0; }
From source file:org.dkpro.similarity.algorithms.structure.TokenPairDistanceMeasure.java
@Override public double getSimilarity(Collection<String> stringList1, Collection<String> stringList2) throws SimilarityException { // Transform input lists into lowercase string lists List<String> sl1 = new LinkedList<String>(); for (String s : stringList1) { sl1.add(s.toLowerCase());//from www .ja v a 2s . c o m } List<String> sl2 = new LinkedList<String>(); for (String s : stringList2) { sl2.add(s.toLowerCase()); } // Get word sets Set<String> strings1 = new LinkedHashSet<String>(sl1); Set<String> strings2 = new LinkedHashSet<String>(sl2); // Get a common word list List<String> commonStrings = new LinkedList<String>(strings1); commonStrings.retainAll(strings2); // Build up pairs (ignoring order, i.e. a-b or b-a) Set<Pair> pairs = new LinkedHashSet<Pair>(); for (String s1 : commonStrings) { for (String s2 : commonStrings) { if (!s1.equals(s2)) { Pair p = new Pair(s1, s2); pairs.add(p); } } } if (pairs.size() > 1) { double[] v1 = new double[pairs.size()]; double[] v2 = new double[pairs.size()]; List<Pair> pairList = new LinkedList<Pair>(pairs); for (int i = 0; i < pairList.size(); i++) { Pair p = pairList.get(i); int idx1a = sl1.indexOf(p.getString1()); int idx1b = sl1.indexOf(p.getString2()); int idx1diff = transform(idx1a - idx1b); int idx2a = sl2.indexOf(p.getString1()); int idx2b = sl2.indexOf(p.getString2()); int idx2diff = transform(idx2a - idx2b); v1[i] = idx1diff; v2[i] = idx2diff; } PearsonsCorrelation pearson = new PearsonsCorrelation(); return pearson.correlation(v1, v2); } return 0.0; }
From source file:org.openmrs.module.pihmalawi.metadata.HivMetadata.java
public List<Location> getHivStaticSystemLocations() { List<Location> l = getLocationsForTag(LocationTags.HIV_STATIC.name()); l.retainAll(getSystemLocations()); return l;//from ww w .ja v a 2 s . co m }
From source file:musite.io.xml.ProteinsXMLWriter.java
private Collection<String> fieldList(Set<String> fields) { if (priorityFields == null) { return fields; } else {/*from w ww .j av a 2s .c om*/ List<String> result = new ArrayList(); result.addAll(priorityFields); result.retainAll(result); for (String field : fields) { if (!priorityFields.contains(field)) { result.add(field); } } return result; } }