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:com.cyberway.issue.crawler.extractor.JerichoExtractorHTMLTest.java

/**
 * Test a GET FORM ACTION extraction//from   w ww  .  j  ava 2  s.  c o m
 * 
 * @throws URIException
 */
public void testFormsLinkGet() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.org"));
    CharSequence cs = "<form name=\"testform\" method=\"GET\" action=\"redirect_me?form=true\"> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"checked[]\" VALUE=\"1\" CHECKED> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"unchecked[]\" VALUE=\"1\"> " + "  <select name=\"selectBox\">"
            + "    <option value=\"selectedOption\" selected>option1</option>"
            + "    <option value=\"nonselectedOption\">option2</option>" + "  </select>"
            + "  <input type=\"submit\" name=\"test\" value=\"Go\">" + "</form>";
    this.extractor.extract(curi, cs);
    curi.getOutLinks();
    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((Link) object).getDestination().toString().indexOf(
                    "/redirect_me?form=true&checked[]=1&unchecked[]=&selectBox=selectedOption&test=Go") >= 0;
        }
    }));
}

From source file:net.shopxx.entity.Shipping.java

@Transient
public boolean getIsDelivery() {
    return CollectionUtils.exists(getShippingItems(), new Predicate() {
        @Override/*from  w  w  w . ja v a  2 s .  c  om*/
        public boolean evaluate(Object object) {
            ShippingItem shippingItem = (ShippingItem) object;
            return shippingItem != null && BooleanUtils.isTrue(shippingItem.getIsDelivery());
        }
    });
}

From source file:com.vmware.appfactory.application.controller.AppApiController.java

/**
 * Get a list of all the applications, in our own JSON format.
 *
 * @param category Optional, to return apps from that category only.
 * @param sort Optional, to sort the results.
 * @param request - Servlet request.  Set by spring.
 * @param response - Servlet response.  Set by spring.
 * @throws IOException - if the etag headers could not be written
 * @return//from  ww  w  . j a v  a 2s  .  c  om
 */
@ResponseBody
@RequestMapping(value = "/apps", method = RequestMethod.GET)
@Nullable
public List<Application> getAllApplications(@RequestParam(required = false) final String category,
        @RequestParam(required = false) boolean sort, @Nonnull HttpServletRequest request,
        @Nonnull HttpServletResponse response) throws IOException {

    /* Get apps */
    ApplicationDao appDao = _daoFactory.getApplicationDao();

    // the e-tag for the Apps table needs to be based on not only the apps
    // db table itself, but also:
    //  - the feeds table
    //  - the fileshares table
    // The reason is that the Application object has a dataSourceName property,
    // so if the name of a feed or fileshare changed, we need a new e-tag.
    if (checkModified(request, response, null, appDao, _daoFactory.getFeedDao(),
            _daoFactory.getFileShareDao())) {
        // shortcut exit - no further processing necessary
        return null;
    }

    final List<Application> apps = appDao.findAllIncluded();

    /**
     * TODO: if we continue to need to filter on categories,
     * just do a proper select here.
     */
    /* Filter on category */
    if (StringUtils.isNotEmpty(category)) {
        CollectionUtils.filter(apps, new Predicate() {
            @Override
            public boolean evaluate(Object obj) {
                Application app = (Application) obj;
                return (app.getCategories().isEmpty() && category.equals(NO_CATEGORY_REQUEST))
                        || (app.belongsToCategory(category));
            }
        });
    }

    if (sort) {
        Collections.sort(apps);
    }

    return apps;
}

From source file:com.perceptive.epm.perkolcentral.bl.ImageNowLicenseBL.java

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, readOnly = true, rollbackFor = ExceptionWrapper.class)
public ArrayList<Imagenowlicenses> getLicensesToBeProvided() throws ExceptionWrapper {
    try {//ww  w.  ja  va2s . c o  m
        ArrayList<Imagenowlicenses> imagenowlicensesArrayList = new ArrayList<Imagenowlicenses>(
                imageNowLicenseDataAccessor.getAllImageNowLicenses().values());
        CollectionUtils.filter(imagenowlicensesArrayList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return !((Imagenowlicenses) o).isIsProvided(); //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        return imagenowlicensesArrayList;
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

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

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

    java.util.List<CorrespondenceEntry> baseEntries = onlyActiveEntries ? getActiveEntries(type)
            : getAnyStateEntries(type);/*from   ww w  . ja v a  2 s  .c o m*/

    CollectionUtils.select(baseEntries, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((CorrespondenceEntry) arg0).isUserAbleToView(Authenticate.getUser());
        }

    }, entries);

    return entries;
}

From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java

