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:clocker.mesos.entity.MesosClusterImpl.java

@Override
public void init() {
    LOG.info("Starting Mesos cluster id {}", getId());
    registerLocationResolver();/*  w w w.jav  a 2  s  . co  m*/
    super.init();

    Group slaves = addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Slaves"));

    Group frameworks = addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Frameworks"));

    DynamicGroup tasks = addChild(EntitySpec.create(DynamicGroup.class)
            .configure(DynamicGroup.ENTITY_FILTER,
                    Predicates.and(Predicates.instanceOf(MesosTask.class),
                            EntityPredicates.attributeEqualTo(MesosAttributes.MESOS_CLUSTER, this)))
            .displayName("Mesos Tasks"));

    DynamicMultiGroup applications = addChild(EntitySpec.create(DynamicMultiGroup.class)
            .configure(DynamicMultiGroup.ENTITY_FILTER,
                    Predicates.and(MesosUtils.sameCluster(this),
                            Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId()))))
            .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L)
            .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() {
                @Override
                public String apply(@Nullable Entity input) {
                    return input.getApplication().getDisplayName() + ":" + input.getApplicationId();
                }
            }).configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(BasicGroup.class))
            .displayName("Mesos Applications"));

    if (config().get(SDN_ENABLE) && config().get(SDN_PROVIDER_SPEC) != null) {
        EntitySpec entitySpec = EntitySpec.create(config().get(SDN_PROVIDER_SPEC));
        entitySpec.configure(MesosAttributes.MESOS_CLUSTER, this);
        Entity sdn = addChild(entitySpec);
        sensors().set(SDN_PROVIDER, sdn);
    }

    sensors().set(MESOS_SLAVES, slaves);
    sensors().set(MESOS_FRAMEWORKS, frameworks);
    sensors().set(MESOS_TASKS, tasks);
    sensors().set(MESOS_APPLICATIONS, applications);

    // Override the health-check: just interested in the slaves, frameworks and sdn (rather than 
    // the groups that show the tasks or apps).
    Entity sdn = sensors().get(SDN_PROVIDER);
    enrichers().add(EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class)
            .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG)
            .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true)
            .configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER,
                    Predicates.or(ImmutableList.of(Predicates.<Entity>equalTo(slaves),
                            Predicates.<Entity>equalTo(frameworks),
                            (sdn == null ? Predicates.<Entity>alwaysFalse() : Predicates.equalTo(sdn))))));
}

From source file:edu.buaa.satla.analysis.core.algorithm.CounterexampleCheckAlgorithm.java

@Override
public boolean run(ReachedSet reached) throws CPAException, InterruptedException {
    boolean sound = true;

    while (reached.hasWaitingState()) {
        sound &= algorithm.run(reached);
        assert ARGUtils.checkARG(reached);

        ARGState lastState = (ARGState) reached.getLastState();

        Deque<ARGState> errorStates = new ArrayDeque<>();
        if (lastState != null && lastState.isTarget()) {
            errorStates.add(lastState);//from   w ww  .  j av a2s  .  c  o m
        } else {
            from(reached).transform(AbstractStates.toState(ARGState.class))
                    .filter(AbstractStates.IS_TARGET_STATE)
                    .filter(Predicates.not(Predicates.in(checkedTargetStates))).copyInto(errorStates);
        }

        if (errorStates.isEmpty()) {
            // no errors, so no analysis necessary
            break;
        }

        // check counterexample
        checkTime.start();
        try {
            boolean foundCounterexample = false;
            while (!errorStates.isEmpty()) {
                ARGState errorState = errorStates.pollFirst();
                if (!reached.contains(errorState)) {
                    // errorState was already removed due to earlier loop iterations
                    continue;
                }

                sound = checkCounterexample(errorState, reached, sound);
                if (reached.contains(errorState)) {
                    checkedTargetStates.add(errorState);
                    foundCounterexample = true;
                }
            }

            if (foundCounterexample) {
                break;
            }
        } finally {
            checkTime.stop();
        }
    }
    return sound;
}

From source file:util.selenium.LazyShould.java

private LazyShould verify(String message, Predicate<List<WebElement>> predicate,
        Function<List<WebElement>, String> toErrorMessage) {
    String verification = "verify that " + element + " " + message;
    System.out.println("   -> " + verification);

    try {/*  w ww .  j a va 2 s .  co m*/
        if (!retry.verify(new Supplier<List<WebElement>>() {
            @Override
            public List<WebElement> get() {
                return LazyShould.this.findElements();
            }
        }, ok ? predicate : Predicates.not(predicate))) {
            throw Failure.create("Failed to " + verification + ". " + toErrorMessage.apply(findElements()));
        }
    } catch (NoSuchElementException e) {
        throw Failure.create("Element not found. Failed to " + verification);
    }

    return ok ? this : not();
}

From source file:brooklyn.entity.database.mysql.MySqlClusterImpl.java

