Example usage for com.google.common.base Predicates not

List of usage examples for com.google.common.base Predicates not

Introduction

In this page you can find the example usage for com.google.common.base Predicates not.

Prototype

public static <T> Predicate<T> not(Predicate<T> predicate) 

Source Link

Document

Returns a predicate that evaluates to true if the given predicate evaluates to false .

Usage

From source file:com.sri.ai.grinder.sgdpllt.library.Equality.java

/**
 * Assumes that first argument is an equality (with possibly more than two arguments) and returns a pair,
 * the first member of which is a collection of the variables in the equality,
 * and the second member of which is the first constant present.
 * Returns null if there are no constants in the equality arguments.
 *//*from www.j av a  2 s .  c  o  m*/
public static Pair<List<Expression>, Expression> getVariablesListAndConstantOrNullIfNoConstant(
        Expression equality, Context context) {
    Pair<List<Expression>, Expression> result;
    List<Expression> variables = new LinkedList<Expression>();
    List<Expression> constants = new LinkedList<Expression>();
    Predicate<Expression> notIsConstant = Predicates.not(context.getIsUniquelyNamedConstantPredicate());
    Util.collectOrReturnFalseIfElementDoesNotFitEither(equality.getArguments(), variables, notIsConstant,
            constants, context.getIsUniquelyNamedConstantPredicate());
    if (constants.isEmpty()) {
        result = null;
    } else {
        result = Pair.make(variables, Util.getFirst(constants));
    }
    return result;
}

From source file:com.facebook.buck.android.AndroidResource.java

@Override
public Sha1HashCode getAbiKeyForDeps() {
    // We hash the transitive dependencies and not just the first order deps because we pass these
    // to aapt to generate R.java/R.txt.
    // Transitive dependencies includes this rule itself; filter it out.
    return HasAndroidResourceDeps.ABI_HASHER.apply(Iterables.filter(transitiveAndroidResourceDeps.get(),
            Predicates.not(Predicates.equalTo((HasAndroidResourceDeps) AndroidResource.this))));
}

From source file:additionalpipes.client.gui.GuiTeleportPipe.java

private void updateSlotStrings() {
    showingFreqs = Ints.toArray(Collections2.filter(Ints.asList(clientProps.propFreqMapFreqs.value),
            Predicates.not(Predicates.equalTo(currentFreq))));
    slotFreqNames.setStrings(ImmutableList.copyOf(
            Iterables.filter(Arrays.asList(currentNames), Predicates.not(Predicates.equalTo(currentName)))));
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

static <C, T> Iterator<Swap<T>> oneItemSwapIterator(Schedule<C, T> schedule, IntList startIndices, T item,
        int fromRow) {
    final IntList indices = indices(schedule.routes.get(fromRow), item);
    final ImmutableList.Builder<Iterator<Swap<T>>> iteratorBuilder = ImmutableList.builder();

    Range<Integer> range;// ww  w.java  2s.  c o  m
    if (indices.size() == 1) {
        range = Range.closedOpen(fromRow, fromRow + 1);
    } else {
        range = Range.closedOpen(0, schedule.routes.size());
    }

    for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); i++) {
        int rowSize = schedule.routes.get(i).size();
        if (fromRow == i) {
            rowSize -= indices.size();
        }
        Iterator<IntList> it = new InsertionIndexGenerator(indices.size(), rowSize, startIndices.getInt(i));
        // filter out swaps that have existing result
        if (fromRow == i) {
            it = Iterators.filter(it, Predicates.not(Predicates.equalTo(indices)));
        }
        iteratorBuilder.add(Iterators.transform(it, new IndexToSwapTransform<T>(item, fromRow, i)));
    }
    return Iterators.concat(iteratorBuilder.build().iterator());
}

From source file:org.trancecode.xml.saxon.SaxonBuilder.java

/**
 * Adds a raw XML fragment/* w  w  w  .  j a  va 2 s . c o  m*/
 * 
 * @param raw
 *            The XML fragment
 */
