Example usage for org.apache.commons.collections ListUtils intersection

List of usage examples for org.apache.commons.collections ListUtils intersection

Introduction

In this page you can find the example usage for org.apache.commons.collections ListUtils intersection.

Prototype

public static List intersection(final List list1, final List list2) 

Source Link

Document

Returns a new list containing all elements that are contained in both given lists.

Usage

From source file:com.formkiq.core.form.FormTransformer.java

/**
 * Update {@link FormJSON} by the selected 'optionsgroup'.
 * @param form {@link FormJSON}//from   w w w .  j a  v a2  s.c o m
 */
public static void updateOptionsGroup(final FormJSON form) {

    List<FormJSONField> list = stream(form).collect(Collectors.toList());

    List<String> optionsGroup = list.stream()
            .filter(f -> !CollectionUtils.isEmpty(f.getOptionsgroup())
                    && f.getOptionsgroup().size() == f.getOptions().size()
                    && f.getOptions().indexOf(f.getValue()) != -1)
            .map(f -> f.getOptionsgroup().get(f.getOptions().indexOf(f.getValue())))
            .collect(Collectors.toList());

    list.forEach(f -> {
        f.setHide(ListUtils.intersection(f.getGroups(), optionsGroup).isEmpty());

        if (CollectionUtils.isEmpty(f.getGroups())) {
            f.setHide(false);
        }
    });
}

From source file:com.agiletec.plugins.jpldap.apsadmin.user.UserFinderAction.java

@Override
public List<String> getSearchResult() {
    List<String> mainSearchResult = super.getSearchResult();
    try {/*from  w w  w  .j a va2 s .c  o m*/
        Integer userType = this.getUserType();
        if (null == userType || userType == 0) {
            return mainSearchResult;
        } else {
            Boolean entandoUser = (userType == 1);
            List<String> ldapUsernames = this.getLdapUsernames();
            List<String> newList = null;
            if (entandoUser) {
                newList = (List<String>) ListUtils.removeAll(mainSearchResult, ldapUsernames);
            } else {
                newList = (List<String>) ListUtils.intersection(mainSearchResult, ldapUsernames);
            }
            return newList;
        }
    } catch (Throwable t) {
        ApsSystemUtils.logThrowable(t, this, "getSearchResult");
        throw new RuntimeException("Error while searching users", t);
    }
}

From source file:br.ufrj.nce.recureco.distributedindex.search.service.SearchService.java

public List<String> getDocuments(String query, boolean booleanOr) {

    List<String> andWords = lineTokenizer.tokenize(query);

    //if query words list is null, return empty results
    if (andWords == null) {
        return new ArrayList<String>();
    }//from  w  w w. j  a va 2  s.  c  om
    //if query words list is  empty, return empty results
    if (andWords.size() == 0) {
        return new ArrayList<String>();
    }

    //if still here, there is something to search
    List<String> results = searchDAO.getDocuments(andWords);

    List<String> documentsResults = new ArrayList<String>();

    boolean firstTime = true;

    for (String docs : results) {

        List<String> auxList = new ArrayList<String>();
        CollectionUtils.addAll(auxList, docs.split(","));

        if (booleanOr) {
            documentsResults = ListUtils.sum(documentsResults, auxList);
        } else {
            if (firstTime) {
                documentsResults = ListUtils.union(documentsResults, auxList);
                firstTime = false;
            } else {
                documentsResults = ListUtils.intersection(documentsResults, auxList);
            }
        }
    }

    return documentsResults;
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.linkbased.algorithm.WikipediaRelatednessMethod.java

private Integer countIncomingSharedLinks(String candidate0, String candidate1) {

    return ListUtils.intersection(incomingLinksList.get(candidate0), incomingLinksList.get(candidate1)).size();
}

From source file:br.com.emsouza.plugin.validate.ValidatePomMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    boolean execute = Boolean.parseBoolean(project.getProperties().getProperty("validate-plugin", "true"));

    if (execute) {
        if (!project.getPackaging().equals("pom")) {

            List<Dependency> dependencies = ConvertData.readProjectFile(pomFile);
            Configuration cfg = ConfigurationFactory.build(configURL);

            // Get the list of valid scopes
            if (!ValidateScopeUtil.isValid(dependencies, cfg.getScopes())) {
                throw new MojoFailureException(
                        "Existem dependncias declaradas fora do padro => " + mavenDocURL);
            }//from www  .j  a  v  a  2s  . co m

            // Verify exclude artifact
            if (CollectionUtils.containsAny(dependencies, cfg.getExclusions())) {
                Dependency art = (Dependency) ListUtils.intersection(dependencies, cfg.getExclusions()).get(0);
                throw new MojoFailureException(String.format(art.getDescription(), art));
            }

            // Verify correct Syntax
            ValidateSyntaxUtil.validate(dependencies, cfg.getSyntax());
        }
    }
}

