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

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

Introduction

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

Prototype

public static void filter(Collection collection, Predicate predicate) 

Source Link

Document

Filter the collection by applying a Predicate to each element.

Usage

From source file:net.sourceforge.fenixedu.applicationTier.Servico.gep.ListMasterDegreeStudents.java

@Atomic
public static Collection run(String executionYearName) {
    final ExecutionYear executionYear = ExecutionYear.readExecutionYearByName(executionYearName);

    final Collection<InfoStudentCurricularPlanWithFirstTimeEnrolment> infoStudentCurricularPlans = new ArrayList();
    final Collection<StudentCurricularPlan> studentCurricularPlans = new ArrayList();
    final Collection<DegreeCurricularPlan> masterDegreeCurricularPlans = DegreeCurricularPlan
            .readByDegreeTypeAndState(DegreeType.MASTER_DEGREE, DegreeCurricularPlanState.ACTIVE);
    CollectionUtils.filter(masterDegreeCurricularPlans, new Predicate() {

        @Override//from   w  w w . j av  a2s .  c  o m
        public boolean evaluate(Object arg0) {
            DegreeCurricularPlan degreeCurricularPlan = (DegreeCurricularPlan) arg0;
            for (ExecutionDegree executionDegree : degreeCurricularPlan.getExecutionDegreesSet()) {
                if (executionDegree.getExecutionYear().equals(executionYear)) {
                    return true;
                }
            }
            return false;
        }

    });

    for (DegreeCurricularPlan degreeCurricularPlan : masterDegreeCurricularPlans) {
        studentCurricularPlans.addAll(degreeCurricularPlan.getStudentCurricularPlansSet());
    }

    for (StudentCurricularPlan studentCurricularPlan : studentCurricularPlans) {

        if (!studentCurricularPlan.isActive()) {
            continue;
        }

        boolean firstTimeEnrolment = true;
        if (studentCurricularPlan.getSpecialization() != null && studentCurricularPlan.getSpecialization()
                .equals(Specialization.STUDENT_CURRICULAR_PLAN_MASTER_DEGREE)) {

            Collection<StudentCurricularPlan> previousStudentCurricularPlans = studentCurricularPlan
                    .getRegistration().getStudentCurricularPlansBySpecialization(
                            Specialization.STUDENT_CURRICULAR_PLAN_MASTER_DEGREE);

            previousStudentCurricularPlans.remove(studentCurricularPlan);
            for (StudentCurricularPlan previousStudentCurricularPlan : previousStudentCurricularPlans) {
                if (previousStudentCurricularPlan.getDegreeCurricularPlan().getDegree()
                        .equals(studentCurricularPlan.getDegreeCurricularPlan().getDegree())) {
                    firstTimeEnrolment = false;
                    break;
                }
            }
        } else if (studentCurricularPlan.getSpecialization() != null && studentCurricularPlan
                .getSpecialization().equals(Specialization.STUDENT_CURRICULAR_PLAN_SPECIALIZATION)) {
            if (!studentCurricularPlan.getDegreeCurricularPlan().getFirstExecutionDegree().getExecutionYear()
                    .equals(executionYear)) {
                continue;
            }
        }

        if (firstTimeEnrolment) {
            if (!studentCurricularPlan.getDegreeCurricularPlan().getFirstExecutionDegree().getExecutionYear()
                    .equals(executionYear)) {
                firstTimeEnrolment = false;
            }
        }

        InfoStudentCurricularPlanWithFirstTimeEnrolment infoStudentCurricularPlan = InfoStudentCurricularPlanWithFirstTimeEnrolment
                .newInfoFromDomain(studentCurricularPlan);
        infoStudentCurricularPlan.setFirstTimeEnrolment(firstTimeEnrolment);
        infoStudentCurricularPlans.add(infoStudentCurricularPlan);
    }

    return infoStudentCurricularPlans;

}

From source file:com.dotosoft.dot4command.commands.FilterCollectionCommand.java