@TriggersRemove(cacheName = { "EmployeeCache", "GroupCache",
        "EmployeeKeyedByGroupCache" }, when = When.AFTER_METHOD_INVOCATION, removeAll = true, keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class)
public void updateEmployeeGroupMap(String employeeId, ArrayList<String> groupIds) throws ExceptionWrapper {
    try {//ww  w  . j  a  va  2s.  co  m
        ArrayList<Employeegroupmap> employeegroupmapArrayList = employeeDataAccessor
                .getEmployeegroupmapByEmployeeID(employeeId);
        for (Object item : employeegroupmapArrayList) {
            final Employeegroupmap employeegroupmap = (Employeegroupmap) item;
            if (!CollectionUtils.exists(groupIds, new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return ((String) o).trim()
                            .equalsIgnoreCase(employeegroupmap.getGroups().getGroupId().toString());
                }
            })) {
                employeeDataAccessor.deleteEmployeeGroupMap(employeegroupmap);
            }
        }
        for (Object item : groupIds) {
            final String groupId = (String) item;
            if (groupId.trim().equalsIgnoreCase(""))
                continue;
            if (!CollectionUtils.exists(employeegroupmapArrayList, new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return ((Employeegroupmap) o).getGroups().getGroupId().toString()
                            .equalsIgnoreCase(groupId.trim());
                }
            })) {
                employeeDataAccessor.addEmployeeGroupMap(employeeId, groupId);
            }
        }

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:net.sf.wickedshell.facade.descriptor.XMLShellDescriptor.java

/**
 * @see net.sf.wickedshell.facade.descriptor.IShellDescriptor#isAllowedForBatchList(java.io.File)
 *///from   w ww .j  av a  2s  .  co m
public boolean isAllowedForBatchList(final File file) {
    return CollectionUtils.exists(Arrays.asList(getExecutableFiles(true)), new Predicate() {
        /**
         * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
         */
        public boolean evaluate(Object object) {
            IExecutableFile executableFile = (IExecutableFile) object;
            return executableFile.isBatchFile() && file.getName().endsWith(executableFile.getExtension());
        }
    });
}

From source file:com.tlabs.eve.api.character.TrainingQueue.java

public final List<SkillInTraining> list(boolean activeOnly) {
    if (!activeOnly) {
        return this.list();
    }/*from w  w w.  j ava  2  s  .c om*/

    final long now = System.currentTimeMillis();
    final List<SkillInTraining> r = new ArrayList<SkillInTraining>(this.training.size());
    CollectionUtils.filter(r, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            SkillInTraining t = (SkillInTraining) object;
            return t.getEndTime() > now;
        }
    });
    return r;
}

From source file:AIR.Common.Web.BrowserParser.java

/**
 *  The general OS platform being used (e.x., WINDOWS)
 *  @return BrowserOS/*from   w  w  w  . j a va2  s  .  c  o m*/
 */
public BrowserOS getOsName() {
    if (_userAgent.contains(" CrOS ")) {
        return BrowserOS.Chrome;
    }

    if (_userAgent.contains("Android")) {
        return BrowserOS.Android;
    }
    if (CollectionUtils.exists(_platformIOS, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return _userAgent.contains((String) object);
        }
    })) {
        return BrowserOS.IOS; // NOTE: needs to be before OS X
    }
    if (CollectionUtils.exists(_platformOSX, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return _userAgent.contains((String) object);
        }
    })) {
        return BrowserOS.OSX;
    }
    if (CollectionUtils.exists(_platformWindows, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return _userAgent.contains((String) object);
        }
    })) {
        return BrowserOS.Windows;
    }
    if (CollectionUtils.exists(_platformLinux, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return _userAgent.contains((String) object);
        }
    })) {
        return BrowserOS.Linux;
    }

    return BrowserOS.Unknown;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.CandidacyProcess.java

public List<IndividualCandidacyProcess> getChildsWithMissingShifts() {
    List<IndividualCandidacyProcess> childs = new ArrayList<IndividualCandidacyProcess>();

    CollectionUtils.select(getChildProcessesSet(), new Predicate() {

        @Override//  w  ww. ja  v  a 2s.  com
        public boolean evaluate(Object arg0) {
            boolean hasNotMissingShifts = true;
            IndividualCandidacyProcess process = (IndividualCandidacyProcess) arg0;
            for (Attends attends : process.getCandidacy().getPersonalDetails().getPerson()
                    .getCurrentAttends()) {
                if (!attends.hasAllShiftEnrolments()) {
                    hasNotMissingShifts = false;
                }
            }
            return !process.isCandidacyCancelled() && !hasNotMissingShifts;
        }

    }, childs);

    return childs;
}