From source file:edu.isistan.carcha.CarchaPipelineTest.java

/**
 * Test calculate metrics.//from  w  w  w.j  a  v a  2s  .  co m
 *
 * @param output the result file from executing the annotator
 * @param golden the golden file annotated by experts
 * @throws UIMAException the UIMA exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void testCalculateMetrics(String output, String golden) throws UIMAException, IOException {

    List<String> goldenDesignDecisions = Utils.extractCoveredTextAnnotations(golden, DesignDecision.class);
    List<String> goldenSentences = Utils.extractCoveredTextAnnotations(golden, Sentence.class);

    List<String> discoveredDesignDecisions = Utils.extractCoveredTextAnnotations(output, DesignDecision.class);
    List<String> discoveredSentences = Utils.extractCoveredTextAnnotations(output, Sentence.class);

    //Golden design decision that were not discovered
    double fn = ListUtils.removeAll(goldenDesignDecisions, discoveredDesignDecisions).size();

    //Sentences that were discovered but are not design decisions
    double fp = ListUtils.removeAll(discoveredDesignDecisions, goldenDesignDecisions).size();

    //Discovered Design Decisions.
    double tp = ListUtils.intersection(discoveredDesignDecisions, goldenDesignDecisions).size();

    //non design decision that were not marked as design decision
    double tn = ListUtils.intersection(discoveredSentences, goldenSentences).size();

    Double presicion = tp / (tp + fp);
    double recall = tp / (tp + fn);
    double fMeasure = 5 * ((presicion * recall) / ((4 * presicion) + recall));
    double accuracy = (tp + tn) / (fn + fp + tp + tn);

    NumberFormat df = new DecimalFormat("#0.00");

    logger.info("Golden DDs:           " + goldenDesignDecisions.size());
    logger.info("Golden Sentences:     " + goldenSentences.size());
    logger.info("Discovered DDs:       " + discoveredDesignDecisions.size());
    logger.info("Discovered Sentences: " + discoveredSentences.size());
    logger.info("------------------");
    logger.info("False Negative:   " + fn);
    logger.info("False Positive:   " + fp);
    logger.info("True  Negative:   " + tn);
    logger.info("True Positive:    " + tp);
    logger.info("------------------");
    logger.info("Presition: " + df.format(presicion * 100) + "%");
    logger.info("Recall:    " + df.format(recall * 100) + "%");
    logger.info("Acurracy:  " + df.format(accuracy * 100) + "%");
    logger.info("F-Measure: " + df.format(fMeasure * 100) + "%");
}

From source file:cooperativegametheory.Partition.java

public boolean completesComponent(int player, int[] rankOrder) {
    Coalition component = getComponent(player);

    List<Integer> roList = new ArrayList<Integer>();
    for (int i : rankOrder) {
        roList.add(i);//w  w  w . j  av  a  2 s.  c om
    }
    List<Integer> coList = new ArrayList<Integer>();
    for (int i : component) {
        coList.add(i);
    }
    List<Integer> coRo = ListUtils.intersection(coList, roList);
    return coRo.get(coRo.size() - 1) == player;
}

From source file:edu.isistan.carcha.lsa.LSARunnerTest.java

/**
 * Test calculate metrics.//ww w  .  j a v  a  2s. c o m
 * 
 * @param result
 *            the result
 * @param golden
 *            the golden
 */
public void calculateMetrics(TraceabilityDocument result, TraceabilityDocument golden) {

    double fn = ListUtils.removeAll(golden.getLinks(), result.getLinks()).size();
    double fp = ListUtils.removeAll(result.getLinks(), golden.getLinks()).size();
    double tn = Utils.calculateTrueNegatives(golden, result);
    double tp = ListUtils.intersection(result.getLinks(), golden.getLinks()).size();

    double presicion = tp / (tp + fp + 0.0000000001);
    double recall = tp / (tp + fn);
    double fMeasure = 5 * ((presicion * recall) / ((4 * presicion) + recall + 0.0000000001));
    double accuracy = (tp + tn) / (fn + fp + tp + tn);

    NumberFormat df = new DecimalFormat("#0.00");

    logger.info("Golden TRAs:" + golden.getLinks().size());
    logger.info("Discovered TRAs:" + result.getLinks().size());
    logger.info("------------------");
    logger.info("False Negative:\t" + fn);
    logger.info("False Positive:\t" + fp);
    logger.info("True  Negative:\t" + tn);
    logger.info("True Positive:\t" + tp);
    logger.info("------------------");
    logger.info("Presition:\t" + df.format(presicion * 100) + "%");
    logger.info("Recall:\t" + df.format(recall * 100) + "%");
    logger.info("Acurracy:\t" + df.format(accuracy * 100) + "%");
    logger.info("F-Measure:\t" + df.format(fMeasure * 100) + "%");
    logger.info("");
    logger.info("");
}

