org.apache.commons.collections.Predicate Java Examples

The following examples show how to use org.apache.commons.collections.Predicate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventReportQueueJob.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<EventReportQueueJob> retrieveDoneGeneratedReports() {
    List<EventReportQueueJob> reports = new ArrayList<>();

    CollectionUtils.select(Bennu.getInstance().getQueueJobSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            if (!(arg0 instanceof EventReportQueueJob)) {
                return false;
            }

            EventReportQueueJob eventReportQueueJob = (EventReportQueueJob) arg0;

            return eventReportQueueJob.getDone();
        }

    }, reports);

    return reports;
}
 
Example #2
Source File: FunctorUtils.java    From Penetration_Testing_POC with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the predicates to ensure that all is well.
 * 
 * @param predicates  the predicates to validate
 * @return predicate array
 */
static Predicate[] validate(Collection predicates) {
    if (predicates == null) {
        throw new IllegalArgumentException("The predicate collection must not be null");
    }
    if (predicates.size() < 2) {
        throw new IllegalArgumentException(
            "At least 2 predicates must be specified in the predicate collection, size was " + predicates.size());
    }
    // convert to array like this to guarantee iterator() ordering
    Predicate[] preds = new Predicate[predicates.size()];
    int i = 0;
    for (Iterator it = predicates.iterator(); it.hasNext();) {
        preds[i] = (Predicate) it.next();
        if (preds[i] == null) {
            throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null");
        }
        i++;
    }
    return preds;
}
 
Example #3
Source File: AbstractPredicateUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public void addPredicates(SearchFilter filter, List<Predicate> predicates) {
	addPredicateForServiceType(filter.getParam(SearchFilter.SERVICE_TYPE), predicates);
	addPredicateForServiceTypeId(filter.getParam(SearchFilter.SERVICE_TYPE_ID), predicates);
	addPredicateForServiceName(filter.getParam(SearchFilter.SERVICE_NAME), predicates);
	// addPredicateForServiceId(filter.getParam(SearchFilter.SERVICE_ID), predicates); // not supported
	addPredicateForPolicyName(filter.getParam(SearchFilter.POLICY_NAME), predicates);
	addPredicateForPolicyId(filter.getParam(SearchFilter.POLICY_ID), predicates);
	addPredicateForIsEnabled(filter.getParam(SearchFilter.IS_ENABLED), predicates);
	addPredicateForIsRecursive(filter.getParam(SearchFilter.IS_RECURSIVE), predicates);
	addPredicateForTagServiceName(filter.getParam(SearchFilter.TAG_SERVICE_NAME), predicates);
	// addPredicateForTagServiceId(filter.getParam(SearchFilter.TAG_SERVICE_ID), predicates); // not supported
	addPredicateForUserName(filter.getParam(SearchFilter.USER), predicates);
	addPredicateForGroupName(filter.getParam(SearchFilter.GROUP), predicates);
	addPredicateForResources(filter.getParamsWithPrefix(SearchFilter.RESOURCE_PREFIX, true), predicates);
	addPredicateForPolicyResource(filter.getParam(SearchFilter.POL_RESOURCE), predicates);
	addPredicateForPartialPolicyName(filter.getParam(SearchFilter.POLICY_NAME_PARTIAL), predicates);
	addPredicateForResourceSignature(filter.getParam(SearchFilter.RESOURCE_SIGNATURE), predicates);
	addPredicateForPolicyType(filter.getParam(SearchFilter.POLICY_TYPE), predicates);
	addPredicateForPolicyPriority(filter.getParam(SearchFilter.POLICY_PRIORITY), predicates);
	addPredicateForPartialPolicyLabels(filter.getParam(SearchFilter.POLICY_LABELS_PARTIAL), predicates);
	addPredicateForZoneName(filter.getParam(SearchFilter.ZONE_NAME), predicates);
	// addPredicateForZoneId(filter.getParam(SearchFilter.ZONE_ID), predicates); // not supported
}
 
