Example usage for org.apache.commons.collections PredicateUtils notPredicate

List of usage examples for org.apache.commons.collections PredicateUtils notPredicate

Introduction

In this page you can find the example usage for org.apache.commons.collections PredicateUtils notPredicate.

Prototype

public static Predicate notPredicate(Predicate predicate) 

Source Link

Document

Create a new Predicate that returns true if the specified predicate returns false and vice versa.

Usage

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,/* w w w  .  ja  v a 2  s .com*/
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class)));
    CollectionUtils.filter(roleModels,
            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:com.daimler.spm.b2bacceleratoraddon.actions.StartWorkFlowForAdmin.java

protected B2BCustomerModel findB2BAdministratorForCustomer(final B2BCustomerModel customer) {
    final List<B2BCustomerModel> b2bAdminGroupUsers = new ArrayList<B2BCustomerModel>(getB2bUnitService()
            .getUsersOfUserGroup(getB2bUnitService().getParent(customer), B2BConstants.B2BADMINGROUP, true));
    // remove the user who placed the order.
    CollectionUtils.filter(b2bAdminGroupUsers,
            PredicateUtils.notPredicate(PredicateUtils.equalPredicate(customer)));
    return (CollectionUtils.isNotEmpty(b2bAdminGroupUsers) ? b2bAdminGroupUsers.get(0) : null);
}

From source file:de.hybris.platform.b2bacceleratorfacades.order.populators.B2BApprovalDataPopulator.java

protected List<B2BOrderHistoryEntryData> filterOrderHistoryEntriesForApprovalStage(
        final List<B2BOrderHistoryEntryData> orderHistoryEntries, final String orderApprovalStage) {

    final Collection<B2BOrderHistoryEntryData> outputList = CollectionUtils.select(orderHistoryEntries,
            applyApprovalStagePredicate(orderApprovalStage));
    if (outputList != null && !outputList.isEmpty()) {
        final List<B2BOrderHistoryEntryData> selectedList = new ArrayList<B2BOrderHistoryEntryData>(
                outputList.size());/*www. j  a va 2s.co m*/
        selectedList.addAll(outputList);

        CollectionUtils.filter(orderHistoryEntries,
                PredicateUtils.notPredicate(applyApprovalStagePredicate(orderApprovalStage)));
        return selectedList;
    }
    return null;
}

From source file:de.hybris.platform.b2bacceleratorfacades.user.populators.B2BCustomerPopulator.java

protected void populateRoles(final B2BCustomerModel source, final CustomerData target) {
    final List<String> roles = new ArrayList<String>();
    final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(source.getGroups());
    CollectionUtils.filter(roleModels,/*w w  w .j av a 2 s  .  c  o  m*/
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class)));
    CollectionUtils.filter(roleModels,
            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:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultCompanyB2BCommerceFacade.java

protected B2BSelectionData populateRolesForCustomer(final B2BCustomerModel customerModel,
        final B2BSelectionData b2BSelectionData) {
    final List<String> roles = new ArrayList<String>();
    final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(customerModel.getGroups());
    CollectionUtils.filter(roleModels,/*  w  w w. ja  v a  2  s  .  c  o  m*/
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class)));
    CollectionUtils.filter(roleModels,
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUserGroupModel.class)));

    for (final PrincipalGroupModel role : roleModels) {
        roles.add(role.getUid());
    }
    b2BSelectionData.setRoles(roles);

    return b2BSelectionData;
}

From source file:com.architexa.diagrams.relo.graph.GraphLayoutManager.java

private void adjustNodeCoords(Graph graph, Map<AbstractGraphicalEditPart, Object> partsToCellMap,
        Point defaultPos) {//from   w  ww .j  av  a 2s. c  o m
    Set<AbstractGraphicalEditPart> newParts = new HashSet<AbstractGraphicalEditPart>();
    newParts.addAll(partsToCellMap.keySet());
    newParts.removeAll(ageMgr.getOldParts());
    Set<AbstractGraphicalEditPart> newEdges = new HashSet<AbstractGraphicalEditPart>(newParts);
    CollectionUtils.filter(newParts,
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(AbstractConnectionEditPart.class)));
    newEdges.removeAll(newParts);

    for (AbstractGraphicalEditPart edge : new HashSet<AbstractGraphicalEditPart>(newEdges)) {
        if (nodeConstrainedConn((AbstractConnectionEditPart) edge))
            newEdges.remove(edge);
    }

    //System.err.println("adjusting graph: " + newNodes.size() + " done: " + oldParts.size());
    GraphLayoutRules.assertRulesForNewParts(graph, newParts, newEdges, partsToCellMap, ageMgr, defaultPos, this,
            rootEditPart);

    // save for next time
    //fixedLocationParts.addAll(newNodes);
}

