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

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

Introduction

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

Prototype

public static Object find(Collection collection, Predicate predicate) 

Source Link

Document

Finds the first element in the given collection which matches the given predicate.

Usage

From source file:net.sourceforge.fenixedu.dataTransferObject.CurricularCourseScopesForPrintDTO.java

private CurricularSemesterForPrintDTO getSelectedSemester(final InfoCurricularCourseScope scope,
        BranchForPrintDTO selectedBranch) {
    CurricularSemesterForPrintDTO selectedSemester = (CurricularSemesterForPrintDTO) CollectionUtils
            .find(selectedBranch.getSemesters(), new Predicate() {

                @Override/* ww  w . j  a v a2s .  c o  m*/
                public boolean evaluate(Object arg0) {
                    CurricularSemesterForPrintDTO curricularSemesterForPrintDTO = (CurricularSemesterForPrintDTO) arg0;
                    if (curricularSemesterForPrintDTO.getSemester()
                            .equals(scope.getInfoCurricularSemester().getSemester())) {
                        return true;
                    }
                    return false;
                }

            });
    if (selectedSemester == null) {
        selectedSemester = new CurricularSemesterForPrintDTO(scope.getInfoCurricularSemester().getSemester());
        selectedBranch.getSemesters().add(selectedSemester);
    }

    return selectedSemester;
}

From source file:com.redhat.rhn.frontend.xmlrpc.preferences.locale.PreferencesLocaleHandler.java

/**
 * Set the language the user will display in the user interface.
 * @param loggedInUser The current user//from w  w w  . ja v a2  s .c  om
 * in user.
 * @param login The login of the user whose language will be changed.
 * @param locale Locale code to be used as the users language.
 * @return Returns 1 if successful (exception otherwise)
 *
 * @xmlrpc.doc Set a user's locale.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param_desc("string", "login", "User's login name.")
 * @xmlrpc.param #param_desc("string", "locale", "Locale to set. (from listLocales)")
 * @xmlrpc.returntype #return_int_success()
 */
public int setLocale(User loggedInUser, String login, String locale) {
    LocalizationService ls = LocalizationService.getInstance();
    List locales = ls.getConfiguredLocales();
    Object o = CollectionUtils.find(locales, new LocalePredicate(locale));
    if (o == null) {
        throw new InvalidLocaleCodeException(locale);
    }

    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
    target.setPreferredLocale(locale);
    UserManager.storeUser(target);
    return 1;
}

From source file:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultB2BCommerceUnitFacade.java

@Override
public SearchPageData<UserData> getPagedCustomersForUnit(final PageableData pageableData,
        final String unitUid) {
    final SearchPageData<UserData> searchPageData = this.getPagedUserDataForUnit(pageableData, unitUid);
    // update the results with users that already have been selected.
    final B2BUnitData unit = this.getUnitForUid(unitUid);
    validateParameterNotNull(unit, String.format("No unit found for uid %s", unitUid));
    for (final UserData userData : searchPageData.getResults()) {
        userData.setSelected(CollectionUtils.find(unit.getCustomers(),
                new BeanPropertyValueEqualsPredicate(B2BCustomerModel.UID, userData.getUid())) != null);
    }/*  w w  w. j av a 2s.  com*/

    return searchPageData;
}

From source file:net.sourceforge.fenixedu.domain.phd.ExternalPhdProgram.java

public static ExternalPhdProgram readExternalPhdProgramByAcronym(final String acronym) {
    return (ExternalPhdProgram) CollectionUtils.find(Bennu.getInstance().getExternalPhdProgramsSet(),
            new Predicate() {

                @Override/* w  w w.  ja  v  a  2  s . co m*/
                public boolean evaluate(Object object) {
                    return acronym.equals(((ExternalPhdProgram) object).getAcronym());
                }

            });
}

From source file:edu.common.dynamicextensions.xmi.XMIUtilities.java

/***
 * Finds and returns the first model element having the given
 * <code>name</code> in the <code>umlPackage</code>, returns
 * <code>null</code> if not found.
 *
 * @param umlPackage The modelPackage to search
 * @param name the name to find.//  w w  w. j  a  v  a 2 s .c o  m
 * @return the found model element.
 */