Example #4
Source File: ChildrenDataSourceServlet.java    From commerce-cif-connector with Apache License 2.0 6 votes vote down vote up
private static Transformer createTransformer(final String itemRT, final Predicate predicate) {
    return new Transformer() {
        public Object transform(Object o) {
            Resource r = ((Resource) o);

            return new PredicatedResourceWrapper(r, predicate) {
                @Override
                public String getResourceType() {
                    if (itemRT == null) {
                        return super.getResourceType();
                    }
                    return itemRT;
                }
            };
        }
    };
}
 
Example #5
Source File: CurricularCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public boolean hasActiveScopeInGivenSemesterForCommonAndGivenBranch(final Integer semester, final Branch branch) {

    Collection<CurricularCourseScope> scopes = getScopesSet();

    List<CurricularCourseScope> result = (List<CurricularCourseScope>) CollectionUtils.select(scopes, new Predicate() {
        @Override
        public boolean evaluate(Object obj) {
            CurricularCourseScope curricularCourseScope = (CurricularCourseScope) obj;
            return ((curricularCourseScope.getBranch().getBranchType().equals(BranchType.COMNBR) || curricularCourseScope
                    .getBranch().equals(branch))
                    && curricularCourseScope.getCurricularSemester().getSemester().equals(semester) && curricularCourseScope
                    .isActive().booleanValue());
        }
    });

    return !result.isEmpty();
}
 
Example #6
Source File: CurricularCourseScopesForPrintDTO.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private CurricularSemesterForPrintDTO getSelectedSemester(final InfoCurricularCourseScope scope,
        BranchForPrintDTO selectedBranch) {
    CurricularSemesterForPrintDTO selectedSemester =
            (CurricularSemesterForPrintDTO) CollectionUtils.find(selectedBranch.getSemesters(), new Predicate() {

                @Override
                public boolean evaluate(Object arg0) {
                    CurricularSemesterForPrintDTO curricularSemesterForPrintDTO = (CurricularSemesterForPrintDTO) arg0;
                    if (curricularSemesterForPrintDTO.getSemester().equals(scope.getInfoCurricularSemester().getSemester())) {
                        return true;
                    }
                    return false;
                }

            });
    if (selectedSemester == null) {
        selectedSemester = new CurricularSemesterForPrintDTO(scope.getInfoCurricularSemester().getSemester());
        selectedBranch.getSemesters().add(selectedSemester);
    }

    return selectedSemester;
}
 
Example #7
Source File: ApprovedLearningAgreementDocumentFile.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected List<ApprovedLearningAgreementExecutedAction> getSentEmailAcceptedStudentActions() {
    List<ApprovedLearningAgreementExecutedAction> executedActionList =
            new ArrayList<ApprovedLearningAgreementExecutedAction>();

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

        @Override
        public boolean evaluate(Object arg0) {
            return ((ApprovedLearningAgreementExecutedAction) arg0).isSentEmailAcceptedStudent();
        };

    }, executedActionList);

    Collections.sort(executedActionList, Collections.reverseOrder(ExecutedAction.WHEN_OCCURED_COMPARATOR));

    return executedActionList;
}
 
Example #8
Source File: TagPredicateUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
@Override
public void addPredicates(SearchFilter filter, List<Predicate> predicates) {
	super.addPredicates(filter, predicates);

	addPredicateForTagDefId(filter.getParam(SearchFilter.TAG_DEF_ID), predicates);
	addPredicateForTagDefGuid(filter.getParam(SearchFilter.TAG_DEF_GUID), predicates);

	addPredicateForTagId(filter.getParam(SearchFilter.TAG_ID), predicates);
	addPredicateForTagGuid(filter.getParam(SearchFilter.TAG_GUID), predicates);
	addPredicateForTagType(filter.getParam(SearchFilter.TAG_TYPE), predicates);

	addPredicateForResourceId(filter.getParam(SearchFilter.TAG_RESOURCE_ID), predicates);
	addPredicateForResourceGuid(filter.getParam(SearchFilter.TAG_RESOURCE_GUID), predicates);
	addPredicateForServiceResourceServiceName(filter.getParam(SearchFilter.TAG_RESOURCE_SERVICE_NAME), predicates);
	addPredicateForResourceSignature(filter.getParam(SearchFilter.TAG_RESOURCE_SIGNATURE), predicates);

	addPredicateForTagResourceMapId(filter.getParam(SearchFilter.TAG_MAP_ID), predicates);
}
 