@Override
public Processing onExecute(C context) {

    Collection dataCollection = (Collection) getProperty(context, fromKey);
    BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate(filterExpression,
            filterValue);/*from  w w  w  . ja  v  a  2  s  .c  om*/
    CollectionUtils.filter(dataCollection, predicate);

    if (dataCollection.isEmpty()) {
        context.remove(toKey);
    } else {
        context.put((K) toKey, (V) dataCollection);
    }

    return Processing.FINISHED;
}

From source file:adalid.commons.util.ColUtils.java

public static <T> Collection<T> anyFilter(Collection<T> collection, Predicate... predicates) {
    if (collection == null || collection.isEmpty() || predicates == null) {
        return collection;
    } else {/*from  w  ww .j  av a  2s . co m*/
        //          Collection<T> list = new ArrayList<T>();
        //          list.addAll(collection);
        Collection<T> list = new ArrayList<>(collection);
        Predicate predicate = PredicateUtils.anyPredicate(predicates);
        CollectionUtils.filter(list, predicate);
        return list;
    }
}

From source file:au.org.emii.geoserver.extensions.filters.layer.data.io.FilterConfigurationWriter.java

private List<Filter> getEnabledFilters() {
    List<Filter> enabledFilters = new ArrayList<Filter>(filters);
    CollectionUtils.filter(enabledFilters, getPredicate());
    return enabledFilters;
}

From source file:com.exxonmobile.ace.hybris.storefront.security.ExcludeUrlRequestMatcher.java

@Required
public void setExcludeUrlSet(final Set<String> excludeUrlSet) {
    // Ensure only valid urls are added to the excludeUrlSet
    CollectionUtils.filter(excludeUrlSet, new Predicate() {
        @Override//from   ww w  . j  a v  a2  s .c o  m
        public boolean evaluate(final Object object) {
            return (object != null) && (object instanceof String) && ((String) object).startsWith("/");
        }
    });

    this.excludeUrlSet = excludeUrlSet;
}

From source file:net.sourceforge.fenixedu.applicationTier.Filtro.PublishedExamsMapAuthorizationFilter.java

private static void filterUnpublishedInformation(InfoSiteEvaluation infoSiteEvaluation) {
    // This code is usefull for when the exams are to be filtered from the
    // public execution course page.
    CollectionUtils.filter(infoSiteEvaluation.getInfoEvaluations(), new Predicate() {
        @Override//from  ww w  . ja  va2s  .  c  om
        public boolean evaluate(Object arg0) {
            return !(arg0 instanceof InfoExam);
        }
    });
}

From source file:com.xebialabs.xlrelease.ci.server.XLReleaseServerImplMock.java

@Override
public List<Release> searchTemplates(final String s) {
    List<Release> templates = getAllTemplates();

    CollectionUtils.filter(templates, new Predicate() {
        public boolean evaluate(Object o) {
            return ((Release) o).getTitle().contains(s);
        }/*from  w ww  . j a  v a2  s  . c  o  m*/
    });
    LoggerFactory.getLogger(this.getClass()).info(templates + "\n");

    return templates;
}

From source file:com.assignmentone.util.persondb.AbstractDbManager.java

@SuppressWarnings("unchecked")
public synchronized List<T> find(final String field, final Object v) {
    List<T> list = new ArrayList<>(entityList);
    CollectionUtils.filter(list, new Predicate() {
        @Override//from  www . j  ava2  s. c om
        public boolean evaluate(Object object) {
            try {
                return ObjectUtils.equals(v, PropertyUtils.getProperty(object, field));
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
        }
    });
    return ListConvertUtil.transform(list, new RowConvertor<T, T>() {
        @Override
        public T convert(int rowIndex, T obj) {
            try {
                return (T) obj.clone();
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException(e);
            }
        }
    });
}

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  ww w  .j a va 2  s . 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);
        }/*  w w  w.j a  va2s.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";
}