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

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

Introduction

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

Prototype

public static Collection intersection(final Collection a, final Collection b) 

Source Link

Document

Returns a Collection containing the intersection of the given Collection s.

Usage

From source file:edu.harvard.med.screensaver.ui.arch.datatable.ColumnVisibilityChangedEvent.java

public ColumnVisibilityChangedEvent(Collection<? extends TableColumn<?, ?>> added,
        Collection<? extends TableColumn<?, ?>> removed) {
    if (CollectionUtils.intersection(added, removed).size() > 0) {
        throw new IllegalArgumentException("'added' and 'removed' collections must be disjoint");
    }//from ww w.  j  a  v  a2  s . c o m
    if (added != null) {
        _added.addAll(added);
    }
    if (removed != null) {
        _removed.addAll(removed);
    }
}

From source file:com.google.mr4c.sources.AggregateFileSource.java

public List<String> getAllFileNames() throws IOException {
    List<String> names = new ArrayList<String>();
    for (FileSource src : m_sources) {
        List<String> newNames = src.getAllFileNames();
        Collection<String> dups = CollectionUtils.intersection(names, newNames);
        if (!dups.isEmpty()) {
            throw new IllegalStateException("Found the following repeated file names: " + dups);
        }/*from   www  .j a  va 2  s  .c  o  m*/
        names.addAll(newNames);
    }
    return names;
}

From source file:com.hiperium.dao.common.list.impl.ListOperationDAOImpl.java

/**
 * {@inheritDoc}//from w ww  . ja v a  2s .c om
 */
@SuppressWarnings("unchecked")
public void process(@NotNull List<T> actualList, @NotNull List<T> newList, @NotNull String sessionId) {
    Collection<T> toUpdateOriginal = CollectionUtils.intersection(actualList, newList);
    Collection<T> toUpdateNew = CollectionUtils.intersection(newList, actualList);
    Collection<T> delete = CollectionUtils.subtract(actualList, newList);
    for (T entity : delete) {
        this.entityManager.remove(entity);
    }
    Collection<T> insert = CollectionUtils.subtract(newList, actualList);
    for (T entity : insert) {
        this.entityManager.persist(entity);
    }
    T[] updatedOriginalList = (T[]) toUpdateOriginal.toArray();
    T[] updatedNewList = (T[]) toUpdateNew.toArray();
    for (int i = 0; i < updatedOriginalList.length; i++) {
        boolean update = false;
        try {
            Map<String, String> originalProperties = BeanUtils.describe(updatedOriginalList[i]);
            Map<String, String> newProperties = BeanUtils.describe(updatedNewList[i]);
            Set<String> properties = originalProperties.keySet();
            for (String string : properties) {
                if (!(originalProperties.get(string) == null && newProperties.get(string) == null)
                        && !originalProperties.get(string).equals(newProperties.get(string))) {
                    update = true;
                    break;
                }
            }
        } catch (Exception e) {
            update = true;
        }
        if (update) {
            this.entityManager.merge(updatedNewList[i]);
        }
    }
}

From source file:com.github.NeighborRegion.java

public int cut_point_count(final NeighborRegion other) {
    return CollectionUtils.intersection(watchers, other.watchers).size();
}

From source file:net.sourceforge.atunes.kernel.modules.search.AndLogicalSearchOperator.java