Example #9
Source File: AbstractPredicateUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public void applyFilter(List<? extends RangerBaseModelObject> objList, SearchFilter filter) {
	if(CollectionUtils.isEmpty(objList)) {
		return;
	}

	Predicate pred = getPredicate(filter);

	if(pred != null) {
		CollectionUtils.filter(objList, pred);
	}

	Comparator<RangerBaseModelObject> sorter = getSorter(filter);

	if(sorter != null) {
		Collections.sort(objList, sorter);
	}
}
 
Example #10
Source File: CurricularCourseScopesForPrintDTO.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private DegreeCurricularPlanForPrintDTO getSelectedCurricularPlan(final InfoCurricularCourseScope scope) {
    DegreeCurricularPlanForPrintDTO selectedCurricularPlan =
            (DegreeCurricularPlanForPrintDTO) CollectionUtils.find(getDegreeCurricularPlans(), new Predicate() {

                @Override
                public boolean evaluate(Object arg0) {
                    DegreeCurricularPlanForPrintDTO degreeCurricularPlanForPrintDTO = (DegreeCurricularPlanForPrintDTO) arg0;
                    if (degreeCurricularPlanForPrintDTO.name.equals(scope.getInfoCurricularCourse()
                            .getInfoDegreeCurricularPlan().getName())) {
                        return true;
                    }

                    return false;
                }
            });

    if (selectedCurricularPlan == null) {
        InfoDegreeCurricularPlan degreeCurricularPlan = scope.getInfoCurricularCourse().getInfoDegreeCurricularPlan();
        selectedCurricularPlan =
                new DegreeCurricularPlanForPrintDTO(degreeCurricularPlan.getName(), degreeCurricularPlan.getInfoDegree()
                        .getNome(), degreeCurricularPlan.getAnotation());
        this.getDegreeCurricularPlans().add(selectedCurricularPlan);
    }

    return selectedCurricularPlan;
}
 
Example #11
Source File: CurricularCourseScopesForPrintDTO.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private BranchForPrintDTO getSelectedBranch(final InfoCurricularCourseScope scope,
        CurricularYearForPrintDTO selectedCurricularYear) {
    BranchForPrintDTO selectedBranch =
            (BranchForPrintDTO) CollectionUtils.find(selectedCurricularYear.getBranches(), new Predicate() {

                @Override
                public boolean evaluate(Object arg0) {
                    BranchForPrintDTO branchForPrintDTO = (BranchForPrintDTO) arg0;
                    if (branchForPrintDTO.getName().equals(scope.getInfoBranch().getName())) {
                        return true;
                    }

                    return false;
                }

            });

    if (selectedBranch == null) {
        selectedBranch = new BranchForPrintDTO(scope.getInfoBranch().getName());
        selectedCurricularYear.getBranches().add(selectedBranch);

    }

    return selectedBranch;
}
 
Example #12
Source File: CountElementsInList.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void number_of_occurence_in_list_apache_commons () {

	List<String> seussCountActivities = Lists.newArrayList(
			"findow", "Balloons", "Elephants", 
			"Boom Bands", "findow", "Hakken-Kraks", 
			"Hakken-Kraks", "Hakken-Kraks", "Elephants");
	
	int numberOfElephants = CollectionUtils.countMatches(seussCountActivities, new Predicate() {
		public boolean evaluate(Object arg0) {
			String compare = (String) arg0;
			return compare.equalsIgnoreCase("Elephants");
		}
	});
	
	logger.info(numberOfElephants);

	assertEquals(2, numberOfElephants);
}
 