@Override
protected void initEnrichers() {
    super.initEnrichers();
    propagateMasterAttribute(MySqlNode.HOSTNAME);
    propagateMasterAttribute(MySqlNode.ADDRESS);
    propagateMasterAttribute(MySqlNode.SUBNET_HOSTNAME);
    propagateMasterAttribute(MySqlNode.SUBNET_ADDRESS);
    propagateMasterAttribute(MySqlNode.MYSQL_PORT);
    propagateMasterAttribute(MySqlNode.DATASTORE_URL);

    addEnricher(Enrichers.builder().aggregating(MySqlNode.DATASTORE_URL).publishing(SLAVE_DATASTORE_URL_LIST)
            .computing(Functions.<Collection<String>>identity()).entityFilter(Predicates.not(IS_MASTER))
            .fromMembers().build());/* ww  w  .  jav  a 2 s  .  c  o m*/

    addEnricher(Enrichers.builder().aggregating(MySqlNode.QUERIES_PER_SECOND_FROM_MYSQL)
            .publishing(QUERIES_PER_SECOND_FROM_MYSQL_PER_NODE).fromMembers().computingAverage()
            .defaultValueForUnreportedSensors(0d).build());
}

From source file:org.apache.brooklyn.entity.database.mysql.MySqlClusterImpl.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   w w  w .  java 2s . c o m*/
protected void initEnrichers() {
    super.initEnrichers();
    propagateMasterAttribute(MySqlNode.HOSTNAME);
    propagateMasterAttribute(MySqlNode.ADDRESS);
    propagateMasterAttribute(MySqlNode.SUBNET_HOSTNAME);
    propagateMasterAttribute(MySqlNode.SUBNET_ADDRESS);
    propagateMasterAttribute(MySqlNode.MYSQL_PORT);
    propagateMasterAttribute(MySqlNode.DATASTORE_URL);

    enrichers()
            .add(Enrichers.builder().aggregating(MySqlNode.DATASTORE_URL).publishing(SLAVE_DATASTORE_URL_LIST)
                    .computing((Function<Collection<String>, List<String>>) (Function) Functions.identity())
                    .entityFilter(Predicates.not(MySqlClusterUtils.IS_MASTER)).fromMembers().build());

    enrichers().add(Enrichers.builder().aggregating(MySqlNode.QUERIES_PER_SECOND_FROM_MYSQL)
            .publishing(QUERIES_PER_SECOND_FROM_MYSQL_PER_NODE).fromMembers().computingAverage()
            .defaultValueForUnreportedSensors(0d).build());
}

From source file:gg.uhc.uhc.modules.team.RandomTeamsCommand.java

@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    int size = -1;
    int count = -1;

    if (options.has(teamCountSpec)) {
        count = teamCountSpec.value(options);
    }/*from ww w .  jav a 2s .  c om*/

    if (options.has(teamSizeSpec)) {
        size = teamSizeSpec.value(options);
    }

    if ((size == -1 && count == -1) || (size != -1 && count != -1)) {
        sender.sendMessage(messages.getRaw("count or size"));
        return true;
    }

    Set<Player> choice = Sets.newHashSet(playersSpec.values(options));

    // if none are provided then add all online players
    if (choice.size() == 0) {
        choice = Sets.newHashSet(Bukkit.getOnlinePlayers());
    }

    // parse excludes into online players
    Set<Player> excludes = Sets.newHashSet(
            Iterables.filter(Iterables.transform(excludingSpec.values(options), FunctionalUtil.ONLINE_VERSION),
                    Predicates.notNull()));

    // final list with excludes removed and players that already in a team
    List<Player> toAssign = Lists
            .newArrayList(Iterables.filter(Sets.difference(choice, excludes), Predicates.not(PLAYER_HAS_TEAM)));

    if (toAssign.size() == 0) {
        sender.sendMessage(messages.getRaw("no players"));
        return true;
    }

    Collections.shuffle(toAssign);

    // calculate team sizes to fit in count teams and assign it to size and carry on as if it was a sized command
    if (count != -1) {
        size = (int) Math.ceil((double) toAssign.size() / (double) count);
    }

    // partition into teams
    List<List<Player>> teams = Lists.newArrayList(Lists.partition(toAssign, size));

    int extras = toAssign.size() % size;

    // if we're excluding leftovers and there were leftovers in a final
    // team, then remove that team from the list. If it's the only team
    // then send a message saying no teams could be created.
    if (options.has(excludeExtrasSpec) && extras > 0) {
        if (teams.size() == 1) {
            sender.sendMessage(messages.evalTemplate("not enough players", ImmutableMap.of("size", size)));
            return true;
        }

        teams.remove(teams.size() - 1);
    }

    // start assigning teams
    for (List<Player> teamPlayers : teams) {
        Optional<Team> optional = module.findFirstEmptyTeam();

        if (!optional.isPresent()) {
            sender.sendMessage(messages.getRaw("not enough teams"));
            return true;
        }

        Team team = optional.get();
        String playerNames = Joiner.on(", ")
                .join(Iterables.transform(teamPlayers, FunctionalUtil.PLAYER_NAME_FETCHER));

        //"teamup notification" : ${colours.command}"You were teamed up into the team {{prefix}}{{name}}"${colours.reset}${colours.command}" with: "${colours.secondary}"{{players}}";

        Map<String, String> context = ImmutableMap.<String, String>builder().put("prefix", team.getPrefix())
                .put("name", team.getName()).put("display name", team.getDisplayName())
                .put("players", playerNames).build();

        String message = messages.evalTemplate("teamup notification", context);

        // add each player
        for (Player player : teamPlayers) {
            team.addPlayer(player);
            player.sendMessage(message);
        }
    }

    Map<String, Integer> context = ImmutableMap.<String, Integer>builder().put("count", teams.size())
            .put("size", teams.get(0).size()).put("players", toAssign.size()).build();

    sender.sendMessage(messages.evalTemplate("created", context));

    if (options.has(excludeExtrasSpec) && extras > 0) {
        sender.sendMessage(messages.evalTemplate("extras notice", ImmutableMap.of("extras", extras)));
    }

    return true;
}

