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:de.xirp.db.ChartDatabaseUtil.java

/**
 * Returns the keys that all of the given records have in common.
 * /*  w w w .  j a  v a 2  s  .  c om*/
 * @param records
 *            The records.
 * @return A list with the common keys.
 * @see de.xirp.db.Observed
 */
@SuppressWarnings("unchecked")
public static List<String> getCommonObservedKeysForRecordList(List<Record> records) {
    List<String> commonKeys = new ArrayList<String>();

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

    Session session = DatabaseManager.getCurrentHibernateSession();
    session.getTransaction().begin();

    Query query;
    for (Record record : records) {
        query = session
                .createQuery("SELECT DISTINCT obs.observedKey FROM Observed as obs WHERE obs.record = ?"); //$NON-NLS-1$
        query.setEntity(0, record);
        lists.add(query.list());
    }
    session.close();

    commonKeys = lists.get(0);
    for (List<String> list : lists) {
        commonKeys = ListUtils.intersection(commonKeys, list);
    }

    return Collections.unmodifiableList(commonKeys);
}

From source file:com.hs.mail.imap.dao.MySqlSearchDao.java

private List<Long> query(List<Long> result, UidToMsnMapper map, long mailboxID, SearchKey key, boolean and) {
    List<Long> list = query(map, mailboxID, key);
    if (CollectionUtils.isNotEmpty(result)) {
        return (and) ? ListUtils.intersection(result, list) : ListUtils.sum(result, list);
    } else {/*w ww  . j  ava2 s .  c om*/
        return list;
    }
}

From source file:com.agiletec.plugins.jacms.aps.system.services.content.showlet.ContentListHelper.java

protected List<String> executeFullTextSearch(RequestContext reqCtx, List<String> masterContentsId,
        UserFilterOptionBean fullTextUserFilter) throws ApsSystemException {
    if (fullTextUserFilter != null && null != fullTextUserFilter.getFormFieldValues()) {
        String word = fullTextUserFilter.getFormFieldValues().get(fullTextUserFilter.getFormFieldNames()[0]);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        List<String> fullTextResult = this.getSearchEngineManager().searchEntityId(currentLang.getCode(), word,
                this.getAllowedGroups(reqCtx));
        return ListUtils.intersection(fullTextResult, masterContentsId);
    } else {/*from   w  w  w.ja  va2 s .  c  o m*/
        return masterContentsId;
    }
}

From source file:es.upm.fi.dia.oeg.ogsadai.sparql.optimizers.WellDesignedRule1Optimiser.java

/**
 * checks safe condition (variables in P1 are in P2 and P')
 * //  w  ww  .j ava  2s  .co m
 * @param filterSelectOperator
 * 
 * @param optionalOperator
 *            (P1 OPT P2)
 * 
 * @return true if pattern is safe
 */
private boolean checkSafeCondition(Operator filterSelectOperator, Operator optionalOperator) {
    List<String> pPrimeAttrs = new ArrayList<String>();
    // getting variables from left side of AND (parent operator)
    for (Attribute attribute : ((SelectOperator) filterSelectOperator).getUsedAttributes()) {
        pPrimeAttrs.add(attribute.getName());
    }

    // getting variables from P2
    List<String> p2Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(1).getHeading().getAttributes()) {
        p2Attrs.add(attribute.getName());
    }
    // p2Attrs.addAll(pPrimeAttrs);

    List<String> intersection = null;
    intersection = new ArrayList<String>();
    intersection = ListUtils.intersection(pPrimeAttrs, p2Attrs);
    // getting variables from P2
    List<String> p1Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(0).getHeading().getAttributes()) {
        p1Attrs.add(attribute.getName());
    }

    if (p1Attrs.containsAll(pPrimeAttrs)) {
        return true;
    }
    return false;
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Range.java

/**
 * Returns the deepest common ancestor container of the Range's two boundary points.
 * @return the deepest common ancestor container of the Range's two boundary points
 *//*from ww  w  .ja  v a 2s .c o m*/
@SuppressWarnings("unchecked")
private Node getCommonAncestor() {
    final List<Node> startAncestors = getAncestorsAndSelf(startContainer_);
    final List<Node> endAncestors = getAncestorsAndSelf(endContainer_);
    final List<Node> commonAncestors = ListUtils.intersection(startAncestors, endAncestors);
    if (commonAncestors.isEmpty()) {
        return null;
    }
    return commonAncestors.get(0);
}

From source file:es.upm.fi.dia.oeg.ogsadai.sparql.optimizers.WellDesignedRule3Optimiser.java

/**
 * checks safe condition (variables in P1 are in P2 and P')
 * /*from   w  w w .  ja v  a2 s.  co m*/
 * @param ousideOperator
 *            operator P'
 * @param optionalOperator
 *            (P1 OPT P2)
 * 
 * @return true if pattern is safe
 */
