Example usage for org.apache.commons.collections Predicate Predicate

List of usage examples for org.apache.commons.collections Predicate Predicate

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:module.siadap.domain.SiadapEvaluationUniverse.java

public List<ObjectiveEvaluation> getObjectiveEvaluations() {
    return getEvaluations(ObjectiveEvaluation.class, new Predicate() {

        @Override//w  ww.j a v a 2s . c om
        public boolean evaluate(Object arg0) {
            ObjectiveEvaluation objective = (ObjectiveEvaluation) arg0;
            return objective.isValidForVersion(getCurrentObjectiveVersion());
        }

    }, ObjectiveEvaluation.COMPARATOR_BY_OLDEST_DATE);

}

From source file:edu.kit.dama.mdm.base.DigitalObjectTransition.java

/**
 * Add the single object-view input mapping.
 *
 * @param pObject The object part of the mapping.
 * @param pView The view part of the mapping.
 *///from   w ww  .  ja v a 2s  . co  m
public void addInputMapping(final DigitalObject pObject, String pView) {
    if (pObject == null || pObject.getDigitalObjectId() == null) {
        return;
    }
    ObjectViewMapping existing = (ObjectViewMapping) CollectionUtils.find(inputObjectViewMappings,
            new Predicate() {

                @Override
                public boolean evaluate(Object o) {
                    return pObject.getDigitalObjectId()
                            .equals(((ObjectViewMapping) o).getDigitalObject().getDigitalObjectId());
                }
            });
    if (existing == null) {
        inputObjectViewMappings.add(new ObjectViewMapping(pObject, pView));
    }
}

From source file:module.mailtracking.domain.MailTracking.java

public java.util.List<CorrespondenceEntry> simpleSearch(CorrespondenceType type, final String key,
        boolean onlyActiveEntries) {
    java.util.List<CorrespondenceEntry> entries = new java.util.ArrayList<CorrespondenceEntry>();

    if (Strings.isNullOrEmpty(key)) {
        return entries;
    }//from  w ww  . ja va  2s  .co  m

    CollectionUtils.select(this.getAbleToViewEntries(type, onlyActiveEntries), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return Helper.matchGivenSearchToken((CorrespondenceEntry) arg0, key);
        }

    }, entries);

    return entries;
}

From source file:com.projity.configuration.FieldDictionary.java

/**
 * Extract fields that have extra status, and also optionally that have validOnOjbectCreate status
 *//*  w w  w.ja v  a  2  s  .co  m*/