public static Object find(org.omg.uml.modelmanagement.UmlPackage umlPackage, final String name) {
    return CollectionUtils.find(umlPackage.getOwnedElement(), new Predicate() {

        public boolean evaluate(Object object) {
            return StringUtils.trimToEmpty(((ModelElement) object).getName()).equals(name);
            //return true;
        }
    });
}

From source file:net.sourceforge.fenixedu.dataTransferObject.guide.reimbursementGuide.InfoReimbursementGuide.java

/**
 * @return// ww w  .  j  a  va2s  .c o  m
 */
public InfoReimbursementGuideSituation getActiveInfoReimbursementGuideSituation() {
    return (InfoReimbursementGuideSituation) CollectionUtils.find(getInfoReimbursementGuideSituations(),
            new Predicate() {
                @Override
                public boolean evaluate(Object obj) {
                    InfoReimbursementGuideSituation situation = (InfoReimbursementGuideSituation) obj;
                    return situation.getState().getState().intValue() == State.ACTIVE;
                }
            });
}

From source file:edu.kit.dama.mdm.dataorganization.impl.staging.CollectionNodeImpl.java

/**
 * Add a new child to this node./*from  w  w  w .  j ava 2 s  .c  o  m*/
 *
 * @param child The new child.
 * @param pOverwrite Overwrite the child if it already exists.
 */
public final void addChild(final IDataOrganizationNode child, boolean pOverwrite) {
    IDataOrganizationNode result;

    if (pOverwrite) {
        result = (IDataOrganizationNode) CollectionUtils.find(children, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                IDataOrganizationNode node = (IDataOrganizationNode) o;
                if (o instanceof ICollectionNode && child instanceof IFileNode) {
                    return false;
                } else if (o instanceof IFileNode && child instanceof ICollectionNode) {
                    return false;
                } else {//node types are equal...check them
                    if (node.getName() != null) {
                        return node.getName().equals(child.getName());
                    } else if (child.getName() != null) {
                        return child.getName().equals(node.getName());
                    }
                    //both are null
                    return true;
                }
            }
        });
        if (children == null) {
            children = new ArrayList<>();
        }
        children.remove(result);
    }

    addChild(child);
}

From source file:eionet.meta.service.VocabularyImportServiceTestBase.java

/**
 * Utility code to make test code more readable. Finds VocabularyConcept with given identifier in a list
 *
 * @param concepts/*  w  w  w.ja v a  2s  . c o  m*/
 *            VocabularyConcepts to be searched
 * @param identifier
 *            identifier for comparison
 * @return First found VocabularyConcept
 */
public static VocabularyConcept findVocabularyConceptByIdentifier(List<VocabularyConcept> concepts,
        String identifier) {
    return (VocabularyConcept) CollectionUtils.find(concepts,
            new VocabularyConceptEvaluateOnIdentifierPredicate(identifier));
}

From source file:com.googelcode.jpractices.Person.java

/**
     * select's the person object from collcetion based on propetyName and value
     * @param propertyName - Person's attribute (firstName (or) lastName (or) salary )
     * @param value - Value to be compared to propertyName
     *//* w  w  w.j a va2 s .  co  m*/
    void selectObjectFromCollection(String propertyName, String value) {
        EqualPredicate nameEqlPredicate = new EqualPredicate(value);
        BeanPredicate beanPredicate = new BeanPredicate(propertyName, nameEqlPredicate);
        System.out.println("Below are person object whose " + propertyName + " is " + value);
        System.out.println(CollectionUtils.find(personList, beanPredicate));
    }

From source file:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultB2BCommerceCostCenterFacade.java

@Override
public SearchPageData<B2BBudgetData> getPagedBudgetsForCostCenters(final PageableData pageableData,
        final String costCenterCode) {
    final SearchPageData<B2BBudgetData> searchPageData = this.getPagedBudgets(pageableData);
    final B2BCostCenterData costCenter = this.getCostCenterDataForCode(costCenterCode);
    for (final B2BBudgetData budgetData : searchPageData.getResults()) {
        budgetData.setSelected(CollectionUtils.find(costCenter.getB2bBudgetData(),
                new BeanPropertyValueEqualsPredicate(B2BBudgetModel.CODE, budgetData.getCode())) != null);
    }/*from  w w  w.ja v  a 2 s  .c  om*/

    return searchPageData;
}