private boolean checkSafeCondition(Operator ousideOperator, Operator optionalOperator) {
    List<String> pPrimeAttrs = new ArrayList<String>();
    // getting variables from left side of AND (parent operator)
    for (Attribute attribute : ousideOperator.getHeading().getAttributes()) {
        pPrimeAttrs.add(attribute.getName());
    }

    // getting variables from P2
    List<String> p2Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(1).getHeading().getAttributes()) {
        p2Attrs.add(attribute.getName());
    }
    // p2Attrs.addAll(pPrimeAttrs);

    List<String> intersection = null;
    intersection = new ArrayList<String>();
    intersection = ListUtils.intersection(pPrimeAttrs, p2Attrs);
    // getting variables from P2
    List<String> p1Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(0).getHeading().getAttributes()) {
        p1Attrs.add(attribute.getName());
    }

    if (p1Attrs.containsAll(intersection)) {
        return true;
    }
    return false;
}

From source file:com.agiletec.plugins.jacms.aps.system.services.content.widget.ContentListHelper.java

protected List<String> executeFullTextSearch(IContentListTagBean bean, List<String> masterContentsId,
        RequestContext reqCtx) throws ApsSystemException {
    UserFilterOptionBean fullTextUserFilter = null;
    List<UserFilterOptionBean> userFilterOptions = bean.getUserFilterOptions();
    if (null != userFilterOptions) {
        for (int i = 0; i < userFilterOptions.size(); i++) {
            UserFilterOptionBean userFilter = userFilterOptions.get(i);
            if (null != userFilter.getFormFieldValues() && userFilter.getFormFieldValues().size() > 0) {
                if (!userFilter.isAttributeFilter()
                        && userFilter.getKey().equals(UserFilterOptionBean.KEY_FULLTEXT)) {
                    fullTextUserFilter = userFilter;
                }//from  w  w  w  .j  a  va 2  s .  c  o  m
            }
        }
    }
    if (fullTextUserFilter != null && null != fullTextUserFilter.getFormFieldValues()) {
        String word = fullTextUserFilter.getFormFieldValues().get(fullTextUserFilter.getFormFieldNames()[0]);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        List<String> fullTextResult = this.getSearchEngineManager().searchEntityId(currentLang.getCode(), word,
                this.getAllowedGroups(reqCtx));
        return ListUtils.intersection(fullTextResult, masterContentsId);
    } else {
        return masterContentsId;
    }
}

From source file:es.upm.fi.dia.oeg.ogsadai.sparql.optimizers.WellDesignedRule2Optimiser.java

/**
 * checks safe condition (variables in P1 are in P2 and P')
 * /*w  w  w .  ja  v  a2  s  .  c o  m*/
 * @param ousideOperator
 *            operator P'
 * @param optionalOperator
 *            (P1 OPT P2)
 * 
 * @return true if pattern is safe
 */
private boolean checkSafeCondition(Operator ousideOperator, Operator optionalOperator) {
    List<String> pPrimeAttrs = new ArrayList<String>();
    // getting variables from left side of AND (parent operator)
    for (Attribute attribute : ousideOperator.getHeading().getAttributes()) {
        pPrimeAttrs.add(attribute.getName());
    }

    // getting variables from P2
    List<String> p2Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(1).getHeading().getAttributes()) {
        p2Attrs.add(attribute.getName());
    }

    List<String> intersection = null;
    intersection = new ArrayList<String>();
    intersection = ListUtils.intersection(pPrimeAttrs, p2Attrs);
    // getting variables from P2
    List<String> p1Attrs = new ArrayList<String>();
    for (Attribute attribute : optionalOperator.getChild(0).getHeading().getAttributes()) {
        p1Attrs.add(attribute.getName());
    }

    if (p1Attrs.containsAll(intersection)) {
        return true;
    }
    return false;
}

From source file:io.cloudslang.lang.tools.build.SlangBuilderTest.java

