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.google.api.tools.framework.importers.swagger.SwaggerImportTool.java

private void printDiagnostics(List<Diag> list) {
    Predicate<Diag> error = new Predicate<Diag>() {
        @Override//from   ww w  .  j  av  a2s.  c o  m
        public boolean apply(Diag input) {
            return input.getKind() == Kind.ERROR;
        }
    };

    String errors = Joiner.on("\n  ").join(Iterables.filter(list, error));
    String warnings = Joiner.on("\n  ").join(Iterables.filter(list, Predicates.not(error)));

    if (!errors.isEmpty()) {
        System.out.printf("\nConversion encountered ERRORS:\n  %s\n", errors);
    }
    if (!warnings.isEmpty()) {
        System.out.printf("\nConversion encountered warnings:\n  %s\n", warnings);
    }
}

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

/**
 * Giving a null or empty argument starts a local server. If a non-null, non-empty argument is given then start a server,
 * listening to all local socket addresses in the argument. Any non-local socket addresses are considered remote peer servers.
 * //from w w w .j a  v  a  2s  . co  m
 * @throws IllegalArgumentException
 *             if the {@link Collection} argument is not empty but contains no local addresses to bind to
 */
public PubSubServer(final Collection<InetSocketAddress> clusterDefinition) {
    final Collection<InetSocketAddress> localAddrs = clusterDefinition != null
            ? Collections2.filter(clusterDefinition, NetUtil.machineLocalSocketAddress())
            : new LinkedList<InetSocketAddress>();
    final Collection<InetSocketAddress> remoteAddrs = clusterDefinition != null
            ? Collections2.filter(clusterDefinition, Predicates.not(NetUtil.machineLocalSocketAddress()))
            : new LinkedList<InetSocketAddress>();
    if (clusterDefinition == null || clusterDefinition.isEmpty())
        localAddrs.add(DEFAULT_ADDRESS);
    else
        Preconditions.checkArgument(!localAddrs.isEmpty(),
                "Attempt to start a server on a machine that is not part of the cluster definition");

    listenAddresses = Collections.unmodifiableCollection(localAddrs);
    openChannels = new DefaultChannelGroup(getClass().getName());
    bossService = Executors.newCachedThreadPool();
    workerService = Executors.newCachedThreadPool();
    factory = new NioServerSocketChannelFactory(bossService, workerService);
    bootstrap = new ServerBootstrap(factory);
    final UUID ourServerID = UUID.randomUUID();
    logger.info("New server created with ID: {}", ourServerID);
    sharedMessageHandler = new ServerMessageHandler(new Predicate<Object>() {

        @Override
        public boolean apply(final Object o) {
            if (o instanceof Message) {
                final Message m = (Message) o;
                return m.ttl() > 0 && !m.serverID().equals(ourServerID);
            } else
                return true;
        }

    }, Collections.unmodifiableCollection(remoteAddrs));
    final ChannelDownstreamHandler uuidPopulatingHandler = new SimpleChannelDownstreamHandler() {

        @Override
        public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
            final Object o = e.getMessage();
            if (o instanceof Message) {
                final Message m = (Message) o;
                if (m.serverID() == null || m.serverID().equals(Message.NO_UUID))
                    m.serverID(ourServerID);
            }
            super.writeRequested(ctx, e);
        }

    };
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() {
            return Channels.pipeline(MessageCodec.decoder(), MessageCodec.encoder(), uuidPopulatingHandler,
                    sharedMessageHandler);
        }

    });
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
}

From source file:controllers.modules.base.Module.java

public <T extends ViewModel> T findViewModel(Class<T> viewModelClass, Iterable<ViewModel> exclude,
        T defaultViewModel) {/*from  www. j  a v  a2s.  co  m*/
    exclude = ObjectUtils.defaultIfNull(exclude, Lists.<ViewModel>newArrayList());
    return Iterables.getFirst(
            Iterables.filter(Iterables.filter(this.viewModels,
                    Predicates.not(Predicates.in(Lists.newArrayList(exclude)))), viewModelClass),
            defaultViewModel);
}

From source file:com.google.cloud.dataflow.sdk.runners.worker.KeyedWorkItem.java

public Iterable<TimerData> timersIterable() {
    FluentIterable<Timer> allTimers = FluentIterable.from(workItem.getTimers().getTimersList());
    FluentIterable<Timer> eventTimers = allTimers.filter(IS_WATERMARK);
    FluentIterable<Timer> nonEventTimers = allTimers.filter(Predicates.not(IS_WATERMARK));
    return eventTimers.append(nonEventTimers).transform(new Function<Timer, TimerData>() {
        private TimeDomain getTimeDomain(Windmill.Timer.Type type) {
            switch (type) {
            case REALTIME:
                return TimeDomain.PROCESSING_TIME;
            case DEPENDENT_REALTIME:
                return TimeDomain.SYNCHRONIZED_PROCESSING_TIME;
            case WATERMARK:
                return TimeDomain.EVENT_TIME;
            default:
                throw new IllegalArgumentException("Unsupported timer type " + type);
            }//ww  w .ja va2 s .c om
        }

        @Override
        public TimerData apply(Timer timer) {
            String tag = timer.getTag().toStringUtf8();
            String namespaceString = tag.substring(0, tag.indexOf('+'));
            StateNamespace namespace = StateNamespaces.fromString(namespaceString, windowCoder);

            Instant timestamp = new Instant(TimeUnit.MICROSECONDS.toMillis(timer.getTimestamp()));
            return TimerData.of(namespace, timestamp, getTimeDomain(timer.getType()));
        }
    });
}

