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:com.assignmentone.util.persondb.AbstractDbManager.java

@SuppressWarnings("unchecked")
public synchronized T find(final int id) {
    T entity = (T) CollectionUtils.find(entityList, new Predicate() {
        @Override// w w w  . java2  s .  c  o m
        public boolean evaluate(Object object) {
            return ((T) object).getId() == id;
        }
    });
    try {
        return (T) entity.clone();
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public SearchPageData<UserData> getPagedApproversForUnit(final PageableData pageableData,
        final String unitUid) {
    final SearchPageData<B2BCustomerModel> approvers = getB2BCommerceUnitService()
            .findPagedApproversForUnitByGroupMembership(pageableData, unitUid, B2BConstants.B2BAPPROVERGROUP);
    final SearchPageData<UserData> searchPageData = convertPageData(approvers, getB2BUserConverter());
    // update the results with approvers 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.getApprovers(),
                new BeanPropertyValueEqualsPredicate(B2BCustomerModel.UID, userData.getUid())) != null);
    }// w ww.  j  ava  2s  . c  o  m

    return searchPageData;
}

From source file:edu.kit.rest.usergroupmanagement.test.UserGroupTestService.java

private UserGroup findGroupById(final Long id) {
    return (UserGroup) CollectionUtils.find(groups, new Predicate() {

        @Override/*from  w  ww . ja  v a  2s  .  c o  m*/
        public boolean evaluate(Object o) {
            return Objects.equals(((UserGroup) o).getId(), id);
        }
    });
}

From source file:net.sourceforge.fenixedu.domain.teacher.Advise.java

public TeacherAdviseService getTeacherAdviseServiceByExecutionPeriod(
        final ExecutionSemester executionSemester) {
    return (TeacherAdviseService) CollectionUtils.find(getTeacherAdviseServicesSet(), new Predicate() {
        @Override/*from w  w w. j a v  a 2s . c  o  m*/
        public boolean evaluate(Object arg0) {
            TeacherAdviseService teacherAdviseService = (TeacherAdviseService) arg0;
            return teacherAdviseService.getTeacherService().getExecutionPeriod() == executionSemester;
        }
    });
}

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

public static PhdProgramFocusArea readPhdProgramFocusAreaByName(final String name) {
    return (PhdProgramFocusArea) CollectionUtils.find(Bennu.getInstance().getPhdProgramFocusAreasSet(),
            new Predicate() {

                @Override/*from   w ww.  j  av a 2s .c  o m*/
                public boolean evaluate(Object arg0) {
                    return name.equals(((PhdProgramFocusArea) arg0).getName().getContent());
                }

            });
}

From source file:eionet.gdem.services.db.dao.SchemaDaoTest.java

@Test
public void getSchemasWithNoRelations() {
    List<Schema> schemas = schemaDao.getSchemasWithRelations();

    Schema schema = (Schema) CollectionUtils.find(schemas, new BeanPredicate("id", new EqualPredicate("6")));

    assertEquals("http://dd.eionet.europa.eu/GetSchema?id=TBL112", schema.getSchema());
    assertEquals("No relations", schema.getDescription());
    assertNull(schema.getUplSchemaFileName());
    assertEquals(0, schema.getCountQaScripts());
    assertEquals(0, schema.getCountStylesheets());

}

From source file:com.tesora.dve.charset.NativeCollationCatalogImpl.java

@Override
public NativeCollation findDefaultCollationForCharSet(String charsetName) {
    final List<NativeCollation> collations = collationsByCharsetName
            .get(charsetName.toUpperCase(Locale.ENGLISH));
    if (collations == null) {
        return null;
    }/*  w w  w .j a v  a 2s  .  c o  m*/

    final NativeCollation defaultCollation = (NativeCollation) CollectionUtils.find(collations,
            new Predicate() {
                @Override
                public boolean evaluate(Object arg0) {
                    if (arg0 instanceof NativeCollation) {
                        final NativeCollation nc = (NativeCollation) arg0;
                        return nc.isDefault();
                    }
                    return false;
                }
            });

    if (defaultCollation == null) {
        throw new PECodingException("No default collation found for character set '" + charsetName + "'");
    }

    return defaultCollation;
}

From source file:de.hybris.platform.acceleratorservices.sitemap.renderer.SiteMapContext.java

