List of usage examples for org.apache.commons.collections CollectionUtils filter
public static void filter(Collection collection, Predicate predicate)
From source file:de.hybris.platform.b2bacceleratorfacades.company.populators.B2BUserPopulator.java
protected void populateRoles(final B2BCustomerModel source, final UserData target) { final List<String> roles = new ArrayList<String>(); final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(source.getGroups()); CollectionUtils.filter(roleModels, PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class))); CollectionUtils.filter(roleModels,/*from w w w . j a v a 2 s. c om*/ PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUserGroupModel.class))); for (final PrincipalGroupModel role : roleModels) { // only display allowed usergroups if (getB2BUserGroupsLookUpStrategy().getUserGroups().contains(role.getUid())) { roles.add(role.getUid()); } } target.setRoles(roles); }
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); }//from w w w .j ava 2 s.co m })); if (!isValid(specification)) { return ERROR_VIEW; } specificationService.update(specification, "productCategory"); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java
@Cacheable(cacheName = "EmployeeKeyedByGroupCache", keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false"))) @Transactional(propagation = Propagation.REQUIRED, readOnly = true, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public LinkedHashMap<Integer, ArrayList<EmployeeBO>> getAllEmployeesKeyedByGroupId() throws ExceptionWrapper { LinkedHashMap<Integer, ArrayList<EmployeeBO>> employeeBOLinkedHashMap = new LinkedHashMap<Integer, ArrayList<EmployeeBO>>(); Collection<EmployeeBO> employeeBOCollection = this.getAllEmployees().values(); try {//from www . ja v a2s. co m for (Object item : groupsBL.getAllGroups().values()) { final GroupBO groupBO = (GroupBO) item; ArrayList<EmployeeBO> employeeBOArrayList = new ArrayList<EmployeeBO>(employeeBOCollection); CollectionUtils.filter(employeeBOArrayList, new Predicate() { @Override public boolean evaluate(Object o) { return CollectionUtils.exists(((EmployeeBO) o).getGroups(), new Predicate() { @Override public boolean evaluate(Object o) { return ((GroupBO) o).getGroupId().equalsIgnoreCase(groupBO.getGroupId()); } }); } }); employeeBOLinkedHashMap.put(Integer.valueOf(groupBO.getGroupId()), employeeBOArrayList); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } return employeeBOLinkedHashMap; }
From source file:ml.shifu.shifu.actor.worker.DataFilterWorker.java
/** * Filter the data - it uses @dataPurifier to filter data * * @param inputDataList - input data to filter *//*from w ww . ja va 2s .co m*/ private void purifyData(List<String> inputDataList) { log.info("starting to filter data ... "); CollectionUtils.filter(inputDataList, new Predicate() { @Override public boolean evaluate(Object object) { String inputData = (String) object; return dataPurifier.isFilter(inputData); } }); log.info("there are {} records after filter.", inputDataList.size()); }
From source file:com.qcadoo.mes.states.service.client.StateChangeViewClientValidationUtil.java
private void addValidationErrorsToForm(final FormComponent form, final List<Entity> messagesList) { final Entity entity = form.getEntity(); final List<Entity> messages = Lists.newArrayList(messagesList); CollectionUtils.filter(messages, VALIDATION_MESSAGES_PREDICATE); for (Entity message : messages) { assignMessageToEntity(entity, message); }/*from ww w .j a v a 2s. c o m*/ if (!entity.isValid()) { form.addMessage("qcadooView.message.saveFailedMessage", MessageType.FAILURE); } form.setEntity(entity); }
From source file:com.perceptive.epm.perkolcentral.bl.LicensesBL.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public HashMap<String, ArrayList<String>> getLicenseRelatedInfo() throws ExceptionWrapper { HashMap<String, ArrayList<String>> licenseInfoKeyedByLicenseName = new HashMap<String, ArrayList<String>>(); try {/*from ww w. jav a2s . c om*/ for (Object obj : licenseMasterDataAccessor.getAllLicenseType().values()) { final LicenseBO licenseBO = (LicenseBO) obj; //get the total license purchased for this type of item ArrayList<Licensepurchase> licensepurchaseArrayList = licensePurchaseDataAccessor .getAllLicensePurchaseInformation(); CollectionUtils.filter(licensepurchaseArrayList, new Predicate() { @Override public boolean evaluate(Object o) { Licensepurchase item = (Licensepurchase) o; return (item.getLicensemaster().getLicenseTypeId() .equals(Long.valueOf(licenseBO.getLicenseTypeId()))); } }); //Add up all the licenses purchased int totLicenses = 0; for (Object item : licensepurchaseArrayList) { totLicenses = totLicenses + ((Licensepurchase) item).getNumberOfLicenses(); } if (!licenseInfoKeyedByLicenseName.containsKey(licenseBO.getLicenseTypeName())) licenseInfoKeyedByLicenseName.put(licenseBO.getLicenseTypeName(), new ArrayList<String>()); licenseInfoKeyedByLicenseName.get(licenseBO.getLicenseTypeName()) .add(Integer.toString(totLicenses)); //Get the total number of licenses used up for this type of licenses licenseInfoKeyedByLicenseName.get(licenseBO.getLicenseTypeName()) .add(Integer.toString(employeeLicenseDataAccessor .getEmployeeIdsByLicenseId(licenseBO.getLicenseTypeId()).size())); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } return licenseInfoKeyedByLicenseName; }
From source file:com.newlandframework.avatarmq.consumer.ConsumerClusters.java
public RemoteChannelData nextRemoteChannelData() { Predicate predicate = new Predicate() { public boolean evaluate(Object object) { RemoteChannelData data = (RemoteChannelData) object; Channel channel = data.getChannel(); return NettyUtil.validateChannel(channel); }//from w w w .j a v a2 s.c om }; CollectionUtils.filter(channelList, predicate); return channelList.get(next++ % channelList.size()); }
From source file:de.hybris.platform.b2bacceleratorservices.company.impl.DefaultB2BCommerceUserService.java
protected Set<PrincipalGroupModel> removeUsergroupFromGroups(final String usergroup, final Set<PrincipalGroupModel> groups) { final Set<PrincipalGroupModel> groupsWithoutUsergroup = new HashSet<PrincipalGroupModel>(groups); CollectionUtils.filter(groupsWithoutUsergroup, new Predicate() { @Override/*from w w w . jav a 2s .c o m*/ public boolean evaluate(final Object object) { final PrincipalGroupModel group = (PrincipalGroupModel) object; return !StringUtils.equals(usergroup, group.getUid()); } }); return groupsWithoutUsergroup; }
From source file:com.vmware.upgrade.progress.DefaultExecutionStateAggregatorTest.java
private Set<ExecutionState> computeStateTransitions(final ExecutionState state) { EnumSet<ExecutionState> states = EnumSet.allOf(ExecutionState.class); CollectionUtils.filter(states, new Predicate() { @Override/*from ww w. ja v a 2 s. c om*/ public boolean evaluate(Object object) { return state.canTransitionTo((ExecutionState) object); } }); return states; }
From source file:fr.itinerennes.bundler.gtfs.GtfsAdvancedDao.java
public List<StopTime> getStopTimes(final Stop stop, final ServiceDate date) { final List<StopTime> stopTimes = new ArrayList<StopTime>(gtfs.getStopTimesForStop(stop)); CollectionUtils.filter(stopTimes, new Predicate() { @Override//from www. j av a2 s.c o m public boolean evaluate(Object object) { final StopTime st = (StopTime) object; final AgencyAndId serviceId = st.getTrip().getServiceId(); final ServiceCalendar sc = gtfs.getCalendarForServiceId(serviceId); final ServiceDate start = sc.getStartDate(); final ServiceDate end = sc.getEndDate(); if (isAdditionalException(date, st.getTrip())) { return true; } else if (isRemovalException(date, sc)) { return false; } else if (start.compareTo(date) <= 0 && end.compareTo(date) >= 0) { final String agencyId = stop.getId().getAgencyId(); final TimeZone tz = GtfsAdvancedDao.this.getTimeZone(agencyId); return DayOfWeek.isSameDay(date.getAsCalendar(tz), sc); } else { return false; } } }); return stopTimes; }