@SuppressWarnings("unchecked")
@Override/*from w  w  w . ja  va  2  s. c o  m*/
public Collection<IAudioObject> evaluate(List<ISearchNode> operands) {
    Collection<IAudioObject> intersection = null;
    for (ISearchNode operand : operands) {
        Collection<IAudioObject> operandResult = operand.evaluate();
        if (operandResult != null) {
            if (intersection == null) {
                intersection = operandResult;
            } else {
                intersection = CollectionUtils.intersection(intersection, operandResult);
            }
        }
    }
    return intersection;
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.phd.AccessTypeAvailableTag.java

private boolean hasProcessNecessaryStateTypes() {
    return !CollectionUtils
            .intersection(getAccessType().getAcceptedTypes(), getMainProcess().getAllPhdProcessStateTypes())
            .isEmpty();/*  www. ja v a2  s .  c o  m*/
}

From source file:controllers.Service.java

public static void toPreview(String surveyId, String resultIDs) {
    // Find the survey
    Survey survey = Survey.findById(Long.decode(surveyId));

    // make an array of results
    Collection<NdgResult> results = new ArrayList<NdgResult>();
    NdgResult result = null;// w  w  w .j  a v  a 2s  . c  o m

    // Get the result
    result = NdgResult.find("byId", Long.parseLong(resultIDs)).first();
    if (result != null) {
        results.add(result);
    }

    // loop the result
    for (NdgResult current : results) {
        List<Question> questions = new ArrayList<Question>();
        questions = survey.getQuestions();
        LinkedList preview = new LinkedList();

        if (questions.isEmpty()) {
            preview.add("No question");
        }

        // loop the questions in the result
        for (Question question : questions) {
            preview.add(question.label);

            // get answers which correspond with questions
            Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection,
                    current.answerCollection);
            if (answers.isEmpty()) {
                preview.add("No answer");
            } else if (answers.size() == 1) {
                Answer answer = answers.iterator().next();
                //System.out.println("Answer " + answer.textData);
                if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) {
                    preview.add(answer.binaryData);
                } else {
                    preview.add(answer.textData);
                }
            }
        }

        JSONSerializer previewSerializer = new JSONSerializer();
        previewSerializer.rootName("preview");
        renderJSON(previewSerializer.serialize(preview));
    }

}

From source file:com.dm.estore.core.models.AbstractEntity.java

@SuppressWarnings("unchecked")
public <Y> Y cloneTo(Y targetBean) {
    try {//from ww  w .  jav a  2 s .  c o m
        Map<String, String> sourceBeanProperties = BeanUtils.describe(this);
        Map<String, String> targetBeanProperties = BeanUtils.describe(targetBean);
        Collection<String> commonProperties = CollectionUtils.intersection(sourceBeanProperties.keySet(),
                targetBeanProperties.keySet());
        for (String property : commonProperties) {
            BeanUtils.copyProperty(this, property, targetBean);
        }

        return targetBean;

    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {

        throw new ImmutableStateException(e);
    }
}

From source file:net.sourceforge.fenixedu.domain.phd.email.PhdProgramEmailBean.java

public AndPredicate<PhdIndividualProgramProcess> getManagedPhdProgramsPredicate() {
    final AndPredicate<PhdIndividualProgramProcess> result = new AndPredicate<PhdIndividualProgramProcess>();
    if (getPhdProgram() != null) {
        result.add(new InlinePredicate<PhdIndividualProgramProcess, PhdProgram>(getPhdProgram()) {

            @Override//w w w. j  a v a  2 s .  c o m
            public boolean eval(PhdIndividualProgramProcess toEval) {
                if (toEval.getPhdProgram() != null) {
                    return getValue().equals(toEval.getPhdProgram());
                } else if (toEval.getPhdProgramFocusArea() != null) {
                    return !CollectionUtils.intersection(Collections.singleton(getValue()),
                            toEval.getPhdProgramFocusArea().getPhdProgramsSet()).isEmpty();
                } else {
                    return false;
                }
            }
        });
    }

    return result;
}

From source file:net.sourceforge.fenixedu.domain.CurricularCourseEquivalence.java

private void checkIfEquivalenceAlreadyExists(CurricularCourse curricularCourse,
        Collection<CurricularCourse> oldCurricularCourses) {
    int size = oldCurricularCourses.size();
    for (final CurricularCourseEquivalence curricularCourseEquivalence : curricularCourse
            .getCurricularCourseEquivalencesSet()) {
        int sizeOld = curricularCourseEquivalence.getOldCurricularCoursesSet().size();
        if ((size == sizeOld) && CollectionUtils
                .intersection(oldCurricularCourses, curricularCourseEquivalence.getOldCurricularCoursesSet())
                .size() == size) {//from   w  w  w  . ja v  a  2  s  .  c  om
            throw new DomainException("error.exists.curricular.course.equivalency");
        }
    }
}