@Test
public void testProcessRunTestsMixed() {
    final Map<String, SlangTestCase> testCases = new LinkedHashMap<>();
    final SlangTestCase testCase1 = new SlangTestCase("test1", "testFlowPath", "desc", asList("abc", "new"),
            "mock", null, null, false, "SUCCESS");
    final SlangTestCase testCase2 = new SlangTestCase("test2", "testFlowPath", "desc", asList("efg", "new"),
            "mock", null, null, false, "SUCCESS");
    final SlangTestCase testCase3 = new SlangTestCase("test3", "testFlowPath", "desc", asList("new", "new2"),
            "mock", null, null, false, "SUCCESS");
    final SlangTestCase testCase4 = new SlangTestCase("test4", "testFlowPath", "desc", asList("new", "new2"),
            "mock", null, null, false, "SUCCESS");

    testCases.put("test1", testCase1);
    testCases.put("test2", testCase2);
    testCases.put("test3", testCase3);
    testCases.put("test4", testCase4);

    final List<String> testSuites = newArrayList("new");
    final Map<String, CompilationArtifact> compiledFlows = new HashMap<>();
    final String projectPath = "aaa";

    final AtomicReference<ThreadSafeRunTestResults> theCapturedArgument = new AtomicReference<>();
    final AtomicReference<Map<String, SlangTestCase>> capturedTestsSeq = new AtomicReference<>();
    final AtomicReference<Map<String, SlangTestCase>> capturedTestsPar = new AtomicReference<>();

    doCallRealMethod().when(slangTestRunner).isTestCaseInActiveSuite(any(SlangTestCase.class), anyList());
    doReturn(SlangBuildMain.TestCaseRunMode.SEQUENTIAL).doReturn(SlangBuildMain.TestCaseRunMode.PARALLEL)
            .doReturn(SlangBuildMain.TestCaseRunMode.PARALLEL)
            .doReturn(SlangBuildMain.TestCaseRunMode.SEQUENTIAL).when(testRunInfoService)
            .getRunModeForTestCase(any(SlangTestCase.class), any(ConflictResolutionStrategy.class),
                    any(DefaultResolutionStrategy.class));

    doAnswer(new Answer() {
        @Override//from  w  w  w. jav a 2s.c o m
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] arguments = invocationOnMock.getArguments();
            Object argument = arguments[arguments.length - 2];
            theCapturedArgument.set((ThreadSafeRunTestResults) argument);

            return invocationOnMock.callRealMethod();
        }
    }).when(slangTestRunner).splitTestCasesByRunState(any(BulkRunMode.class), anyMap(), anyList(),
            any(IRunTestResults.class), eq(buildModeConfig));

    doAnswer(new Answer() {
        @Override
        @SuppressWarnings("unchecked")
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] arguments = invocationOnMock.getArguments();
            capturedTestsSeq.set((Map<String, SlangTestCase>) arguments[1]);

            return null;
        }
    }).when(slangTestRunner).runTestsSequential(anyString(), anyMap(), anyMap(), any(IRunTestResults.class));
    doAnswer(new Answer() {
        @Override
        @SuppressWarnings("unchecked")
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] arguments = invocationOnMock.getArguments();
            capturedTestsPar.set((Map<String, SlangTestCase>) arguments[1]);

            return null;
        }
    }).when(slangTestRunner).runTestsParallel(anyString(), anyMap(), anyMap(),
            any(ThreadSafeRunTestResults.class));

    // Tested call
    slangBuilder.processRunTests(projectPath, testSuites, POSSIBLY_MIXED, compiledFlows, testCases,
            buildModeConfig);

    InOrder inOrder = inOrder(slangTestRunner);
    inOrder.verify(slangTestRunner).splitTestCasesByRunState(eq(POSSIBLY_MIXED), eq(testCases), eq(testSuites),
            isA(ThreadSafeRunTestResults.class), eq(buildModeConfig));
    inOrder.verify(slangTestRunner).runTestsSequential(eq(projectPath), anyMap(), eq(compiledFlows),
            eq(theCapturedArgument.get()));
    inOrder.verify(slangTestRunner).runTestsParallel(eq(projectPath), anyMap(), eq(compiledFlows),
            eq(theCapturedArgument.get()));

    final List<SlangTestCase> listSeq = newArrayList(capturedTestsSeq.get().values());
    final List<SlangTestCase> listPar = newArrayList(capturedTestsPar.get().values());
    assertEquals(0, ListUtils.intersection(listSeq, listPar).size()); // assures that a test is run only once
    assertEquals(newHashSet(testCases.values()), newHashSet(ListUtils.union(listSeq, listPar)));
}

From source file:hydrograph.ui.dataviewer.filter.FilterHelper.java

/**
 * Validate user group selection.//  w  w  w . j  a v  a 2s .c  o m
 * 
 * @param groupSelectionMap
 *            the group selection map
 * @param selectionList
 *            the selection list
 * @return true, if successful
 */
public boolean validateUserGroupSelection(Map<Integer, List<List<Integer>>> groupSelectionMap,
        List<Integer> selectionList) {
    boolean retValue = true;
    for (int key : groupSelectionMap.keySet()) {
        List<List<Integer>> groups = groupSelectionMap.get(key);
        for (List<Integer> grp : groups) {
            if (selectionList.size() == grp.size()) {
                if (!ListUtils.isEqualList(selectionList, grp)
                        && ListUtils.intersection(selectionList, grp).size() == 0) {
                    retValue = true;
                } else if (ListUtils.isEqualList(selectionList, grp)) {
                    if (createErrorDialog(Messages.GROUP_CLAUSE_ALREADY_EXISTS).open() == SWT.OK) {
                        retValue = false;
                        break;
                    }
                } else if (ListUtils.intersection(selectionList, grp).size() > 0) {
                    if (createErrorDialog(Messages.CANNOT_CREATE_GROUP_CLAUSE).open() == SWT.OK) {
                        retValue = false;
                        break;
                    }
                }
            } else {
                if (ListUtils.isEqualList(ListUtils.intersection(selectionList, grp), grp)) {
                    retValue = true;
                } else if (ListUtils.isEqualList(ListUtils.intersection(grp, selectionList), selectionList)) {
                    retValue = true;
                } else if (ListUtils.intersection(selectionList, grp).size() == 0) {
                    retValue = true;
                } else {
                    if (createErrorDialog(Messages.CANNOT_CREATE_GROUP_CLAUSE).open() == SWT.OK) {
                        retValue = false;
                        break;
                    }
                }
            }
        }
        if (!retValue) {
            break;
        }
    }
    return retValue;
}