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:org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.java

/**
 * Many OAI annotations can either be found singly or as a wrapped array.  This method will
 * look for both and return a list of all found.  Both the single and wrapper annotation names
 * must be provided./*from  ww  w. j  ava2s.co m*/
 * @param method
 * @param singleAnnotationName
 * @param repeatableAnnotationName
 */
public static List<AnnotationInstance> getRepeatableAnnotation(MethodInfo method, DotName singleAnnotationName,
        DotName repeatableAnnotationName) {
    List<AnnotationInstance> annotations = new ArrayList<>(method.annotations());
    CollectionUtils.filter(annotations, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            AnnotationInstance annotation = (AnnotationInstance) object;
            return annotation.name().equals(singleAnnotationName);
        }
    });
    if (repeatableAnnotationName != null && method.hasAnnotation(repeatableAnnotationName)) {
        AnnotationInstance annotation = method.annotation(repeatableAnnotationName);
        AnnotationValue annotationValue = annotation.value();
        if (annotationValue != null) {
            AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
            annotations.addAll(Arrays.asList(nestedArray));
        }
    }
    return annotations;
}

From source file:org.xlcloud.console.images.controllers.ImageCreateBean.java

private void removeEmptyProperties(Image image) {
    CollectionUtils.filter(image.getProperties().getProperty(), new Predicate() {
        public boolean evaluate(Object object) {
            Property property = (Property) object;
            return StringUtils.isNotBlank(property.getName()) || StringUtils.isNotBlank(property.getValue());
        }//  w w w . j a v  a2  s  . c  o  m
    });
}

From source file:org.yes.cart.service.dto.impl.DtoProductServiceImpl.java

/**
 * {@inheritDoc}/*from   w w w  .  j a va2 s  .  c om*/
 */
public List<? extends AttrValueDTO> getEntityAttributes(final long entityPk)
        throws UnmappedInterfaceException, UnableToCreateInstanceException {

    final ProductDTO productDTO = getById(entityPk);
    final List<AttrValueProductDTO> productAttrs = new ArrayList<AttrValueProductDTO>(
            productDTO.getAttributes());

    final List<AttributeDTO> ptList = dtoAttributeService
            .findAvailableAttributesByProductTypeId(productDTO.getProductTypeDTO().getProducttypeId());

    final List<AttributeDTO> images = dtoAttributeService
            .findAvailableImageAttributesByGroupCode(AttributeGroupNames.PRODUCT);

    ptList.addAll(images);

    final List<AttributeDTO> mandatory = dtoAttributeService.findAvailableAttributesByGroupCodeStartsWith(
            AttributeGroupNames.PRODUCT, AttributeNamesKeys.Product.PRODUCT_DESCRIPTION_PREFIX);

    ptList.addAll(mandatory);

    final Set<String> existingAttrValueCodes = new HashSet<String>();
    for (final AttrValueProductDTO value : productAttrs) {
        existingAttrValueCodes.add(value.getAttributeDTO().getCode());
    }

    final List<AttrValueProductDTO> full = new ArrayList<AttrValueProductDTO>(ptList.size());
    for (final AttributeDTO available : ptList) {
        if (!existingAttrValueCodes.contains(available.getCode())) {
            // add blank value for available attribute
            final AttrValueProductDTO attrValueDTO = getAssemblerDtoFactory()
                    .getByIface(AttrValueProductDTO.class);
            attrValueDTO.setAttributeDTO(available);
            attrValueDTO.setProductId(entityPk);
            full.add(attrValueDTO);
        }
    }

    full.addAll(productAttrs); // add all the rest values that are specified for this product

    CollectionUtils.filter(full, new Predicate() {
        public boolean evaluate(final Object object) {
            return ((AttrValueDTO) object).getAttributeDTO() != null;
        }
    });

    Collections.sort(full, new AttrValueDTOComparatorImpl());
    return full;
}

From source file:org.yes.cart.service.dto.impl.DtoProductSkuServiceImpl.java

/**
 * {@inheritDoc}/*  ww w. j a va2  s.c om*/
 */
