List of usage examples for org.apache.commons.collections.functors AndPredicate AndPredicate
public AndPredicate(Predicate predicate1, Predicate predicate2)
From source file:com.discursive.jccook.collections.predicate.PredicatedMapExample.java
public void start() { // Create the Predicates ValidTeamPredicate validTeam = new ValidTeamPredicate(); ValidCoachPredicate validCoach = new ValidCoachPredicate(); // Tie two Predicates together into an AndPredicate AndPredicate valuePredicate = new AndPredicate(validTeam, validCoach); // Decorate a HashMap with a predicate on the value teamMap = PredicatedMap.decorate(new HashMap(), null, valuePredicate); // Manufacture some teams Team redSox = new Team("Red Sox", new Coach("Patrick", "Moloney")); Team yankees = new Team("Yankees", new Coach("David", "McGarry")); Team dodgers = new Team("Dodgers", new Coach("Nick", "Taylor")); Team twins = new Team(null, new Coach("Patrick", "Moloney")); Team braves = new Team("Braves", null); // The follow put calls should work fine teamMap.put("RedSox", redSox); teamMap.put("Yankees", yankees); teamMap.put("Dodgers", dodgers); // This put should fail because the team name is null try {/*from w ww . j av a 2 s . com*/ teamMap.put("Twins", twins); } catch (IllegalArgumentException iae) { System.out.println("Twins put failed, as expected"); } // This put should fail because the coach is null try { teamMap.put("Braves", braves); } catch (IllegalArgumentException iae) { System.out.println("Braves put failed, as expected"); } }
From source file:net.shopxx.controller.admin.ParameterController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Parameter parameter, Long productCategoryId, RedirectAttributes redirectAttributes) { CollectionUtils.filter(parameter.getNames(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String name = (String) object; return StringUtils.isNotEmpty(name); }//from w ww. j a v a2s . c om })); parameter.setProductCategory(productCategoryService.find(productCategoryId)); if (!isValid(parameter, BaseEntity.Save.class)) { return ERROR_VIEW; } parameterService.save(parameter); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:net.shopxx.controller.admin.SpecificationController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Specification specification, Long productCategoryId, RedirectAttributes redirectAttributes) { CollectionUtils.filter(specification.getOptions(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String option = (String) object; return StringUtils.isNotEmpty(option); }//from w w w . j a v a 2 s.com })); specification.setProductCategory(productCategoryService.find(productCategoryId)); if (!isValid(specification, BaseEntity.Save.class)) { return ERROR_VIEW; } specificationService.save(specification); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:net.shopxx.controller.admin.ParameterController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Parameter parameter, RedirectAttributes redirectAttributes) { CollectionUtils.filter(parameter.getNames(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String name = (String) object; return StringUtils.isNotEmpty(name); }/*from ww w . j av a2 s. c om*/ })); if (!isValid(parameter, BaseEntity.Update.class)) { return ERROR_VIEW; } parameterService.update(parameter, "productCategory"); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:net.shopxx.controller.admin.SpecificationController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Specification specification, RedirectAttributes redirectAttributes) { CollectionUtils.filter(specification.getOptions(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String option = (String) object; return StringUtils.isNotEmpty(option); }//w ww . ja v a2 s . c om })); if (!isValid(specification)) { return ERROR_VIEW; } specificationService.update(specification, "productCategory"); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:lt.kape1395.jenkins.ditz.DitzPublisherAction.java
/** * Used from UI./*from w w w .j a va2 s . c o m*/ * @param release Release to get issues for. * @return Issues. */ @SuppressWarnings("rawtypes") public Collection getActiveReleaseIssues(Release release) { return CollectionUtils.select(getProject().getIssues(), new AndPredicate(new IssueInReleasePredicate(release), new IssueActivePredicate())); }
From source file:com.all.client.util.PredicateUtil.java
public static Predicate mergeAndPredicate(List<Predicate> predicates) { if (predicates.size() > 1) { Predicate andPredicate = new AndPredicate(predicates.get(0), predicates.get(1)); for (int i = 2; i < predicates.size(); i++) { andPredicate = new AndPredicate(andPredicate, predicates.get(i)); }//w ww. j a v a2 s. c o m return andPredicate; } else { return predicates.get(0); } }
From source file:gov.nih.nci.caarray.dao.ProjectDaoTest.java
@Test public void testOwnerPermissions() throws Exception { CaArrayUsernameHolder.setUser(STANDARD_USER); Transaction tx = this.hibernateHelper.beginTransaction(); saveSupportingObjects();/*from w w w.j ava 2 s.com*/ daoObject.save(DUMMY_PROJECT_1); tx.commit(); tx = this.hibernateHelper.beginTransaction(); Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId()); assertTrue(SecurityUtils.isOwner(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canWrite(DUMMY_SOURCE, CaArrayUsernameHolder.getCsmUser())); assertNotNull(p.getPublicProfile()); assertEquals(2, p.getFiles().size()); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_1.getId())); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_2.getId())); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_DATA_FILE.getId())); List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); assertTrue(SecurityUtils.canRead(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canWrite(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canFullRead(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canFullWrite(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canModifyPermissions(p, CaArrayUsernameHolder.getCsmUser())); }
From source file:gov.nih.nci.caarray.dao.ProjectDaoTest.java
@Test public void testInitialProjectPermissions() { // create project Transaction tx = this.hibernateHelper.beginTransaction(); saveSupportingObjects();// w w w. j a v a 2s .c o m this.hibernateHelper.getCurrentSession().save(DUMMY_PROJECT_1); this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_1); this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_2); tx.commit(); // check initial settings.. drafts should be not visible tx = this.hibernateHelper.beginTransaction(); final Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId()); List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertEquals(8, list.size()); // expect the user-only ones only assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); p.getPublicProfile().setSecurityLevel(SecurityLevel.VISIBLE); tx.commit(); // check that after changing to visible, the role is reflected. tx = this.hibernateHelper.beginTransaction(); list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertEquals(9, list.size()); // expect the user-only ones and the anonymous access one assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); tx.commit(); }
From source file:nl.strohalm.cyclos.services.accounts.guarantees.GuaranteeServiceImpl.java
@SuppressWarnings("unchecked") private Collection<? extends MemberGroup> filterMemberGroups(final Predicate predicate, Collection<? extends Group> groups) { Predicate predicateToApply = predicate; if (groups == null) { // search for not removed member and broker groups final GroupQuery query = new GroupQuery(); query.setStatus(Group.Status.NORMAL); query.setNatures(Group.Nature.MEMBER, Group.Nature.BROKER); groups = groupService.search(query); } else if (groups.isEmpty()) { // if the group list is empty then return the same (empty) list return (Collection<? extends MemberGroup>) groups; } else { // it creates a predicate to filter not removed member and broker groups final Predicate memberGroupPredicate = new Predicate() { @Override/*from www.java 2 s. c o m*/ public boolean evaluate(final Object object) { final Group grp = (Group) object; return Group.Status.NORMAL == grp.getStatus() && (Group.Nature.MEMBER == grp.getNature() || Group.Nature.BROKER == grp.getNature()); } }; predicateToApply = predicate == null ? memberGroupPredicate : new AndPredicate(memberGroupPredicate, predicate); } CollectionUtils.filter(groups, predicateToApply); return (Collection<? extends MemberGroup>) groups; }