Example #13
Source File: WhileClosure.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method that performs validation.
 * 
 * @param predicate  the predicate used to evaluate when the loop terminates, not null
 * @param closure  the closure the execute, not null
 * @param doLoop  true to act as a do-while loop, always executing the closure once
 * @return the <code>while</code> closure
 * @throws IllegalArgumentException if the predicate or closure is null
 */
public static Closure getInstance(Predicate predicate, Closure closure, boolean doLoop) {
    if (predicate == null) {
        throw new IllegalArgumentException("Predicate must not be null");
    }
    if (closure == null) {
        throw new IllegalArgumentException("Closure must not be null");
    }
    return new WhileClosure(predicate, closure, doLoop);
}
 
Example #14
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);

    for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }

    for(AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }

    for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }

    for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }

    for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) {
        if (searchPredicates.evaluate(relationshipType)) {
            typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
        }
    }

    return typesDef;
}
 
Example #15
Source File: ContentTypes.java    From mr4c with Apache License 2.0 5 votes vote down vote up
public static Collection<String> filterByContentType(Collection<String> fileNames, final String contentType, final boolean canonicalOnly) {
	return CollectionUtils.predicatedCollection(fileNames, new Predicate() {
		public boolean evaluate(Object obj) {
			String name = (String)obj;
			if ( canonicalOnly ) {
				String suffix = ContentTypes.getSuffix(contentType);
				return FilenameUtils.isExtension(name, suffix);
			} else {
				Collection<String> suffixes = ContentTypes.getSuffixes(contentType);
				return FilenameUtils.isExtension(name, suffixes);
			}
		}
	} );
}
 
Example #16
Source File: FunctorUtils.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the predicates to ensure that all is well.
 * 
 * @param predicates  the predicates to validate
 */
static void validate(Predicate[] predicates) {
    if (predicates == null) {
        throw new IllegalArgumentException("The predicate array must not be null");
    }
    for (int i = 0; i < predicates.length; i++) {
        if (predicates[i] == null) {
            throw new IllegalArgumentException("The predicate array must not contain a null predicate, index " + i + " was null");
        }
    }
}
 
Example #17
Source File: ConsumerClusters.java    From AvatarMQ with Apache License 2.0 5 votes vote down vote up
public RemoteChannelData nextRemoteChannelData() {

        Predicate predicate = new Predicate() {
            public boolean evaluate(Object object) {
                RemoteChannelData data = (RemoteChannelData) object;
                Channel channel = data.getChannel();
                return NettyUtil.validateChannel(channel);
            }
        };

        CollectionUtils.filter(channelList, predicate);
        return channelList.get(next++ % channelList.size());
    }
 
Example #18
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the required (not-nullable) columns in this table. If none are found,
 * then an empty array will be returned.
 * 
 * @return The required columns
 */
public Column[] getRequiredColumns()
{
    Collection requiredColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column)input).isRequired();
        }
    });

    return (Column[])requiredColumns.toArray(new Column[requiredColumns.size()]);
}
 
Example #19
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of non-unique indices on this table.
 * 
 * @return The unique indices
 */
public Index[] getNonUniqueIndices()
{
    Collection nonUniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return !((Index)input).isUnique();
        }
    });

    return (Index[])nonUniqueIndices.toArray(new Index[nonUniqueIndices.size()]);
}
 
Example #20
Source File: PublicPhdProgramCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<PhdCandidacyPeriod> getCandidacyPeriods() {
    List<PhdCandidacyPeriod> candidacyPeriodList = new ArrayList<PhdCandidacyPeriod>();

    CollectionUtils.select(Bennu.getInstance().getCandidacyPeriodsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return arg0 instanceof PhdCandidacyPeriod;
        }

    }, candidacyPeriodList);

    return candidacyPeriodList;
}
 
Example #21
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPatchRollbackPredicateWrongClass() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	
	boolean result = patchRollbackPredicate.evaluate(new Object());
	assertFalse("testPatchRollbackPredicateWrongClass returned true unexpectedly",result);
}
 