public List<? extends AttrValueDTO> getEntityAttributes(final long entityPk)
        throws UnmappedInterfaceException, UnableToCreateInstanceException {

    final ProductSkuDTO sku = getById(entityPk);
    final List<AttrValueProductSkuDTO> skuAttrs = new ArrayList<AttrValueProductSkuDTO>(sku.getAttributes());

    final ProductDTO product = getDtoProductService().getById(sku.getProductId());
    final List<AttrValueProductDTO> productAttrs = new ArrayList<AttrValueProductDTO>(product.getAttributes());

    final List<AttributeDTO> ptList = dtoAttributeService
            .findAvailableAttributesByProductTypeId(product.getProductTypeDTO().getProducttypeId());

    final List<AttributeDTO> images = dtoAttributeService
            .findAvailableImageAttributesByGroupCode(AttributeGroupNames.PRODUCT);

    ptList.addAll(images);

    final List<AttributeDTO> mandatory = dtoAttributeService.findAvailableAttributesByGroupCodeStartsWith(
            AttributeGroupNames.PRODUCT, AttributeNamesKeys.Product.PRODUCT_DESCRIPTION_PREFIX);

    ptList.addAll(mandatory);

    // code to list as we may have multivalues
    final Map<String, List<AttrValueProductDTO>> existingProductAttrValues = new HashMap<String, List<AttrValueProductDTO>>();
    for (final AttrValueProductDTO value : productAttrs) {
        final String attrCode = value.getAttributeDTO().getCode();
        List<AttrValueProductDTO> codeValues = existingProductAttrValues.get(attrCode);
        if (codeValues == null) {
            codeValues = new ArrayList<AttrValueProductDTO>();
            existingProductAttrValues.put(attrCode, codeValues);
        }
        codeValues.add(value);
    }

    final Set<String> existingSkuAttrValueCodes = new HashSet<String>();
    for (final AttrValueProductSkuDTO value : skuAttrs) {
        existingSkuAttrValueCodes.add(value.getAttributeDTO().getCode());
    }

    final List<AttrValueProductSkuDTO> full = new ArrayList<AttrValueProductSkuDTO>(ptList.size());
    for (final AttributeDTO available : ptList) {
        if (!existingSkuAttrValueCodes.contains(available.getCode())) {

            final List<AttrValueProductDTO> productValues = existingProductAttrValues.get(available.getCode());
            if (productValues == null) {

                // we do not have product nor sku values, so create blank
                final AttrValueProductSkuDTO attrValueDTO = getAssemblerDtoFactory()
                        .getByIface(AttrValueProductSkuDTO.class);
                attrValueDTO.setAttributeDTO(available);
                attrValueDTO.setSkuId(entityPk);
                full.add(attrValueDTO);

            } else {
                for (final AttrValueProductDTO prodValue : productValues) {

                    // pre-fill sku value with product value so that we can easily see it
                    AttrValueProductSkuDTO attrValueDTO = getAssemblerDtoFactory()
                            .getByIface(AttrValueProductSkuDTO.class);
                    attrValueDTO.setAttributeDTO(available);
                    attrValueDTO.setSkuId(entityPk);
                    attrValueDTO.setVal("* " + prodValue.getVal());
                    full.add(attrValueDTO);

                }
            }
        }
    }

    full.addAll(skuAttrs); // add all the rest values that are specified for this sku

    CollectionUtils.filter(full, new Predicate() {
        public boolean evaluate(final Object object) {
            return ((AttrValueDTO) object).getAttributeDTO() != null;
        }
    });

    Collections.sort(full, new AttrValueDTOComparatorImpl());
    return full;
}

From source file:pt.ist.expenditureTrackingSystem.presentationTier.widgets.MyProcessesWidget.java

@Override
public void doView(WidgetRequest request) {
    DashBoardWidget widget = request.getWidget();
    ExpenditureWidgetOptions options = getOrCreateOptions(widget);
    Person loggedPerson = Person.getLoggedPerson();

    List<PaymentProcess> myProcesses = loggedPerson.getAcquisitionProcesses(PaymentProcess.class);
    CollectionUtils.filter(myProcesses, NOT_PAYED_PROCESS_PREDICATE);
    Collections.sort(myProcesses, new ReverseComparator(new BeanComparator("acquisitionProcessId")));
    myProcesses = myProcesses.subList(0, Math.min(options.getMaxListSize(), myProcesses.size()));

    request.setAttribute("widgetOptions-" + widget.getExternalId(), options);
    request.setAttribute("ownProcesses", myProcesses);
    request.setAttribute("person", loggedPerson);
}

From source file:ru.org.linux.site.tags.BoxListTag.java