From source file:no.sesat.search.query.analyser.AnalysisRuleFactory.java

private Predicate createPredicate(final Element element, final Map predicateMap,
        final Map inheritedPredicates) {

    Predicate result = null;//from   w ww  .  jav  a  2s.c  o m
    // The operator to use from PredicateUtils.
    //   The replaceAll's are so we end up with a method with one Predicate[] argument.
    final String methodName = element.getTagName().replaceAll("and", "all").replaceAll("or", "any")
            .replaceAll("either", "one").replaceAll("neither", "none") + "Predicate";
    // because we can't use the above operator methods with only one child predicate
    //  the not operator must be a special case.
    final boolean notPredicate = "not".equals(element.getTagName());

    try {
        // Find PredicateUtils static method through reflection
        final Method method = notPredicate ? null
                : PredicateUtils.class.getMethod(methodName, new Class[] { Collection.class });

        // load all the predicates it will apply to
        final List childPredicates = new LinkedList();
        final NodeList predicates = element.getChildNodes();
        for (int i = 0; i < predicates.getLength(); ++i) {
            final Node node = predicates.item(i);
            if (node instanceof Element) {
                final Element e = (Element) node;
                if ("predicate".equals(e.getTagName())) {
                    childPredicates.add(readPredicate(e, predicateMap, inheritedPredicates));
                }
            }
        }
        if (notPredicate) {
            // there should only be one in the list
            if (childPredicates.size() > 1) {
                throw new IllegalStateException(ERR_TOO_MANY_PREDICATES_IN_NOT + element.getParentNode());
            }
            result = PredicateUtils.notPredicate((Predicate) childPredicates.get(0));
        } else {
            // use the operator through reflection
            result = (Predicate) method.invoke(null, new Object[] { childPredicates });
        }

    } catch (SecurityException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_FIND_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (NoSuchMethodException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_FIND_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (IllegalAccessException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (InvocationTargetException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (IllegalArgumentException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    }

    return result;
}

From source file:org.apache.cayenne.wocompat.EOModelProcessor.java

/**
 * Performs EOModel loading./* ww  w.  java  2 s .  co  m*/
 * 
 * @param url
 *            URL of ".eomodeld" directory.
 * @param generateClientClass
 *            if true then loading of EOModel is java client classes aware
 *            and the following processing will work with Java client class
 *            settings of the EOModel.
 */
public DataMap loadEOModel(URL url, boolean generateClientClass) throws Exception {
    EOModelHelper helper = makeHelper(url);

    // create empty map
    DataMap dataMap = helper.getDataMap();

    // process enitities ... throw out prototypes ... for now
    List modelNames = new ArrayList(helper.modelNamesAsList());
    CollectionUtils.filter(modelNames, PredicateUtils.notPredicate(prototypeChecker));

    Iterator it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();

        // create and register entity
        makeEntity(helper, name, generateClientClass);
    }

    // now sort following inheritance hierarchy
    Collections.sort(modelNames, new InheritanceComparator(dataMap));

    // after all entities are loaded, process attributes
    it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();

        EOObjEntity e = (EOObjEntity) dataMap.getObjEntity(name);
        // process entity attributes
        makeAttributes(helper, e);
    }

    // after all entities are loaded, process relationships
    it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        makeRelationships(helper, dataMap.getObjEntity(name));
    }

    // after all normal relationships are loaded, process flattened
    // relationships
    it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        makeFlatRelationships(helper, dataMap.getObjEntity(name));
    }

    // now create missing reverse DB (but not OBJ) relationships
    // since Cayenne requires them
    it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        DbEntity dbEntity = dataMap.getObjEntity(name).getDbEntity();

        if (dbEntity != null) {
            makeReverseDbRelationships(dbEntity);
        }
    }

    // build SelectQueries out of EOFetchSpecifications...
    it = modelNames.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        Iterator queries = helper.queryNames(name);
        while (queries.hasNext()) {
            String queryName = (String) queries.next();
            EOObjEntity entity = (EOObjEntity) dataMap.getObjEntity(name);
            makeQuery(helper, entity, queryName);
        }
    }

    return dataMap;
}