Example #22
Source File: MobilityApplicationProcess.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<MobilityIndividualApplicationProcess> getProcessesWithNotViewedAlerts() {
    List<MobilityIndividualApplicationProcess> processList = new ArrayList<MobilityIndividualApplicationProcess>();
    CollectionUtils.select(getChildProcessesSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            MobilityIndividualApplicationProcess process = (MobilityIndividualApplicationProcess) arg0;
            return process.isProcessWithMostRecentAlertMessageNotViewed();
        }

    }, processList);

    return processList;
}
 
Example #23
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of unique indices on this table.
 * 
 * @return The unique indices
 */
public Index[] getUniqueIndices()
{
    Collection uniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Index)input).isUnique();
        }
    });

    return (Index[])uniqueIndices.toArray(new Index[uniqueIndices.size()]);
}
 
Example #24
Source File: ExternalPhdProgram.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<ExternalPhdProgram> readExternalPhdProgramsForCollaborationType(
        final PhdIndividualProgramCollaborationType type) {
    List<ExternalPhdProgram> phdProgramList = new ArrayList<ExternalPhdProgram>();

    CollectionUtils.select(Bennu.getInstance().getExternalPhdProgramsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((ExternalPhdProgram) arg0).isForCollaborationType(type);
        }

    }, phdProgramList);

    return phdProgramList;
}
 
Example #25
Source File: BaseAuthenticationService.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
protected boolean requestURIdoesLogin(final HttpServletRequest request) {
    return CollectionUtils.exists(getLoginURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }
    });
}
 
Example #26
Source File: ModulaOutlinePageContentProvider.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private Collection<IXdsElement> filter(Collection<IXdsElement> elements) {
	if (!elements.isEmpty()) {
		elements = new ArrayList<IXdsElement>(elements);
	}
    CollectionUtils.filter(elements, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            IXdsElement xdsElement = (IXdsElement)o;
            return filter.accept(xdsElement);
        }
    });
    return elements;
}
 
Example #27
Source File: ChildrenDataSourceServlet.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
private static Predicate getFilter(String filter) {
    if (filter == null) {
        return Filter.folderOrProduct;
    }

    try {
        return Filter.valueOf(filter);
    } catch (IllegalArgumentException x) {
        return Filter.folderOrProduct;
    }
}
 
Example #28
Source File: EnvironmentAlertHandlersImpl.java    From peer-os with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings( "unchecked" )
public Collection<AlertHandler> getEffectiveHandlers()
{
    return CollectionUtils.select( handlers.values(), new Predicate()
    {
        @Override
        public boolean evaluate( final Object o )
        {
            return o != null;
        }
    } );
}
 
Example #29
Source File: DegreeCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Branch> getCommonAreas() {
    return (List<Branch>) CollectionUtils.select(getAreasSet(), new Predicate() {
        @Override
        public boolean evaluate(Object obj) {
            Branch branch = (Branch) obj;
            if (branch.getBranchType() == null) {
                return branch.getName().equals("") && branch.getCode().equals("");
            }
            return branch.getBranchType().equals(org.fenixedu.academic.domain.branch.BranchType.COMNBR);

        }
    });
}
 
Example #30
Source File: SwitchClosure.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method that performs validation and copies the parameter arrays.
 * 
 * @param predicates  array of predicates, cloned, no nulls
 * @param closures  matching array of closures, cloned, no nulls
 * @param defaultClosure  the closure to use if no match, null means nop
 * @return the <code>chained</code> closure
 * @throws IllegalArgumentException if array is null
 * @throws IllegalArgumentException if any element in the array is null
 */
public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) {
    FunctorUtils.validate(predicates);
    FunctorUtils.validate(closures);
    if (predicates.length != closures.length) {
        throw new IllegalArgumentException("The predicate and closure arrays must be the same size");
    }
    if (predicates.length == 0) {
        return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
    }
    predicates = FunctorUtils.copy(predicates);
    closures = FunctorUtils.copy(closures);
    return new SwitchClosure(predicates, closures, defaultClosure);
}