public static LinkedList extractExtraFields(Collection from, final boolean mustBeValidOnObjectCreate) {
    LinkedList result = new LinkedList();
    CollectionUtils.select(from, new Predicate() {
        public boolean evaluate(Object arg0) {
            Field f = (Field) arg0;
            return f.isExtra() && (!mustBeValidOnObjectCreate || f.isValidOnObjectCreate());
        }
    }, result);
    return result;
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.StudySiteService.java

@SuppressWarnings({ "unchecked" })
public List<List<StudySite>> refreshStudySitesForSites(final List<Site> sites) {
    if (sites == null) {
        throw new IllegalArgumentException(SITE_IS_NULL);
    }/*from   w ww  .j  a  va  2s.c  om*/

    List<List<StudySite>> refreshed = new ArrayList<List<StudySite>>();

    final Map<String, List<Study>> studies = buildProvidedStudyMap();
    final List<List<StudySite>> allProvided = studySiteConsumer.refreshStudies(sites);

    for (int i = 0; i < sites.size(); i++) {
        final Site site = sites.get(i);
        List<StudySite> provided = allProvided.get(i);
        if (provided == null) {
            provided = EMPTY_LIST;
        }

        Collection<StudySite> qualifying = CollectionUtils.select(provided, new Predicate() {
            public boolean evaluate(Object o) {
                StudySite potential = (StudySite) o;

                // Verify Provider for existing Site is equal to StudySite Provider
                if (site.getProvider() == null || !site.getProvider().equals(potential.getProvider())) {
                    return false;
                }

                // Verify Provider for existing Study is equal to StudySite Provider (And Study Exists)
                List<Study> providerSpecific = studies.get(potential.getProvider());
                if (providerSpecific == null || CollectionUtilsPlus.matching(asList(potential.getStudy()),
                        providerSpecific, StudySecondaryIdentifierMatcher.instance()).size() == 0) {
                    return false;
                }

                // Verify new study site
                Study study = (Study) CollectionUtilsPlus.matching(asList(potential.getStudy()),
                        providerSpecific, StudySecondaryIdentifierMatcher.instance()).iterator().next();
                if (StudySite.findStudySite(study, site) != null) {
                    return false;
                }

                return true;
            }
        });

        logger.debug("Found " + qualifying.size() + " new study sites from the provider.");
        for (StudySite u : qualifying) {
            logger.debug("- " + u);
        }

        // StudySites returned from provider are proxied by CGLIB.  This causes problems when saving,
        // so we want to create a fresh StudySite instance. Also, we want to populate the site with a
        // valid Site from SiteService.
        Collection<StudySite> enhanced = CollectionUtils.collect(qualifying, new Transformer() {
            public Object transform(Object o) {
                StudySite s = (StudySite) o;

                List<Study> providerSpecific = studies.get(s.getProvider());
                Study study = (Study) CollectionUtilsPlus.matching(asList(s.getStudy()), providerSpecific,
                        StudySecondaryIdentifierMatcher.instance()).iterator().next();

                StudySite e = new StudySite(study, site);
                e.getStudy().addStudySite(e);
                e.getSite().addStudySite(e);
                e.setProvider(s.getProvider());
                e.setLastRefresh(s.getLastRefresh());
                return e;
            }
        });

        for (StudySite s : enhanced) {
            studySiteDao.save(s);
        }

        refreshed.add(site.getStudySites());
    }

    return refreshed;
}

From source file:gov.nih.nci.caarray.domain.hybridization.Hybridization.java

/**
 * Return the factor value for the factor with given name in this hybridization. 
 * If there is none, return null.// w ww  .  jav  a 2  s.  c om
 * @param factorName name of factor for which to find a value.
 * @return the factor value for factor with given name or null if there is none.
 */
public AbstractFactorValue getFactorValue(final String factorName) {
    return (AbstractFactorValue) CollectionUtils.find(getFactorValues(), new Predicate() {
        public boolean evaluate(Object o) {
            AbstractFactorValue fv = (AbstractFactorValue) o;
            return factorName.equals(fv.getFactor().getName());
        }
    });
}

From source file:module.mailtracking.domain.CorrespondenceEntry.java

public static java.util.List<CorrespondenceEntry> getActiveEntries() {
    java.util.Collection<CorrespondenceEntry> allEntries = Bennu.getInstance().getCorrespondenceEntriesSet();
    java.util.List<CorrespondenceEntry> activeEntries = new java.util.ArrayList<CorrespondenceEntry>();

    CollectionUtils.select(allEntries, new Predicate() {

        @Override//from ww  w. j av  a 2 s  .c  o  m
        public boolean evaluate(Object arg0) {
            return CorrespondenceEntryState.ACTIVE.equals(((CorrespondenceEntry) arg0).getState());
        }

    }, activeEntries);

    return activeEntries;
}

From source file:de.hybris.platform.b2b.testframework.ModelFactory.java

public AddressModel createAddressByUniqueEmail(final String email, final ItemModel owner,
        final AddressModel addressData) {
    Assert.assertNotNull("Owner must be given for the address, it can not be null!", owner);
    Assert.assertNotNull("Email must be given for the address, since it is used as uid for it.", email);
    Assert.assertNotNull("Address data can contain no values but must be at least initialized!", addressData);
    AddressModel address = null;//from www . j  ava 2  s.co m
    try {
        final Collection<AddressModel> addresses = addressService.getAddressesForOwner(owner);
        if (CollectionUtils.isNotEmpty(addresses)) {
            address = (AddressModel) CollectionUtils.find(addresses, new Predicate() {
                @Override
                public boolean evaluate(final Object arg0) {
                    final AddressModel a = (AddressModel) arg0;
                    return StringUtils.equals(a.getEmail(), email);
                }
            });
        }
    } catch (final Exception e) {
        // nothing found,create a new one
    }
    if (address == null) {
        address = new AddressModel();
        address.setOwner(owner);
        address.setEmail(email);
        address.setFirstname(addressData.getFirstname());
        address.setLastname(addressData.getLastname());
        address.setStreetname(addressData.getStreetname());
        address.setStreetnumber(addressData.getStreetnumber());
        address.setPostalcode(addressData.getPostalcode());
        address.setTown(addressData.getTown());
        address.setPhone1(addressData.getPhone1());
        modelService.save(address);
    }
    return address;
}

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

public List<DegreeProjectTutorialService> getDegreeProjectTutorialServices() {
    return (List<DegreeProjectTutorialService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override//from   w w w.  j ava  2 s. c o  m
        public boolean evaluate(Object arg0) {
            return arg0 instanceof DegreeProjectTutorialService;
        }
    });
}

From source file:info.magnolia.test.mock.MockContent.java

@Override
public Collection<Content> getChildren(final ContentFilter filter, final String namePattern,
        Comparator<Content> orderCriteria) {
    // copy//from  w w w .  j  a v  a 2  s. c  o m
    final Collection<MockNode> children = ((MockNode) node).getChildren().values();
    final Collection<Content> contentChildren = new ArrayList<Content>();
    for (MockNode current : children) {
        contentChildren.add(wrapAsContent(current));
    }

    final Predicate filterPredicate = new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return filter.accept((Content) object);
        }
    };

    CollectionUtils.filter(contentChildren, filterPredicate);

    if (namePattern != null) {
        CollectionUtils.filter(contentChildren, new NamePatternFilter(namePattern));
    }

    return contentChildren;
}