List of usage examples for org.apache.commons.collections CollectionUtils exists
public static boolean exists(Collection collection, Predicate predicate)
From source file:net.sf.wickedshell.facade.descriptor.XMLShellDescriptor.java
/** * @see net.sf.wickedshell.facade.descriptor.IShellDescriptor#isExecutable(java.io.File) *///from ww w. ja v a 2 s . co m public boolean isExecutable(final File file) { return CollectionUtils.exists(Arrays.asList(getExecutableFiles(false)), new Predicate() { /** * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object) */ public boolean evaluate(Object object) { IExecutableFile executableFile = (IExecutableFile) object; return file.getName().endsWith(executableFile.getExtension()); } }); }
From source file:com.perceptive.epm.perkolcentral.action.ajax.EmployeeDetailsAction.java
public String executeGetAllEmployees() throws ExceptionWrapper { try {//from w w w . ja v a 2s . com Soundex sndx = new Soundex(); DoubleMetaphone doubleMetaphone = new DoubleMetaphone(); final StringEncoderComparator comparator1 = new StringEncoderComparator(doubleMetaphone); LoggingHelpUtil.printDebug("Page " + getPage() + " Rows " + getRows() + " Sorting Order " + getSord() + " Index Row :" + getSidx()); LoggingHelpUtil.printDebug("Search :" + searchField + " " + searchOper + " " + searchString); // Calcalate until rows ware selected int to = (rows * page); // Calculate the first row to read int from = to - rows; LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = new LinkedHashMap<Long, EmployeeBO>(); employeeLinkedHashMap = employeeBL.getAllEmployees(); ArrayList<EmployeeBO> allEmployees = new ArrayList<EmployeeBO>(employeeLinkedHashMap.values()); //Handle search if (searchOper != null && !searchOper.trim().equalsIgnoreCase("") && searchString != null && !searchString.trim().equalsIgnoreCase("")) { if (searchOper.trim().equalsIgnoreCase("eq")) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return ((EmployeeBO) o).getEmployeeName().equalsIgnoreCase(searchString.trim()); //To change body of implemented methods use File | Settings | File Templates. } }); } else if (searchOper.trim().equalsIgnoreCase("slk")) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (new StringEncoderComparator(new Soundex()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new Metaphone()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new RefinedSoundex()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0); //To change body of implemented methods use File | Settings | File Templates. } }); } else { //First check whether there is an exact match if (CollectionUtils.exists(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (((EmployeeBO) o).getEmployeeName().toLowerCase() .contains(searchString.trim().toLowerCase())); //To change body of implemented methods use File | Settings | File Templates. } })) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (((EmployeeBO) o).getEmployeeName().toLowerCase() .contains(searchString.trim().toLowerCase())); } }); } else { ArrayList<String> matchedEmployeeIds = employeeBL.getLuceneUtil() .getBestMatchEmployeeName(searchString.trim().toLowerCase()); allEmployees = new ArrayList<EmployeeBO>(); for (String id : matchedEmployeeIds) { allEmployees.add(employeeBL.getAllEmployees().get(Long.valueOf(id))); } } } /*{ CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { if (((EmployeeBO) o).getEmployeeName().toLowerCase().contains(searchString.trim().toLowerCase())) return true; else if(new StringEncoderComparator(new Soundex()).compare(((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare(((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0) { return true; } else { for (String empNameParts : ((EmployeeBO) o).getEmployeeName().trim().split(" ")) { if (new StringEncoderComparator(new Soundex()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 // || new StringEncoderComparator(new Metaphone()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 // || new StringEncoderComparator(new RefinedSoundex()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 ) { return true; } } return false; } } }); } */ } //// Handle Order By if (sidx != null && !sidx.equals("")) { Collections.sort(allEmployees, new Comparator<EmployeeBO>() { public int compare(EmployeeBO e1, EmployeeBO e2) { if (sidx.equalsIgnoreCase("employeeName")) return sord.equalsIgnoreCase("asc") ? e1.getEmployeeName().compareTo(e2.getEmployeeName()) : e2.getEmployeeName().compareTo(e1.getEmployeeName()); else if (sidx.equalsIgnoreCase("jobTitle")) return sord.equalsIgnoreCase("asc") ? e1.getJobTitle().compareTo(e2.getJobTitle()) : e2.getJobTitle().compareTo(e1.getJobTitle()); else if (sidx.equalsIgnoreCase("manager")) return sord.equalsIgnoreCase("asc") ? e1.getManager().compareTo(e2.getManager()) : e2.getManager().compareTo(e1.getManager()); else return sord.equalsIgnoreCase("asc") ? e1.getEmployeeName().compareTo(e2.getEmployeeName()) : e2.getEmployeeName().compareTo(e1.getEmployeeName()); } }); } // records = allEmployees.size(); total = (int) Math.ceil((double) records / (double) rows); gridModel = new ArrayList<EmployeeBO>(); to = to > records ? records : to; for (int iCounter = from; iCounter < to; iCounter++) { EmployeeBO employeeBO = allEmployees.get(iCounter); //new EmployeeBO((Employee) employeeLinkedHashMap.values().toArray()[iCounter]); gridModel.add(employeeBO); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } return SUCCESS; }
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 updateEmployeeLicenseMap(String employeeId, ArrayList<String> licenseIds) throws ExceptionWrapper { try {//from w w w .j ava2 s. co m ArrayList<Employeelicensemapping> employeelicensemappingArrayList = employeeDataAccessor .getEmployeeLicenseMapByEmployeeId(employeeId); for (Object item : employeelicensemappingArrayList) { final Employeelicensemapping employeelicensemapping = (Employeelicensemapping) item; if (!CollectionUtils.exists(licenseIds, new Predicate() { @Override public boolean evaluate(Object o) { return ((String) o).trim().equalsIgnoreCase( employeelicensemapping.getLicensemaster().getLicenseTypeId().toString()); } })) { employeeDataAccessor.deleteEmployeeLicenseMap(employeelicensemapping); } } for (Object item : licenseIds) { final String licenseTypeId = (String) item; if (licenseTypeId.trim().equalsIgnoreCase("")) continue; if (!CollectionUtils.exists(employeelicensemappingArrayList, new Predicate() { @Override public boolean evaluate(Object o) { return ((Employeelicensemapping) o).getLicensemaster().getLicenseTypeId().toString() .equalsIgnoreCase(licenseTypeId.trim()); } })) { employeeDataAccessor.addEmployeeLicenseMap(employeeId, licenseTypeId); } } } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:gov.nih.nci.firebird.service.task.MissingRoleTasksGenerator.java
private boolean containsInvestigatorRegistration(Set<AbstractProtocolRegistration> invitedRegistrations) { return CollectionUtils.exists(invitedRegistrations, PredicateUtils.instanceofPredicate(InvestigatorRegistration.class)); }
From source file:gov.nih.nci.firebird.service.task.MissingRoleTasksGenerator.java
private boolean containsSubInvestigatorRegistration(Set<AbstractProtocolRegistration> invitedRegistrations) { return CollectionUtils.exists(invitedRegistrations, PredicateUtils.instanceofPredicate(SubInvestigatorRegistration.class)); }
From source file:com.cyberway.issue.crawler.extractor.JerichoExtractorHTMLTest.java
/** * Test a POST FORM ACTION being found with non-default setting * // ww w.j a v a 2s. c om * @throws URIException * @throws ReflectionException * @throws MBeanException * @throws InvalidAttributeValueException * @throws AttributeNotFoundException */ public void testFormsLinkFindPost() throws URIException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { 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.setAttribute(new Attribute(ExtractorHTML.ATTR_EXTRACT_ONLY_FORM_GETS, false)); 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:com.iggroup.oss.restdoclet.plugin.mojo.RestDocumentationMojo.java
/** * Generates services from the documentation of controllers and * data-binders./*from w ww . j ava 2 s . c o m*/ * * @throws BeansNotFoundException if a bean with an identifier or Java type * can't be found. * @throws IOException if services can't be marshaled. * @throws JavadocNotFoundException if a controller's documentation can't be * found. * @throws JiBXException if a JiBX exception occurs. */ private void services() throws IOException, JavadocNotFoundException, JiBXException { LOG.info("Generating services"); DirectoryBuilder dirs = new DirectoryBuilder(baseDirectory, outputDirectory); int identifier = 1; List<Service> services = new ArrayList<Service>(); LOG.info("Looking for mappings"); HashMap<String, ArrayList<Method>> uriMethodMappings = new HashMap<String, ArrayList<Method>>(); HashMap<String, Controller> uriControllerMappings = new HashMap<String, Controller>(); HashMap<String, Collection<Uri>> multiUriMappings = new HashMap<String, Collection<Uri>>(); for (Controller controller : controllers) { LOG.info(new StringBuilder().append("- Controller ").append(controller.getType()).toString()); for (Method method : controller.getMethods()) { LOG.info(new StringBuilder().append("... for Method ").append(method.toString())); if (excludeMethod(method)) { continue; } // Collate multiple uris into one string key. Collection<Uri> uris = method.getUris(); if (!uris.isEmpty()) { String multiUri = ""; for (Uri uri : uris) { multiUri = multiUri + ", " + uri; } multiUriMappings.put(multiUri, uris); ArrayList<Method> methodList = uriMethodMappings.get(multiUri); if (methodList == null) { methodList = new ArrayList<Method>(); uriMethodMappings.put(multiUri, methodList); } methodList.add(method); uriControllerMappings.put(multiUri, controller); } } } LOG.info("Processing controllers..."); for (String uri : uriControllerMappings.keySet()) { LOG.info(new StringBuilder().append("Processing controllers for ").append(uri).toString()); Controller controller = uriControllerMappings.get(uri); LOG.info(new StringBuilder().append("Found controller ") .append(uriControllerMappings.get(uri).getType()).toString()); ArrayList<Method> matches = uriMethodMappings.get(uri); LOG.info(new StringBuilder().append("Found methods ").append(matches.toString()).append(" ") .append(matches.size()).toString()); Service service = new Service(identifier, multiUriMappings.get(uri), new Controller(controller.getType(), controller.getJavadoc(), matches)); services.add(service); service.assertValid(); JiBXUtils.marshallService(service, ServiceUtils.serviceFile(dirs, identifier)); identifier++; } LOG.info("Processing services..."); Services list = new Services(); for (Service service : services) { org.apache.commons.collections.Predicate predicate = new ControllerTypePredicate( service.getController().getType()); if (CollectionUtils.exists(list.getControllers(), predicate)) { ControllerSummary controller = (ControllerSummary) CollectionUtils.find(list.getControllers(), predicate); controller.addService(service); } else { ControllerSummary controller = new ControllerSummary(service.getController().getType(), service.getController().getJavadoc()); controller.addService(service); list.addController(controller); } } LOG.info("Marshalling services..."); list.assertValid(); JiBXUtils.marshallServices(list, ServiceUtils.servicesFile(dirs)); }
From source file:com.iggroup.oss.restdoclet.doclet.type.builder.MethodBuilder.java
/** * Initialises the REST-parameters of this method. * /*w ww. jav a 2s.c o m*/ * @param method method to initialise * @param methodDoc the method's Java documentation object. * @param baseUri the controller base uri */ private void initRestParams(Method method, final MethodDoc methodDoc, final String baseUri) { LOG.debug(method.getName()); ArrayList<RestParameter> restParams = new ArrayList<RestParameter>(); for (NameValuePair pair : new RequestMappingParamsParser( elementValue(methodDoc, RequestMapping.class, "params")).parse()) { final Predicate predicate = new ParameterNamePredicate(pair.getName()); if (!CollectionUtils.exists(method.getRequestParams(), predicate)) { LOG.debug(pair.getName() + " - " + pair.getValue()); restParams.add(new RestParameter(pair)); } } AnnotationValue urlAnnotation = elementValue(methodDoc, RequestMapping.class, "value"); if (urlAnnotation != null) { Boolean deprecatedMatch = false; String[] methodUris = parseValueAnnotation(urlAnnotation); String[] deprecatedURIs = DocTypeUtils.getDeprecatedURIs(methodDoc); for (final String uri : methodUris) { LOG.debug("uri:" + baseUri + uri); boolean deprecated = false; if (deprecatedURIs != null) { for (final String deprecatedUri : deprecatedURIs) { LOG.debug("deprecated:" + deprecatedUri); if (StringUtils.equals(deprecatedUri, uri)) { LOG.debug("=DEPRECATED"); deprecated = true; deprecatedMatch = true; break; } } } method.getUris().add(new Uri(baseUri + uri, deprecated)); } if (deprecatedURIs != null && !deprecatedMatch) { LOG.warn("Deprecated URI tag on method " + methodDoc.name() + " does not match any service URIs."); } } method.setRestParams(restParams); }
From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceTest.java
/** * @see http://gforge.nci.nih.gov/tracker/index.php?func=detail&aid=12306 */// w ww. j a va 2s. co m @Test public void testAddUserKeepsAnonUserInAnonGroup() throws CSTransactionException, CSObjectNotFoundException { final Predicate anonUserExists = new Predicate() { @Override public boolean evaluate(Object o) { return ((User) o).getLoginName().equals(SecurityUtils.ANONYMOUS_USERNAME); } }; final Group g = (Group) hibernateHelper.getCurrentSession().load(Group.class, SecurityUtils.findGroupByName(SecurityUtils.ANONYMOUS_GROUP).getGroupId()); assertTrue(CollectionUtils.exists(g.getUsers(), anonUserExists)); this.permissionsManagementService.addUsers(SecurityUtils.ANONYMOUS_GROUP, "biostatistician"); hibernateHelper.getCurrentSession().refresh(g); assertTrue(CollectionUtils.exists(g.getUsers(), anonUserExists)); }
From source file:com.cyberway.issue.crawler.extractor.ExtractorHTMLTest.java
/** * Test a particular <embed src=...> construct that was suspicious in * the No10GovUk crawl.//from w w w . ja v a2 s. com * * @throws URIException */ public void testEmbedSrc() throws URIException { CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.org")); // An example from http://www.records.pro.gov.uk/documents/prem/18/1/default.asp?PageId=62&qt=true CharSequence cs = "<embed src=\"/documents/prem/18/1/graphics/qtvr/" + "hall.mov\" width=\"320\" height=\"212\" controller=\"true\" " + "CORRECTION=\"FULL\" pluginspage=\"http://www.apple.com/" + "quicktime/download/\" /> "; this.extractor.extract(curi, cs); assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() { public boolean evaluate(Object object) { return ((Link) object).getDestination().toString() .indexOf("/documents/prem/18/1/graphics/qtvr/hall.mov") >= 0; } })); }