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

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

Introduction

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

Prototype

public static boolean exists(Collection collection, Predicate predicate) 

Source Link

Document

Answers true if a predicate is true for at least one element of a collection.

Usage

From source file:com.exxonmobile.ace.hybris.test.job.AccountManagerJob.java

public void acctMgrApproveOrRejectAction(final String orderCode, final boolean approve) {
    final String decision = approve ? APPROVE.toString() : REJECT.toString();
    LOG.info(String.format("Attempting to apply decision: %s  on order: %s", orderCode, decision));

    final EmployeeModel employee = getUserService().getUserForUID(ACCOUNTMANAGERUID, EmployeeModel.class);

    final Collection<WorkflowActionModel> workFlowActionModelList = new ArrayList<WorkflowActionModel>(
            getB2bWorkflowIntegrationService().getWorkflowActionsForUser(employee));

    LOG.debug(ACCOUNTMANAGERUID + " has actions count:" + workFlowActionModelList.size());
    CollectionUtils.filter(workFlowActionModelList, new Predicate() {
        @Override//  ww  w  .j  a  va2  s . c  o  m
        public boolean evaluate(final Object object) {
            final WorkflowActionModel workflowActionModel = (WorkflowActionModel) object;

            if (APPROVAL.name().equals(workflowActionModel.getQualifier())) {
                return CollectionUtils.exists(workflowActionModel.getAttachmentItems(), new Predicate() {
                    @Override
                    public boolean evaluate(final Object object) {
                        if (object instanceof OrderModel) {
                            LOG.debug("This approval action is for order " + ((OrderModel) object).getCode()
                                    + " vs " + orderCode);
                            return (orderCode.equals(((OrderModel) object).getCode()));
                        }
                        return false;
                    }
                });
            } else {
                return false;
            }
        }
    });

    LOG.debug(String.format("Employee %s has %s actions to %s for this order %s", employee.getUid(),
            Integer.toString(workFlowActionModelList.size()), decision, orderCode));

    for (final WorkflowActionModel workflowActionModel : workFlowActionModelList) {
        getB2bWorkflowIntegrationService().decideAction(workflowActionModel, decision);
        LOG.debug("Decided for ActionCode" + workflowActionModel.getCode() + " to " + decision);
    }
}

From source file:gov.nih.nci.caarray.domain.project.ExperimentContact.java

/**
 * Returns whether this contact is the PI for the experiment (based on
 * whether he has the appropriate role).
 *
 * @return whether this contact is the PI for the experiment
 *///w  ww. ja  va2s . c o  m
@Transient
public boolean isPrimaryInvestigator() {
    return CollectionUtils.exists(roles, new RolePredicate(PI_ROLE));
}

From source file:gov.nih.nci.caarray.domain.project.ExperimentContact.java

/**
 * Returns whether this contact is the main POC for the experiment (based on
 * whether he has the appropriate role).
 *
 * @return whether this contact is the main POC for the experiment
 *///from  ww  w .j  a  v  a 2  s. c  om
@Transient
public boolean isMainPointOfContact() {
    return CollectionUtils.exists(roles, new RolePredicate(MAIN_POC_ROLE));
}

From source file:com.cyberway.issue.crawler.extractor.JerichoExtractorHTMLTest.java

/**
 * Test a GET FORM ACTION extraction//from  ww  w.j a v a  2s.  co  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/* ww w.  j  a  v a  2  s  . c  o  m*/
        public boolean evaluate(Object object) {
            ShippingItem shippingItem = (ShippingItem) object;
            return shippingItem != null && BooleanUtils.isTrue(shippingItem.getIsDelivery());
        }
    });
}

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 {/*from  w  ww  . j  a va  2s.  c o  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)
 *//*www .j  a v a2s  . c  o  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:AIR.Common.Web.BrowserParser.java

/**
 *  The general OS platform being used (e.x., WINDOWS)
 *  @return BrowserOS/*from  w w  w. j  a v a  2 s . co 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.sf.wickedshell.facade.descriptor.XMLShellDescriptor.java

/**
 * @see net.sf.wickedshell.facade.descriptor.IShellDescriptor#isCurrentOSSupported()
 *//*ww  w  . ja  va  2 s. co  m*/
public boolean isCurrentOSSupported() {
    final String operatingSystem = System.getProperty(ShellID.OS_KEY);
    return CollectionUtils.exists(Arrays.asList(getOperatingSystems()), new Predicate() {
        /**
         * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
         */
        public boolean evaluate(Object object) {
            String supportingOperatingSystem = (String) object;
            return supportingOperatingSystem.equalsIgnoreCase(operatingSystem);
        }
    });
}

From source file:com.cyberway.issue.crawler.extractor.JerichoExtractorHTMLTest.java

/**
 * Test a POST FORM ACTION being properly ignored 
 * /*w w w.jav a 2s  .c o m*/
 * @throws URIException
 */
public void testFormsLinkIgnorePost() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.org"));
    CharSequence cs = "<form name=\"testform\" method=\"POST\" 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;
        }
    }));
}