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:org.apache.aurora.common.net.http.handlers.TimeSeriesDataSource.java

@VisibleForTesting
String getResponse(@Nullable String metricsQuery, @Nullable String sinceQuery) throws MetricException {

    if (metricsQuery == null) {
        // Return metric listing.
        return gson.toJson(ImmutableList.copyOf(timeSeriesRepo.getAvailableSeries()));
    }//from www  .  ja  v  a2 s .  c o  m

    List<Iterable<Number>> tsData = Lists.newArrayList();
    tsData.add(timeSeriesRepo.getTimestamps());
    // Ignore requests for "time" since it is implicitly returned.
    Iterable<String> names = Iterables.filter(Splitter.on(",").split(metricsQuery),
            Predicates.not(Predicates.equalTo(TIME_METRIC)));
    for (String metric : names) {
        TimeSeries series = timeSeriesRepo.get(metric);
        if (series == null) {
            JsonObject response = new JsonObject();
            response.addProperty("error", "Unknown metric " + metric);
            throw new MetricException(gson.toJson(response));
        }
        tsData.add(series.getSamples());
    }

    final long since = Long.parseLong(Optional.fromNullable(sinceQuery).or("0"));
    Predicate<List<Number>> sinceFilter = next -> next.get(0).longValue() > since;

    ResponseStruct response = new ResponseStruct(
            ImmutableList.<String>builder().add(TIME_METRIC).addAll(names).build(),
            FluentIterable.from(Iterables2.zip(tsData, 0)).filter(sinceFilter).toList());
    // TODO(wfarner): Let the jax-rs provider handle serialization.
    return gson.toJson(response);
}

From source file:edu.mit.streamjit.util.bytecode.insts.PhiInst.java

public FluentIterable<Value> incomingValues() {
    return operands().filter(Predicates.not(Predicates.instanceOf(BasicBlock.class)));
}

From source file:org.n52.iceland.util.activation.Activatables.java

public static <K, T> Set<K> deactivatedKeys(Map<K, T> map, ActivationProvider<? super K> provider) {
    return Sets.filter(map.keySet(), Predicates.not(asPredicate(provider)));
}

From source file:io.usethesource.criterion.profiler.MemoryFootprintProfiler.java

/**
 * Run this code after a benchmark iteration finished
 *
 * @param benchmarkParams benchmark parameters used for current launch
 * @param iterationParams iteration parameters used for current launch
 * @param result iteration result/*  w w w.  j a v a 2  s .c om*/
 * @return profiler results
 */
