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.newlandframework.avatarmq.consumer.ConsumerClusters.java

public void detachRemoteChannelData(String clientId) {
    channelMap.remove(clientId);/*from   w  w  w .  j  a v a  2  s. c  o m*/

    Predicate predicate = new Predicate() {
        public boolean evaluate(Object object) {
            String id = ((RemoteChannelData) object).getClientId();
            return id.compareTo(clientId) == 0;
        }
    };

    RemoteChannelData data = (RemoteChannelData) CollectionUtils.find(channelList, predicate);
    if (data != null) {
        channelList.remove(data);
    }
}

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

private UserData findUserByUserId(final String userId) {
    return (UserData) CollectionUtils.find(users, new Predicate() {

        @Override/* w  ww  .  java2s.  co  m*/
        public boolean evaluate(Object o) {
            return Objects.equals(((UserData) o).getDistinguishedName(), userId);
        }
    });
}

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

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

                @Override/*from   w  w  w  .  j a  va 2s .c om*/
                public boolean evaluate(Object object) {
                    return name.equals(((ExternalPhdProgram) object).getName().getContent());
                }

            });
}

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

/**
 * Utility code to make test code more readable. Finds VocabularyConcept with given id in a list
 *
 * @param concepts/*from w ww.ja v  a 2  s . co  m*/
 *            VocabularyConcepts to be searched
 * @param id
 *            Id for comparison
 * @return First found VocabularyConcept
 */
public static VocabularyConcept findVocabularyConceptById(List<VocabularyConcept> concepts, int id) {
    return (VocabularyConcept) CollectionUtils.find(concepts, new VocabularyConceptEvaluateOnIdPredicate(id));
}

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

@Override
public SearchPageData<UserData> getPagedApproversForCustomer(final PageableData pageableData,
        final String uid) {
    final SearchPageData<B2BCustomerModel> approvers = getB2BCommerceUserService()
            .getPagedCustomersByGroupMembership(pageableData, B2BConstants.B2BAPPROVERGROUP);
    final SearchPageData<UserData> searchPageData = convertPageData(approvers, getB2BUserConverter());
    // update the results with approvers that already have been selected.
    final CustomerData customer = this.getCustomerDataForUid(uid);
    validateParameterNotNull(customer, String.format("No customer found for uid %s", uid));
    for (final UserData userData : searchPageData.getResults()) {
        userData.setSelected(CollectionUtils.find(customer.getApprovers(),
                new BeanPropertyValueEqualsPredicate(B2BCustomerModel.UID, userData.getUid())) != null);
    }/* w  ww . j  a v a 2s  .c om*/

    return searchPageData;
}

From source file:de.hybris.platform.b2b.punchout.services.CXMLElementBrowser.java

protected <T> T findElementInList(final List<?> list, final Class<T> clazz) {
    return (T) CollectionUtils.find(list, PredicateUtils.instanceofPredicate(clazz));
}

From source file:com.ciphertool.zodiacengine.util.ZodiacSolutionPredicateEvaluator.java

@Override
public int determineConfidenceLevel(SolutionChromosome solution) {
    clearHasMatchValues(solution);// w ww .  j  av  a 2 s  .  c o m

    Plaintext plaintext = null;
    Plaintext otherPlaintext = null;
    int total = 0;
    int totalUnique = 0;
    boolean uniqueMatch = false;
    /*
     * Iterate for each List of occurrences of the same Ciphertext
     */
    for (List<Ciphertext> ciphertextIndices : ciphertextKey.values()) {
        int maxMatches = 0;
        uniqueMatch = false;

        /*
         * Now iterate for each occurrence of the current Ciphertext
         * character
         */
        for (Ciphertext ciphertextIndice : ciphertextIndices) {
            int matches = 0;

            /*
             * The predicate used here just returns the Plaintext character
             * that corresponds to the given Ciphertext character. Using the
             * Predicate to find the Plaintext Id is about 10 times less
             * performant than using List.get() on the CiphertextId
             */
            plaintext = (Plaintext) CollectionUtils.find(solution.getPlaintextCharacters(),
                    new PlaintextPredicate(ciphertextIndice));

            /*
             * Iterate through the same list of Ciphertext characters,
             * checking if the corresponding Plaintext character has any
             * matches
             */
            for (Ciphertext otherCiphertext : ciphertextIndices) {

                /*
                 * The predicate used here just returns the Plaintext
                 * character that corresponds to the given Ciphertext
                 * character. Using the Predicate to find the Plaintext Id
                 * is about 10 times less performant than using List.get()
                 * on the CiphertextId
                 */
                otherPlaintext = (Plaintext) CollectionUtils.find(solution.getPlaintextCharacters(),
                        new PlaintextPredicate(otherCiphertext));

                /*
                 * Check if there are any Plaintext characters which are the
                 * same for this Ciphertext character. If so, then it is
                 * more likely that we have found the correct Plaintext
                 * character. Remember to ignore case here since proper
                 * nouns can have capital letters in the database
                 */
                if (!plaintext.equals(otherPlaintext)
                        && plaintext.getValue().equalsIgnoreCase(otherPlaintext.getValue())) {
                    matches++;
                    uniqueMatch = true;
                }
            }

            /*
             * We want to use the most optimistic number of Plaintext
             * character matches possible for the given Ciphertext character
             */
            if (matches > maxMatches) {
                maxMatches = matches;
            }
        }

        /*
         * Add the Plaintext matches on this Ciphertext character to the
         * overall confidence value, represented by total
         */
        total += maxMatches;

        /*
         * Increment the unique matches by converting a boolean to an int
         */
        totalUnique += (uniqueMatch ? 1 : 0);
    }
    solution.setTotalMatches(total);
    solution.setUniqueMatches(totalUnique);

    log.info("Solution " + solution.getId() + " has a confidence level of: " + total);

    return total;
}

From source file:edu.kit.sharing.test.SharingTestService.java

@Override
public IEntityWrapper<? extends IDefaultReferenceId> createReference(String pDomain, String pDomainUniqueId,
        String pReferenceGroupId, String pRole, String pGroupId, HttpContext hc) {
    SecurableResourceId resId = new SecurableResourceId(pDomain, pDomainUniqueId);

    CollectionUtils.find(references, new Predicate() {

        @Override/*from   ww w . ja v  a  2 s  .c  o  m*/
        public boolean evaluate(Object o) {
            return false;
        }
    });

    ReferenceId rid = new ReferenceId(resId, new GroupId(pReferenceGroupId));
    references.add(rid);

    return new ReferenceIdWrapper(rid);
}

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

private UserData findUserById(final Long id) {
    return (UserData) CollectionUtils.find(users, new Predicate() {

        @Override//from   w ww . j av a2 s .c o m
        public boolean evaluate(Object o) {
            return Objects.equals(((UserData) o).getUserId(), id);
        }
    });
}

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

public DegreeTeachingService getDegreeTeachingServiceByShiftAndProfessorship(final Shift shift,
        final Professorship professorship) {
    return (DegreeTeachingService) CollectionUtils.find(getDegreeTeachingServices(), new Predicate() {
        @Override/*from  ww  w  .  jav  a2  s . c  om*/
        public boolean evaluate(Object arg0) {
            DegreeTeachingService degreeTeachingService = (DegreeTeachingService) arg0;
            return (degreeTeachingService.getShift() == shift)
                    && (degreeTeachingService.getProfessorship() == professorship);
        }
    });
}