From source file:com.projity.pm.graphic.model.event.CompositeCacheEvent.java

private void generateDiffLists() {
    if (diffListsGenerated)
        return;/*from w w w .ja v  a 2 s  . c  o  m*/

    //nodes
    CacheEvent event;
    List nodes;
    for (Iterator i = nodeEvents.iterator(); i.hasNext();) {
        event = (CacheEvent) i.next();
        nodes = event.getNodes();
        switch (event.getType()) {
        case CacheEvent.NODES_CHANGED:
            if (nodes != null && nodes.size() > 0) {
                if (updatedNodes == null)
                    updatedNodes = new ArrayList(nodes.size());
                updatedNodes.addAll(nodes);
            }
            break;
        case CacheEvent.NODES_INSERTED:
            //              check for hidden updates
            if (removedNodes != null) {
                List inter = ListUtils.intersection(nodes, removedNodes);
                if (inter.size() > 0) {
                    removedNodes.removeAll(inter);
                    nodes.removeAll(inter);
                    if (updatedNodes == null)
                        updatedNodes = new ArrayList(nodes.size());
                    updatedNodes.addAll(inter);
                }
            }

            if (nodes != null && nodes.size() > 0) {
                if (insertedNodes == null)
                    insertedNodes = new ArrayList(nodes.size());
                insertedNodes.addAll(nodes);
            }
            break;
        case CacheEvent.NODES_REMOVED:
            //INSERT FOLLOWED BY REMOVE NEVER HAPPENS
            //nothing special to handle
            if (nodes != null && nodes.size() > 0) {
                if (removedNodes == null)
                    removedNodes = new ArrayList(nodes.size());
                removedNodes.addAll(nodes);
            }
            break;
        default:
            break;
        }
    }

    //edges
    for (Iterator i = edgeEvents.iterator(); i.hasNext();) {
        event = (CacheEvent) i.next();
        nodes = event.getNodes();
        switch (event.getType()) {
        case CacheEvent.NODES_CHANGED:
            if (nodes != null && nodes.size() > 0) {
                if (updatedEdges == null)
                    updatedEdges = new ArrayList(nodes.size());
                updatedEdges.addAll(nodes);
            }
            break;
        case CacheEvent.NODES_INSERTED:
            if (nodes != null && nodes.size() > 0) {
                if (insertedEdges == null)
                    insertedEdges = new ArrayList(nodes.size());
                insertedEdges.addAll(nodes);
            }
            break;
        case CacheEvent.NODES_REMOVED:
            if (nodes != null && nodes.size() > 0) {
                if (removedEdges == null)
                    removedEdges = new ArrayList(nodes.size());
                removedEdges.addAll(nodes);
            }
            break;
        default:
            break;
        }
    }

    diffListsGenerated = true;
}

From source file:com.xpn.xwiki.plugin.watchlist.WatchListEventMatcher.java

/**
 * Get the events matching criteria./*from  w  w w  . ja v  a2s .c o m*/
 * 
 * @param wikis a list of wikis from which events should match
 * @param spaces a list of spaces from which events should match
 * @param documents a list of documents from which events should match
 * @param users a list of users from which events should match
 * @param userName notification recipient
 * @param context the XWiki context
 * @return the list of events matching the given scopes
 */
public List<WatchListEvent> getMatchingEvents(List<String> wikis, List<String> spaces, List<String> documents,
        List<String> users, String userName, XWikiContext context) {
    List<WatchListEvent> matchingEvents = new ArrayList<WatchListEvent>();
    WatchListPlugin plugin = (WatchListPlugin) context.getWiki().getPlugin(WatchListPlugin.ID, context);
    List<String> jobDocumentNames = plugin.getStore().getJobDocumentNames();

    for (WatchListEvent event : events) {
        if (wikis.contains(event.getWiki()) || spaces.contains(event.getPrefixedSpace())
                || documents.contains(event.getPrefixedFullName())
                || ListUtils.intersection(users, event.getAuthors()).size() > 0) {
            try {
                // We exclude watchlist jobs from notifications since they are modified each time they are fired,
                // producing useless noise. We also ensure that users have the right to view documents we send
                // notifications for.
                if (!jobDocumentNames.contains(event.getFullName()) && context.getWiki().getRightService()
                        .hasAccessLevel("view", userName, event.getPrefixedFullName(), context)) {
                    matchingEvents.add(event);
                }
            } catch (XWikiException e) {
                // We're in a job, we don't throw exceptions
                e.printStackTrace();
            }
        }
    }

    Collections.sort(matchingEvents);

    return matchingEvents;
}