public void raw(final String raw, final Processor processor) {
    Preconditions.checkNotNull(processor);
    Preconditions.checkNotNull(raw);

    final String toBeParsed = "<wrapperElement>" + raw + "</wrapperElement>";
    final XdmNode parsedNode = Saxon.parse(toBeParsed, processor);
    final XdmNode rootNode = Iterables.getOnlyElement(SaxonAxis.childNodes(parsedNode));

    // Re-ask for subnodes as the first childNodes() call will give the
    // wrapperElement element
    final Iterable<XdmNode> subNodesList = SaxonAxis.childNodes(rootNode);
    final Iterable<XdmNode> filteredSubNodesList = Iterables.filter(subNodesList,
            Predicates.not(SaxonPredicates.isIgnorableWhitespace()));

    nodes(filteredSubNodesList);
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.ISEComplexMoveValidator.java

private void checkMoves() {
    for (ISequenceEvent ise : topLevelElements) {
        if (!moveIsValid(ise, true)) {
            valid = false;/*from www. ja  v a 2s.com*/
            eventInError.add(ise);
            // break;
        }
    }

    if (valid) {
        Iterable<ISequenceEvent> otherMovedElements = Iterables.filter(movedElements,
                Predicates.not(Predicates.in(topLevelElements)));
        for (ISequenceEvent ise : otherMovedElements) {
            if (!(ise instanceof Operand) && !moveIsValid(ise, false)) {
                valid = false;
                eventInError.add(ise);
            }
        }
    }

    for (Message resizedMsg : Iterables.concat(startReflexiveMessageToResize, endReflexiveMessageToResize)) {
        boolean currentResizeIsValid = rangeFunction.apply(resizedMsg)
                .width() >= LayoutConstants.MESSAGE_TO_SELF_BENDPOINT_VERTICAL_GAP;
        valid = valid && currentResizeIsValid;
        if (!currentResizeIsValid) {
            eventInError.add(resizedMsg);
        }
    }

    valid = valid && checkConflictesInFinalPositions() && checkTitleZonesInFinalPositions();
}

From source file:com.eucalyptus.auth.euare.UserPrincipalImpl.java

public UserPrincipalImpl(final EuareUser user) throws AuthException {
    final EuareAccount account = user.getAccount();

    final List<PolicyVersion> policies = Lists.newArrayList();
    if (user.isEnabled()) {
        if (user.isAccountAdmin()) {
            policies.add(PolicyVersions.getAdministratorPolicy());
        } else {//from w w w.  j  a v  a  2  s  .co m
            Iterables.addAll(policies, Iterables.transform(user.getPolicies(),
                    PolicyVersions.policyVersion(PolicyScope.User, Accounts.getUserArn(user))));
            for (final EuareGroup group : Iterables.filter(user.getGroups(),
                    Predicates.not(Accounts.isUserGroup()))) {
                Iterables.addAll(policies, Iterables.transform(group.getPolicies(),
                        PolicyVersions.policyVersion(PolicyScope.Group, Accounts.getGroupArn(group))));
            }
        }
        EuareUser admin;
        try {
            admin = account.lookupAdmin();
        } catch (AuthException e) {
            throw new AuthException(e);
        }
        if (admin != null) {
            Iterables.addAll(policies, Iterables.transform(admin.getPolicies(),
                    PolicyVersions.policyVersion(PolicyScope.Account, user.getAccountNumber())));
        }
    }

    this.name = user.getName();
    this.path = user.getPath();
    this.userId = user.getUserId();
    this.authenticatedId = user.getUserId();
    this.canonicalId = account.getCanonicalId();
    this.token = user.getToken();
    this.accountAlias = account.getName();
    this.accountNumber = account.getAccountNumber();
    this.enabled = user.isEnabled();
    this.accountAdmin = user.isAccountAdmin();
    this.systemAdmin = user.isSystemAdmin();
    this.systemUser = user.isSystemUser();
    this.password = user.getPassword();
    this.passwordExpires = password == null ? null
            : Objects.firstNonNull(user.getPasswordExpires(), Long.MAX_VALUE);
    this.keys = ImmutableList.copyOf(
            Iterables.filter(Iterables.transform(user.getKeys(), keyWrapper(this)), AccessKeys.isActive()));
    this.certificates = ImmutableList
            .copyOf(Iterables.filter(user.getCertificates(), propertyPredicate(true, active())));
    this.principalPolicies = ImmutableList.copyOf(policies);
    this.ptag = null;
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.PinnedElementsHandler.java

private boolean hasRemainingSolvableOverlaps() {
    for (IGraphicalEditPart part : fixedEditParts) {
        if (!Collections2.filter(findOverlappingParts(part), Predicates.not(isPinned)).isEmpty()) {
            return true;
        }//  w w w .j a v  a2  s  . c o  m
    }
    return false;
}

From source file:org.apache.brooklyn.entity.nosql.riak.RiakClusterImpl.java

protected void onServerPoolMemberChanged(final Entity member) {
    synchronized (mutex) {
        log.trace("For {}, considering membership of {} which is in locations {}",
                new Object[] { this, member, member.getLocations() });

        Map<Entity, String> nodes = getAttribute(RIAK_CLUSTER_NODES);
        if (belongsInServerPool(member)) {
            // TODO can we discover the nodes by asking the riak cluster, rather than assuming what we add will be in there?
            // TODO and can we do join as part of node starting?

            if (nodes == null) {
                nodes = Maps.newLinkedHashMap();
            }//ww  w .jav a 2 s . c om
            String riakName = getRiakName(member);
            Preconditions.checkNotNull(riakName);

            // flag a first node to be the first node in the riak cluster.
            Boolean firstNode = getAttribute(IS_FIRST_NODE_SET);
            if (!Boolean.TRUE.equals(firstNode)) {
                sensors().set(IS_FIRST_NODE_SET, Boolean.TRUE);

                nodes.put(member, riakName);
                sensors().set(RIAK_CLUSTER_NODES, nodes);

                ((EntityInternal) member).sensors().set(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE);

                log.info("Added initial Riak node {}: {}; {} to new cluster",
                        new Object[] { this, member, getRiakName(member) });
            } else {
                // TODO: be wary of erroneous nodes but are still flagged 'in cluster'
                // add the new node to be part of the riak cluster.
                Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(), Predicates.and(
                        Predicates.instanceOf(RiakNode.class),
                        EntityPredicates.attributeEqualTo(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER, true)));
                if (anyNodeInCluster.isPresent()) {
                    if (!nodes.containsKey(member)
                            && member.getAttribute(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER) == null) {
                        String anyNodeName = anyNodeInCluster.get().getAttribute(RiakNode.RIAK_NODE_NAME);
                        Entities.invokeEffectorWithArgs(this, member, RiakNode.JOIN_RIAK_CLUSTER, anyNodeName)
                                .blockUntilEnded();
                        nodes.put(member, riakName);
                        sensors().set(RIAK_CLUSTER_NODES, nodes);
                        log.info("Added Riak node {}: {}; {} to cluster",
                                new Object[] { this, member, getRiakName(member) });
                    }
                } else {
                    log.error("isFirstNodeSet, but no cluster members found to add {}", member.getId());
                }
            }
        } else {
            if (nodes != null && nodes.containsKey(member)) {
                DependentConfiguration.attributeWhenReady(member, RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER,
                        Predicates.equalTo(false)).blockUntilEnded(Duration.TWO_MINUTES);
                @SuppressWarnings("unchecked")
                Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(),
                        Predicates.and(Predicates.instanceOf(RiakNode.class),
                                EntityPredicates.attributeEqualTo(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER, true),
                                Predicates.not(Predicates.equalTo(member))));
                if (anyNodeInCluster.isPresent()) {
                    Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), RiakNode.REMOVE_FROM_CLUSTER,
                            getRiakName(member)).blockUntilEnded();
                }
                nodes.remove(member);
                sensors().set(RIAK_CLUSTER_NODES, nodes);
                log.info("Removed Riak node {}: {}; {} from cluster",
                        new Object[] { this, member, getRiakName(member) });
            }
        }

        ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this, RIAK_CLUSTER_NODES);

        calculateClusterAddresses();
    }
}