@Override
public Collection<? extends Result<ProfilerResult>> afterIteration(BenchmarkParams benchmarkParams,
        IterationParams iterationParams, IterationResult result) {

    try {
        final String benchmarkClassName = benchmarkToClassName(benchmarkParams.getBenchmark());
        final Method factoryMethod = factoryMethod(benchmarkClassName);

        final JmhValue wrappedObject = (JmhValue) factoryMethod.invoke(null,
                initializeArguments(benchmarkParams));
        final Object objectToMeasure = wrappedObject.unwrap();

        final Predicate<Object> predicateDataStructureOverhead = Predicates
                .not(Predicates.instanceOf(JmhValue.class));
        final Predicate<Object> predicateRetainedSize = Predicates.alwaysTrue();

        final List<ProfilerResult> profilerResults = new ArrayList<>();

        /**
         * Traverse object graph for measuring memory footprint (in bytes).
         */
        long memoryInBytes = objectexplorer.MemoryMeasurer.measureBytes(objectToMeasure,
                predicateDataStructureOverhead);

        // NOTE: non-standard constructor for passing ResultRole.PRIMARY
        final ProfilerResult memoryResult = new ProfilerResult(ResultRole.PRIMARY, "memory", memoryInBytes,
                UNIT_BYTES, POLICY);

        // hack: substitute results
        result.resetResults();
        result.addResult(memoryResult);

        //      /**
        //       * Traverse object graph for measuring field statistics.
        //       */
        //      final Footprint statistic = objectexplorer.ObjectGraphMeasurer
        //          .measure(objectToMeasure, predicateDataStructureOverhead);
        //
        //      final ProfilerResult objectsResult =
        //          new ProfilerResult("objects", statistic.getObjects(), UNIT_COUNT, POLICY);
        //      profilerResults.add(objectsResult);
        //
        //      final ProfilerResult referencesResult =
        //          new ProfilerResult("references", statistic.getReferences(), UNIT_COUNT, POLICY);
        //      profilerResults.add(referencesResult);
        //
        //      final ProfilerResult primitivesResult =
        //          new ProfilerResult("primitives", statistic.getPrimitives().size(), UNIT_COUNT, POLICY);
        //      profilerResults.add(primitivesResult);

        return profilerResults;
    } catch (Exception e) {
        e.printStackTrace();
        return Arrays.asList();
    }
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.commands.emf.PasteFromSiriusClipboardCommand.java

private void prepareClipboard() {
    // Initiate current domain clipboard from viewpoint multi session
    // clipboard//from   w  w w.j a v a2s  .  c o  m
    SiriusClipboardManager.getInstance().setDomainClipboard(domain);
    clipboard = domain.getClipboard();

    // and filter DElements
    if (clipboard != null) {
        clipboard = Lists.newArrayList(
                Iterables.filter(clipboard, Predicates.not(Predicates.instanceOf(DSemanticDecorator.class))));
    }

    // add to current domain clipboard
    domain.setClipboard(clipboard);
}

From source file:com.google.errorprone.bugpatterns.PrivateConstructorForUtilityClass.java

@Override
public Description matchClass(ClassTree classTree, VisitorState state) {
    if (!classTree.getKind().equals(CLASS)) {
        return NO_MATCH;
    }/*  w  w  w . j  ava2 s .  co  m*/

    FluentIterable<? extends Tree> nonSyntheticMembers = FluentIterable.from(classTree.getMembers())
            .filter(Predicates.not(new Predicate<Tree>() {
                @Override
                public boolean apply(Tree tree) {
                    return tree.getKind().equals(METHOD) && isGeneratedConstructor((MethodTree) tree);
                }
            }));
    if (nonSyntheticMembers.isEmpty()) {
        return NO_MATCH;
    }
    boolean isUtilityClass = nonSyntheticMembers.allMatch(new Predicate<Tree>() {
        @Override
        public boolean apply(Tree tree) {
            switch (tree.getKind()) {
            case CLASS:
                return ((ClassTree) tree).getModifiers().getFlags().contains(STATIC);
            case METHOD:
                return ((MethodTree) tree).getModifiers().getFlags().contains(STATIC);
            case VARIABLE:
                return ((VariableTree) tree).getModifiers().getFlags().contains(STATIC);
            case BLOCK:
                return ((BlockTree) tree).isStatic();
            case ENUM:
            case ANNOTATION_TYPE:
            case INTERFACE:
                return true;
            default:
                throw new AssertionError("unknown member type:" + tree.getKind());
            }
        }
    });
    if (!isUtilityClass) {
        return NO_MATCH;
    }
    return describeMatch(classTree,
            addMembers(classTree, state, "private " + classTree.getSimpleName() + "() {}"));
}

From source file:nerds.antelax.commons.net.pubsub.PubSubServerContextListener.java

@Override
public synchronized void contextInitialized(final ServletContextEvent ctx) {
    final ServletContext sc = ctx.getServletContext();
    final Collection<InetSocketAddress> cluster = sc != null ? NetUtil.hostPortPairsFromString(
            sc.getInitParameter(CLUSTER_INIT_PARAM), PubSubServer.DEFAULT_ADDRESS.getPort()) : EMPTY;
    REMOTE_SERVERS.set(Collections2.filter(cluster, Predicates.not(NetUtil.machineLocalSocketAddress())));
    if (Iterables.any(cluster, NetUtil.machineLocalSocketAddress())) {
        server = new PubSubServer(cluster);
        ctx.getServletContext()/*from  w  ww .j  av a2 s .c o  m*/
                .log("Starting PubSub server, this machine is part of the cluster definition[" + cluster + "]");
        server.start();
    } else {
        server = null;
        ctx.getServletContext()
                .log("No PubSub server started, remotes available for final clients are " + remoteServers());
    }
}

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

public Optional<Team> findFirstEmptyTeam() {
    return Iterables.tryFind(teams.values(), Predicates.not(FunctionalUtil.TEAMS_WITH_PLAYERS));
}

From source file:io.druid.sql.calcite.rule.DruidSemiJoinRule.java

private DruidSemiJoinRule() {
    super(operand(Project.class,
            operand(Join.class, null, IS_LEFT_OR_INNER,
                    some(operand(DruidRel.class, null, Predicates.not(IS_GROUP_BY), any()),
                            operand(DruidRel.class, null, IS_GROUP_BY, any())))));
}

From source file:org.apache.gobblin.data.management.conversion.hive.watermarker.TableLevelWatermarker.java

public TableLevelWatermarker(State state) {
    this.tableWatermarks = Maps.newHashMap();

    // Load previous watermarks in case of sourceState
    if (state instanceof SourceState) {
        SourceState sourceState = (SourceState) state;
        for (Map.Entry<String, Iterable<WorkUnitState>> datasetWorkUnitStates : sourceState
                .getPreviousWorkUnitStatesByDatasetUrns().entrySet()) {

            // Use the minimum of all previous watermarks for this dataset
            List<LongWatermark> previousWatermarks = FluentIterable.from(datasetWorkUnitStates.getValue())
                    .filter(Predicates.not(PartitionLevelWatermarker.WATERMARK_WORKUNIT_PREDICATE))
                    .transform(new Function<WorkUnitState, LongWatermark>() {
                        @Override
                        public LongWatermark apply(WorkUnitState w) {
                            return w.getActualHighWatermark(LongWatermark.class);
                        }/*w w w .j ava 2 s.  c o m*/
                    }).toList();

            if (!previousWatermarks.isEmpty()) {
                this.tableWatermarks.put(datasetWorkUnitStates.getKey(), Collections.min(previousWatermarks));
            }
        }
        log.debug("Loaded table watermarks from previous state " + this.tableWatermarks);
    }
}