public void init(final CMSSiteModel site, final SiteMapPageEnum siteMapPageEnum) {
    final String currentUrlEncodingPattern = getUrlEncoderService().getCurrentUrlEncodingPattern();
    this.put(BASE_URL,
            getSiteBaseUrlResolutionService().getWebsiteUrlForSite(site, currentUrlEncodingPattern, false, ""));
    this.put(MEDIA_URL, getSiteBaseUrlResolutionService().getMediaUrlForSite(site, false, ""));

    final Collection<SiteMapPageModel> siteMapPages = site.getSiteMapConfig().getSiteMapPages();
    final SiteMapPageModel siteMapPageModel = (SiteMapPageModel) CollectionUtils.find(siteMapPages,
            new Predicate() {
                @Override//  w ww  .j  ava 2s . c o  m
                public boolean evaluate(final Object o) {
                    return ((SiteMapPageModel) o).getCode().equals(siteMapPageEnum);
                }
            });

    if (siteMapPageModel != null) {
        this.put(CHANGE_FREQ, siteMapPageModel.getFrequency().getCode());
        this.put(PRIORITY, siteMapPageModel.getPriority());
    } else {
        this.put(CHANGE_FREQ, SiteMapChangeFrequencyEnum.DAILY.getCode());
        this.put(PRIORITY, Double.valueOf(0.5D));
    }
}

From source file:net.sourceforge.fenixedu.domain.accounting.events.serviceRequests.PartialRegistrationRegimeRequestEvent.java

@Override
public PostingRule getPostingRule() {
    Set<PostingRule> activePostingRules = getAdministrativeOffice().getServiceAgreementTemplate()
            .getActivePostingRules(getExecutionYear().getBeginDateYearMonthDay().toDateTimeAtMidnight());

    return (PostingRule) CollectionUtils.find(activePostingRules, new Predicate() {

        @Override/* w  w  w  .  j av a2 s  .co  m*/
        public boolean evaluate(Object arg0) {
            return ((PostingRule) arg0).getEventType().equals(getEventType())
                    && ((PartialRegistrationRegimeRequestPR) arg0).getExecutionYear()
                            .equals(getAcademicServiceRequest().getExecutionYear());
        }

    });
}

From source file:de.hybris.platform.security.captcha.ReCaptchaAspect.java

public Object advise(final ProceedingJoinPoint joinPoint) throws Throwable {

    final boolean captcaEnabledForCurrentStore = isCaptcaEnabledForCurrentStore();
    if (captcaEnabledForCurrentStore) {
        final List<Object> args = Arrays.asList(joinPoint.getArgs());
        HttpServletRequest request = (HttpServletRequest) CollectionUtils.find(args,
                PredicateUtils.instanceofPredicate(HttpServletRequest.class));

        if (request == null
                && RequestContextHolder.getRequestAttributes() instanceof ServletRequestAttributes) {
            final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes();
            request = requestAttributes.getRequest();
        }/*  w  w w  .  j  a va 2s .com*/

        if (request != null) {
            request.setAttribute("captcaEnabledForCurrentStore", Boolean.valueOf(captcaEnabledForCurrentStore));
            request.setAttribute("recaptchaPublicKey",
                    getSiteConfigService().getProperty(RECAPTCHA_PUBLIC_KEY_PROPERTY));
            final String challengeFieldValue = request.getParameter(RECAPTCHA_CHALLENGE_FIELD_PARAM);
            final String responseFieldValue = request.getParameter(RECAPTCHA_RESPONSE_FIELD_PARAM);
            if ((StringUtils.isBlank(challengeFieldValue) || StringUtils.isBlank(responseFieldValue))
                    || !checkAnswer(request, challengeFieldValue, responseFieldValue)) {
                // if there is an error add a message to binding result.
                final BindingResult bindingResult = (BindingResult) CollectionUtils.find(args,
                        PredicateUtils.instanceofPredicate(BindingResult.class));
                if (bindingResult != null) {
                    bindingResult.reject("recaptcha.challenge.field.invalid", "Challenge Answer is invalid.");
                }
                request.setAttribute("recaptchaChallangeAnswered", Boolean.FALSE);
            }
        }
    }
    return joinPoint.proceed();
}