From source file:tile80.tile80.Tile80.java

public Tile80 removeBehavior(Behavior80 behavior) {
    return new Tile80Eager(getPos(), getId(), getTags(),
            FluentIterable.from(getBehavior()).filter(Predicates.not(Predicates.equalTo(behavior))),
            getKeyspace());//  www.j a  v a  2 s.c  om
}

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

/**
 * Performs all the computations required to validate the resizing, and
 * stores any important information which will be useful to actually execute
 * the resize if it is valid, like for example avoid contact with siblings.
 *//*  ww  w  . ja  va2s  .co  m*/
protected void validate() {
    valid = checkAndComputeRanges();
    if (valid) {
        Collection<ISequenceEvent> finalParents = getFinalParentsWithAutoExpand();

        Collection<ISequenceEvent> movableParents = Lists
                .newArrayList(Iterables.filter(finalParents, Predicates.not(unMove)));
        Collection<ISequenceEvent> fixedParents = Lists.newArrayList(Iterables.filter(finalParents, unMove));
        if (movableParents.isEmpty() || !movedElements.containsAll(movableParents)) {

            valid = valid && Iterables.isEmpty(Iterables.filter(finalParents, invalidParents));
            valid = valid && (!Iterables.any(finalParents, Predicates.instanceOf(Operand.class))
                    || finalParents.size() == 1);
            valid = valid && checkFinalRangeStrictlyIncludedInParents(movableParents);
            valid = valid && checkLocalSiblings(movableParents);
        }
        valid = valid && checkFinalRangeStrictlyIncludedInParents(fixedParents);
        valid = valid && checkLocalSiblings(fixedParents);
    }

    if (getRequestQuery().isResize()) {
        valid = valid && checkGlobalPositions();
    }
}

From source file:org.apache.isis.core.runtime.userprofile.UserProfileLoaderDefault.java

private UserProfile createDefaultProfile(final String userName) {
    final UserProfile profile = new UserProfile();
    profile.newPerspective(/*from   ww w  . j  a  va 2  s  .c o m*/
            DEFAULT_PERSPECTIVE_NAME + (IsisContext.getDeploymentType().isExploring() ? EXPLORATION : ""));

    final List<Object> singletonServices = Lists.newArrayList(
            Iterables.filter(getServices(), Predicates.not(RequestScopedService.Predicates.instanceOf())));
    if (singletonServices.size() == 0 && mode == Mode.STRICT) {
        throw new IsisException("No known (singleton) services");
    }
    for (final Object service : singletonServices) {
        profile.getPerspective().addToServices(service);
    }
    LOG.debug("creating exploration UserProfile for " + userName);
    return profile;
}

From source file:com.twitter.common.application.AppLauncher.java

/**
 * Used to launch an application with a restricted set of {@literal @CmdLine} {@link Arg}s
 * considered for parsing.  This is useful if the classpath includes annotated fields you do not
 * wish arguments to be parsed for.//from  w w  w. ja v a  2s. c o m
 *
 * @param appClass The application class to instantiate and launch.
 * @param argFilter A filter that selects the {@literal @CmdLine} {@link Arg}s to enable for
 *     parsing.
 * @param args The command line arguments to parse.
 * @see ArgFilters
 */
public static void launch(Class<? extends Application> appClass, Predicate<Field> argFilter,
        List<String> args) {
    Preconditions.checkNotNull(appClass);
    Preconditions.checkNotNull(argFilter);
    Preconditions.checkNotNull(args);

    parseArgs(Predicates.<Field>and(Predicates.not(SELECT_APP_CLASS), argFilter), args);
    try {
        new AppLauncher().run(appClass.newInstance());
    } catch (InstantiationException e) {
        throw new IllegalStateException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
}