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

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

Introduction

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

Prototype

public static boolean exists(Collection collection, Predicate predicate) 

Source Link

Document

Answers true if a predicate is true for at least one element of a collection.

Usage

From source file:com.doculibre.constellio.utils.EqualityUtils.java

public static <T extends Object> boolean contains(Collection<T> collection, T bean, String propertyName) {
    Object propertyValue;//from ww w  . j av  a  2  s  .  co m
    try {
        propertyValue = PropertyUtils.getProperty(bean, propertyName);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    EqualPredicate equalityPredicate = new EqualPredicate(propertyValue);
    BeanPredicate beanPredicate = new BeanPredicate(propertyName, equalityPredicate);
    return CollectionUtils.exists(collection, beanPredicate);
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.RemoveProfessorshipWithPerson.java

@Atomic
public static Boolean run(Person person, ExecutionCourse executionCourse) throws NotAuthorizedException {
    AbstractModifyProfessorshipWithPerson.run(person);

    Professorship professorshipToDelete = person.getProfessorshipByExecutionCourse(executionCourse);

    Collection shiftProfessorshipList = professorshipToDelete.getAssociatedShiftProfessorshipSet();

    boolean hasCredits = false;

    if (!shiftProfessorshipList.isEmpty()) {
        hasCredits = CollectionUtils.exists(shiftProfessorshipList, new Predicate() {

            @Override//from   w  w w.  j  a v  a 2s  . com
            public boolean evaluate(Object arg0) {
                ShiftProfessorship shiftProfessorship = (ShiftProfessorship) arg0;
                return shiftProfessorship.getPercentage() != null && shiftProfessorship.getPercentage() != 0;
            }
        });
    }

    if (!hasCredits) {
        professorshipToDelete.delete();
    } else {
        if (hasCredits) {
            throw new DomainException("error.remove.professorship");
        }
    }
    return Boolean.TRUE;
}

From source file:fr.dudie.acrachilisync.utils.ChiliprojectUtils.java

/**
 * Gets wheter or not the given report has already been synchronized with the given issue.
 * /*from w  w  w  .  j a  va  2 s  .co  m*/
 * @param pReport
 *            an ACRA report
 * @param pIssue
 *            a Chiliproject issue
 * @return true if the given report has already been synchronized with the given issue
 * @throws IssueParseException
 *             the Date of one of the synchronized issue is unreadable
 */
public static boolean isSynchronized(final AcraReport pReport, final Issue pIssue) throws IssueParseException {

    final IssueDescriptionReader reader = new IssueDescriptionReader(pIssue);
    return CollectionUtils.exists(reader.getOccurrences(), new ReportPredicate(pReport));
}

From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java

protected boolean requestURIRequiresAuthentication(final HttpServletRequest request) {
    return !CollectionUtils.exists(getUnprotectedURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }/*w ww  . jav a 2s.c o  m*/
    });
}

From source file:com.exxonmobile.ace.hybris.storefront.security.ExcludeUrlRequestMatcher.java

@Override
public boolean matches(final HttpServletRequest request) {
    // Do not match patterns specified in the excludeUrlSet to the servletPath
    return !CollectionUtils.exists(this.excludeUrlSet, new Predicate() {
        @Override//from ww w.jav a 2 s . c o m
        public boolean evaluate(final Object excludeUrl) {
            return pathMatcher.match((String) excludeUrl, request.getServletPath());
        }
    });
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.student.ReadAvailableFinalDegreeWorkProposalHeadersForGroup.java

@Atomic
public static List run(String groupOID) {
    check(RolePredicates.STUDENT_PREDICATE);
    final List<FinalDegreeWorkProposalHeader> result = new ArrayList<FinalDegreeWorkProposalHeader>();

    final FinalDegreeWorkGroup group = FenixFramework.getDomainObject(groupOID);

    if (group != null && group.getExecutionDegree() != null) {
        final Set<Proposal> finalDegreeWorkProposals = group.getExecutionDegree().getScheduling()
                .findPublishedProposals();

        for (final Proposal proposal : finalDegreeWorkProposals) {
            if (!CollectionUtils.exists(group.getGroupProposalsSet(),
                    new PREDICATE_FIND_GROUP_PROPOSAL_BY_PROPOSAL(proposal))) {
                result.add(FinalDegreeWorkProposalHeader.newInfoFromDomain(proposal));
            }/*from   w w w.  j a  v  a  2 s. c om*/
        }
    }

    return result;
}

From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java

protected boolean requestURIdoesLogin(final HttpServletRequest request) {
    return CollectionUtils.exists(getLoginURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }//from   w w w .  j  a  va 2  s .com
    });
}

From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java

protected boolean requestPostCsfrWhitelist(final HttpServletRequest request) {
    return CollectionUtils.exists(getPostUnprotectedURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }//from w w w .j a va2 s .  co m
    });
}

From source file:com.tacitknowledge.flip.AbstractFeatureServiceFactory.java

/**
 * Determines whether provided <code>list</code> contains item 
 * of a given type <code>klass</code>
 * /*from  w  ww.  j  a  v a  2 s  .  co m*/
 * @param list {@link List} to process
 * @param klass item type to look for
 * @return <code>true</code> in case there is an existent item of a given type within
 *  provided list, <code>false</code> - otherwise
 */
protected boolean isListHasItemOfType(final List<?> list, final Class<?> klass) {
    return CollectionUtils.exists(list, InstanceofPredicate.getInstance(klass));
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.DeleteProfessorshipWithPerson.java

@Atomic
public static Boolean run(Person person, ExecutionCourse executionCourse) throws NotAuthorizedException {
    try {/*ww  w  .  j  a va2s . co m*/

        final Person loggedPerson = AccessControl.getPerson();

        Professorship selectedProfessorship = null;
        selectedProfessorship = person.getProfessorshipByExecutionCourse(executionCourse);

        if ((loggedPerson == null) || (selectedProfessorship == null) || !loggedPerson.hasRole(RoleType.TEACHER)
                || isSamePersonAsBeingRemoved(loggedPerson, selectedProfessorship.getPerson())
                || selectedProfessorship.getResponsibleFor()) {
            throw new NotAuthorizedException();
        }
    } catch (RuntimeException e) {
        throw new NotAuthorizedException();
    }

    Professorship professorshipToDelete = person.getProfessorshipByExecutionCourse(executionCourse);

    Collection shiftProfessorshipList = professorshipToDelete.getAssociatedShiftProfessorshipSet();

    boolean hasCredits = false;

    if (!shiftProfessorshipList.isEmpty()) {
        hasCredits = CollectionUtils.exists(shiftProfessorshipList, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                ShiftProfessorship shiftProfessorship = (ShiftProfessorship) arg0;
                return shiftProfessorship.getPercentage() != null && shiftProfessorship.getPercentage() != 0;
            }
        });
    }

    if (!hasCredits && professorshipToDelete.getStudentInquiriesTeachingResultsSet().isEmpty()) {
        professorshipToDelete.delete();
    } else {
        if (hasCredits) {
            throw new DomainException("error.remove.professorship");
        }
    }
    return Boolean.TRUE;
}