From source file:org.kaaproject.kaa.server.common.nosql.cassandra.dao.EndpointProfileCassandraDao.java

private CassandraEndpointProfile updateProfile(CassandraEndpointProfile profile) {
    LOG.debug("Updating endpoint profile with id {}", profile.getId());
    ByteBuffer epKeyHash = profile.getEndpointKeyHash();
    byte[] keyHash = getBytes(epKeyHash);
    CassandraEndpointProfile storedProfile = findByKeyHash(keyHash);
    if (storedProfile != null) {
        profile = super.save(profile);
        List<Statement> statementList = new ArrayList<>();

        Set<String> oldEndpointGroupIds = getEndpointProfilesGroupIdSet(storedProfile);
        Set<String> newEndpointGroupIds = getEndpointProfilesGroupIdSet(profile);

        Set<String> removeEndpointGroupIds = Sets.filter(oldEndpointGroupIds,
                Predicates.not(Predicates.in(newEndpointGroupIds)));

        Set<String> addEndpointGroupIds = Sets.filter(newEndpointGroupIds,
                Predicates.not(Predicates.in(oldEndpointGroupIds)));
        if (addEndpointGroupIds != null) {
            for (String id : addEndpointGroupIds) {
                statementList.add(cassandraEpByEndpointGroupIdDao
                        .getSaveQuery(new CassandraEpByEndpointGroupId(id, epKeyHash)));
            }/*from ww w .j  a va  2 s.co  m*/

            if (removeEndpointGroupIds != null) {
                for (String id : removeEndpointGroupIds) {
                    statementList.add(delete().from(EP_BY_ENDPOINT_GROUP_ID_COLUMN_FAMILY_NAME)
                            .where(eq(EP_BY_ENDPOINT_GROUP_ID_ENDPOINT_GROUP_ID_PROPERTY, id))
                            .and(eq(EP_BY_ENDPOINT_GROUP_ID_ENDPOINT_KEY_HASH_PROPERTY, epKeyHash)));
                }
            }
            executeBatch(statementList.toArray(new Statement[statementList.size()]));
        } else {
            LOG.error("[{}] Can't update endpoint profile with version {}. "
                    + "Endpoint profile already changed!", profile.getId(), profile.getVersion());
            throw new KaaOptimisticLockingFailureException(
                    "Can't update endpoint profile with" + " version . Endpoint profile already changed!");
        }

        String accessToken = profile.getAccessToken();
        if (storedProfile.getAccessToken() != null && !storedProfile.getAccessToken().equals(accessToken)) {
            cassandraEpByAccessTokenDao.removeById(storedProfile.getAccessToken());
        }
        if (accessToken != null) {
            statementList.add(cassandraEpByAccessTokenDao
                    .getSaveQuery(new CassandraEpByAccessToken(accessToken, epKeyHash)));
        }
        executeBatch(statementList.toArray(new Statement[statementList.size()]));
        LOG.debug("[{}] Endpoint profile updated", profile.getId());
    } else {
        LOG.error("[{}] Stored profile is null. Can't update endpoint profile.", profile.getId());
        throw new DatabaseProcessingException("Stored profile is null. " + "Can't update endpoint profile.");
    }
    return profile;
}