From source file:com.eucalyptus.cloudwatch.common.CloudWatchResourceName.java

public static Set<String> simpleNames(final Iterable<String> namesAndArns) {
    return Sets.newHashSet(Iterables.filter(namesAndArns, Predicates.not(isResourceName())));
}

From source file:com.twitter.crunch.BaseRackIsolationPlacementRules.java

/**
 * Use the predicate to reject already selected racks.
 *//*w  ww.ja  v  a2s.co  m*/
private Predicate<Node> getRackPredicate(Set<Node> selectedRacks) {
    return Predicates.not(Predicates.in(selectedRacks));
}

From source file:org.sosy_lab.cpachecker.util.refinement.PathExtractor.java

/**
 * This method returns an unsorted, non-empty collection of target states
 * found during the analysis.//from   w ww  .  ja  v a2 s.  c  om
 *
 * @param pReached the set of reached states
 * @return the target states
 * @throws org.sosy_lab.cpachecker.exceptions.RefinementFailedException
 */
public Collection<ARGState> getTargetStates(final ARGReachedSet pReached) throws RefinementFailedException {

    // extract target locations from and exclude those found to be feasible before,
    // e.g., when analysis.stopAfterError is set to false
    List<ARGState> targets = extractTargetStatesFromArg(pReached)
            .filter(Predicates.not(Predicates.in(feasibleTargets))).toList();

    // set of targets may only be empty, if all of them were found feasible previously
    if (targets.isEmpty()) {
        assert feasibleTargets.containsAll(extractTargetStatesFromArg(pReached).toSet());

        throw new RefinementFailedException(Reason.RepeatedCounterexample,
                ARGUtils.getOnePathTo(Iterables.getLast(feasibleTargets)));
    }

    logger.log(Level.FINEST, "number of targets found: " + targets.size());

    targetCounter = targetCounter + targets.size();

    return targets;
}

From source file:eu.interedition.text.xml.ConverterBuilder.java

public Converter build() {
    final List<StreamFilter> filters = Lists.newLinkedList();

    if (nodePathTracker != null) {
        filters.add(nodePathTracker);//from w w  w .j  a va 2 s. c  o  m
    }

    Iterable<ConversionFilter> textStreamFilters = Iterables.filter(this.filters, ConversionFilter.class);

    Iterables.addAll(filters, Iterables.filter(textStreamFilters, ConversionFilter.BEFORE_TEXT_GENERATION));

    if (offsetMapper != null) {
        filters.add(offsetMapper);
    }
    if (whitespaceCompressor != null) {
        filters.add(whitespaceCompressor);
    }

    Iterables.addAll(filters,
            Iterables.filter(textStreamFilters, Predicates.not(ConversionFilter.BEFORE_TEXT_GENERATION)));
    Iterables.addAll(filters,
            Iterables.filter(this.filters, Predicates.not(Predicates.instanceOf(ConversionFilter.class))));

    return new Converter(whitespaceCompressor, offsetMapper, namespaceMapping, filters).add(listeners);
}

From source file:com.eucalyptus.loadbalancing.config.LoadBalancingServiceBuilder.java

@SuppressWarnings("unchecked")
private boolean noOtherEnabled(final ServiceConfiguration config) {
    return Iterables.isEmpty(ServiceConfigurations.filter(LoadBalancing.class,
            Predicates.and(ServiceConfigurations.filterHostLocal(), ServiceConfigurations.filterEnabled(),
                    Predicates.not(Predicates.equalTo(config)))));
}

From source file:com.facebook.buck.query.DepsFunction.java

/**
 * Evaluates to the dependencies of the argument.
 * Breadth first search from the given argument until there are no more unvisited nodes in the
 * transitive closure or the maximum depth (if supplied) is reached.
 *//*from   w  w  w.  j av a  2 s . c  om*/
@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    Set<QueryTarget> argumentSet = args.get(0).getExpression().eval(env, executor);
    int depthBound = args.size() > 1 ? args.get(1).getInteger() : Integer.MAX_VALUE;
    env.buildTransitiveClosure(argumentSet, depthBound, executor);

    // LinkedHashSet preserves the order of insertion when iterating over the values.
    // The order by which we traverse the result is meaningful because the dependencies are
    // traversed level-by-level.
    Set<QueryTarget> result = new LinkedHashSet<>();
    Set<QueryTarget> current = argumentSet;

    // Iterating depthBound+1 times because the first one processes the given argument set.
    for (int i = 0; i <= depthBound; i++) {
        Set<QueryTarget> next = env.getFwdDeps(Iterables.filter(current, Predicates.not(result::contains)));
        result.addAll(current);
        if (next.isEmpty()) {
            break;
        }
        current = next;
    }
    return result;
}