@Override
public int doStartTag() throws JspException {
    Template t = Template.getTemplate(pageContext.getRequest());
    String s = object;// w  ww  .  ja  v  a 2  s  . c o m
    if (StringUtils.isEmpty(s)) {
        s = "main2";
    }
    List<String> boxnames = t.getProf().getList(s);
    CollectionUtils.filter(boxnames, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            String s = (String) o;
            return DefaultProfile.isBox(s);
        }
    });
    pageContext.setAttribute(var, boxnames);
    return EVAL_BODY_INCLUDE;
}

From source file:ru.org.linux.spring.AddRemoveBoxesController.java

@RequestMapping(value = "/add-box.jsp", method = RequestMethod.POST)
public String doAdd(@ModelAttribute("form") EditBoxesForm form, BindingResult result, SessionStatus status,
        HttpServletRequest request)/*  w w  w. j  a  va 2  s .  co m*/
        throws IOException, UtilException, AccessViolationException, StorageException {

    new EditBoxesFormValidator().validate(form, result);
    ValidationUtils.rejectIfEmptyOrWhitespace(result, "boxName", "boxName.empty",
            "?  ?");
    if (StringUtils.isNotEmpty(form.getBoxName()) && !DefaultProfile.isBox(form.getBoxName())) {
        result.addError(new FieldError("boxName", "boxName.invalid", "? ?"));
    }
    if (result.hasErrors()) {
        return "add-box";
    }
    Template t = Template.getTemplate(request);

    if (result.hasErrors()) {
        return "add-box";
    }

    if (form.getPosition() == null) {
        form.setPosition(0);
    }

    String objectName = getObjectName(form, request);
    List<String> boxlets = new ArrayList<String>(t.getProf().getList(objectName));

    CollectionUtils.filter(boxlets, DefaultProfile.getBoxPredicate());

    if (boxlets.size() > form.position) {
        boxlets.add(form.position, form.boxName);
    } else {
        boxlets.add(form.boxName);
    }

    t.getProf().setList(objectName, boxlets);
    t.writeProfile(t.getProfileName());

    status.setComplete();
    return "redirect:/edit-boxes.jsp";
}

From source file:ru.org.linux.user.AddRemoveBoxesController.java

@RequestMapping(value = "/add-box.jsp", method = RequestMethod.POST)
public String doAdd(@ModelAttribute("form") EditBoxesRequest form, BindingResult result, SessionStatus status,
        HttpServletRequest request) throws IOException, AccessViolationException, StorageException {

    new EditBoxesRequestValidator().validate(form, result);
    ValidationUtils.rejectIfEmptyOrWhitespace(result, "boxName", "boxName.empty",
            "?  ?");
    if (StringUtils.isNotEmpty(form.getBoxName()) && !DefaultProfile.isBox(form.getBoxName())) {
        result.addError(new FieldError("boxName", "boxName.invalid", "? ?"));
    }//from ww  w.j  a  v a 2 s . com
    if (result.hasErrors()) {
        return "add-box";
    }
    Template t = Template.getTemplate(request);

    if (result.hasErrors()) {
        return "add-box";
    }

    if (form.getPosition() == null) {
        form.setPosition(0);
    }

    String objectName = getObjectName(form, request);
    List<String> boxlets = new ArrayList<String>(t.getProf().getList(objectName));

    CollectionUtils.filter(boxlets, DefaultProfile.getBoxPredicate());

    if (boxlets.size() > form.position) {
        boxlets.add(form.position, form.boxName);
    } else {
        boxlets.add(form.boxName);
    }

    t.getProf().setList(objectName, boxlets);
    t.writeProfile(t.getProfileName());

    status.setComplete();
    return "redirect:/edit-boxes.jsp";
}

From source file:sturesy.core.backend.services.crud.VotingCRUDService.java

/**
 * Filters a collection of Votes for invalid votes
 * //from  w w w  . j  av a 2  s.  c  o m
 * @param votes
 */
private void filterFalseVotes(Collection<Vote> votes) {
    CollectionUtils.filter(votes, new ValidVotePredicate(10));
}

From source file:sturesy.votinganalysis.VotingAnalysis.java

/**
 * Filters all Votes which are not actually matching the associated question
 * //from w w w.j a v a2s. co m
 * @param votes
 */
private void filter(Map<Integer, Set<Vote>> votes) {
    for (Integer index : votes.keySet()) {
        int upperbound = _questionSet.getIndex(index).getAnswerSize();
        CollectionUtils.filter(votes.get(index), new ValidVotePredicate(upperbound));
    }
}