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

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

Introduction

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

Prototype

public static <T> Predicate<T> or(Predicate<? super T>... components) 

Source Link

Document

Returns a predicate that evaluates to true if any one of its components evaluates to true .

Usage

From source file:org.sonatype.nexus.plugins.capabilities.internal.rest.StoresResource.java

private Predicate<Repository> hasNoneOfContentClasses(final List<String> contentClasses) {
    if (contentClasses != null && !contentClasses.isEmpty()) {
        List<Predicate<Repository>> predicates = Lists.newArrayList();
        for (final String contentClass : contentClasses) {
            if (StringUtils.isNotEmpty(contentClass) && contentClass.startsWith("!")) {
                predicates.add(new Predicate<Repository>() {
                    @Override/*from w ww .j av a2s. c  o  m*/
                    public boolean apply(@Nullable final Repository input) {
                        return input != null
                                && !input.getRepositoryContentClass().getId().equals(contentClass.substring(1));
                    }
                });
            }
        }
        if (!predicates.isEmpty()) {
            return Predicates.or(predicates);
        }
    }
    return null;
}

From source file:com.eucalyptus.ws.WebServices.java

public static synchronized void restart() {
    if (serverShutdown != null) {
        serverShutdown.run();//ww w .j ava 2s.c om
        serverShutdown = null;
    }
    final Executor workerPool = workerPool();
    final ChannelFactory serverChannelFactory = channelFactory(workerPool);
    final ChannelPipelineFactory serverPipelineFactory = Handlers.serverPipelineFactory();
    final ChannelGroup serverChannelGroup = channelGroup();
    final ChannelHandler channelGroupHandler = new ChannelGroupChannelHandler(serverChannelGroup);
    final ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = serverPipelineFactory.getPipeline();
            pipeline.addLast("channel-group-handler", channelGroupHandler);
            return pipeline;
        }
    };
    final ServerBootstrap bootstrap = serverBootstrap(serverChannelFactory, pipelineFactory);

    final List<Pair<InetAddress, Integer>> internalAddressAndPorts = Arrays.asList(
            Pair.pair(Internets.localHostInetAddress(), StackConfiguration.INTERNAL_PORT),
            Pair.pair(Internets.loopback(), StackConfiguration.INTERNAL_PORT));
    final Set<Pair<InetAddress, Integer>> listenerAddressAndPorts = Sets.newLinkedHashSet();
    listenerAddressAndPorts.addAll(internalAddressAndPorts);
    if (Bootstrap.isOperational()) { // skip additional listeners until bootstrapped
        Iterables.addAll(listenerAddressAndPorts, Iterables.transform(
                Iterables.filter(
                        Iterables.concat(Collections.singleton(Internets.any()),
                                Internets.getAllInetAddresses()),
                        Predicates.or(parse(Cidr.parse(), StackConfiguration.LISTENER_ADDRESS_MATCH))),
                CollectionUtils.flipCurried(Pair.<InetAddress, Integer>pair()).apply(StackConfiguration.PORT)));
    }
    if (listenerAddressAndPorts.contains(Pair.pair(Internets.any(), StackConfiguration.INTERNAL_PORT))) {
        listenerAddressAndPorts.removeAll(internalAddressAndPorts);
    }
    LOG.info("Starting web services listeners on " + Joiner.on(',')
            .join(Iterables.transform(listenerAddressAndPorts, Pair.<InetAddress, Integer>left())));
    for (final Pair<InetAddress, Integer> listenerAddressAndPort : listenerAddressAndPorts) {
        final InetAddress address = listenerAddressAndPort.getLeft();
        final int port = listenerAddressAndPort.getRight();
        try {
            final Channel serverChannel = bootstrap.bind(new InetSocketAddress(address, port));
            serverChannelGroup.add(serverChannel);
        } catch (ChannelException ex) {
            LOG.error("Unable to bind web services listener " + address + ":" + port
                    + ", port may be already in use.");
            Logs.extreme().error(ex, ex);
        }
    }
    try {
        serverShutdown = new Runnable() {
            AtomicBoolean ranned = new AtomicBoolean(false);

            @Override
            public void run() {
                if (this.ranned.compareAndSet(false, true)) {
                    serverChannelGroup.close().awaitUninterruptibly();
                    serverChannelFactory.releaseExternalResources();
                }
            }
        };
        OrderedShutdown.registerPreShutdownHook(serverShutdown);
    } catch (Exception ex) {
        LOG.error(ex, ex);
    }

}

From source file:com.eucalyptus.blockstorage.SnapshotManager.java

private static boolean isReservedSnapshot(final String snapshotId) {
    // Fix for EUCA-4932. Any snapshot associated with an (available or pending) image as a root/non-root device is a reserved snapshot
    // and can't be deleted without first unregistering the image
    return Predicates.or(SnapshotInUseVerifier.INSTANCE).apply(snapshotId);
}

From source file:org.immutables.value.processor.meta.ValueType.java

public List<ValueAttribute> getImplementedAttributes() {
    if (implementedAttributes == null) {
        implementedAttributes = attributes()
                .filter(Predicates.or(Arrays.asList(ValueAttributeFunctions.isGenerateAbstract(),
                        ValueAttributeFunctions.isGenerateDefault(),
                        ValueAttributeFunctions.isGenerateDerived())))
                .toList();//from w ww .  j  av  a  2  s . c o  m
    }
    return implementedAttributes;
}

From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java

/**
 * Generate a Filter for the given filters.
 *
 * @param filters The map of filter names to (multiple) values
 * @param allowInternalFilters True to allow use of internal filters
 * @return The filter representation/* ww w  . j  av a2 s.  c o  m*/
 * @throws InvalidFilterException If a filter is invalid
 */
public Filter generate(final Map<String, Set<String>> filters, final boolean allowInternalFilters,
        final String accountId) throws InvalidFilterException {
    // Construct collection filter
    final List<Predicate<Object>> and = Lists.newArrayList();
    for (final Map.Entry<String, Set<String>> filter : Iterables.filter(filters.entrySet(),
            Predicates.not(isTagFilter()))) {
        final List<Predicate<Object>> or = Lists.newArrayList();
        for (final String value : filter.getValue()) {
            final Function<? super String, Predicate<? super RT>> predicateFunction = predicateFunctions
                    .get(filter.getKey());
            if (predicateFunction == null
                    || (!allowInternalFilters && internalFilters.contains(filter.getKey()))) {
                throw InvalidFilterException.forName(filter.getKey());
            }
            final Predicate<? super RT> valuePredicate = predicateFunction.apply(value);
            or.add(typedPredicate(valuePredicate));
        }
        and.add(Predicates.or(or));
    }

    // Construct database filter and aliases
    final Junction conjunction = Restrictions.conjunction();
    final Map<String, String> aliases = Maps.newHashMap();
    for (final Map.Entry<String, Set<String>> filter : Iterables.filter(filters.entrySet(),
            Predicates.not(isTagFilter()))) {
        final Junction disjunction = Restrictions.disjunction();
        for (final String value : filter.getValue()) {
            final PersistenceFilter persistenceFilter = persistenceFilters.get(filter.getKey());
            if (persistenceFilter != null) {
                final Object persistentValue = persistenceFilter.value(value);
                if (persistentValue != null) {
                    for (final String alias : persistenceFilter.getAliases())
                        aliases.put(alias, this.aliases.get(alias));
                    disjunction.add(buildRestriction(persistenceFilter.getProperty(), persistentValue));
                } // else, there is no valid DB filter for the given value (e.g. wildcard for integer value)
            }
        }
        conjunction.add(disjunction);
    }

    // Construct database filter and aliases for tags
    boolean tagPresent = false;
    final List<Junction> tagJunctions = Lists.newArrayList();
    for (final Map.Entry<String, Set<String>> filter : Iterables.filter(filters.entrySet(), isTagFilter())) {
        tagPresent = true;
        final Junction disjunction = Restrictions.disjunction();
        final String filterName = filter.getKey();
        for (final String value : filter.getValue()) {
            if ("tag-key".equals(filterName)) {
                disjunction.add(buildTagRestriction(value, null, true));
            } else if ("tag-value".equals(filterName)) {
                disjunction.add(buildTagRestriction(null, value, true));
            } else {
                disjunction.add(buildTagRestriction(filterName.substring(4), value, false));
            }
        }
        tagJunctions.add(disjunction);
    }
    if (tagPresent)
        conjunction.add(tagCriterion(accountId, tagJunctions));

    return new Filter(aliases, conjunction, Predicates.and(and), tagPresent);
}

From source file:org.pantsbuild.tools.jar.JarBuilder.java

/**
 * Creates a jar at the configured target path applying the scheduled additions per the given
 * {@code duplicateHandler}.// www.ja  va2 s.  com
 *
 * @param compress Pass {@code true} to compress all jar entries; otherwise, they will just be
 *     stored.
 * @param duplicateHandler A handler for dealing with duplicate entries.
 * @param skipPatterns An optional sequence of patterns that match entry paths that should be
 *     excluded.
 * @return The jar file that was written.
 * @throws IOException if there was a problem writing the jar file.
 * @throws DuplicateEntryException if the the policy in effect for an entry is
 *     {@link DuplicateAction#THROW} and that entry is a duplicate.
 */
public File write(final boolean compress, DuplicateHandler duplicateHandler, Iterable<Pattern> skipPatterns)
        throws DuplicateEntryException, IOException {

    Preconditions.checkNotNull(duplicateHandler);
    Predicate<CharSequence> skipPath = Predicates
            .or(Iterables.transform(ImmutableList.copyOf(skipPatterns), AS_PATH_SELECTOR));

    final Iterable<ReadableEntry> entries = getEntries(skipPath, duplicateHandler);

    File tmp = File.createTempFile(target.getName(), ".tmp", target.getParentFile());
    try {
        try {
            JarWriter writer = jarWriter(tmp, compress);
            writer.write(JarFile.MANIFEST_NAME, manifest == null ? DEFAULT_MANIFEST : manifest);
            List<ReadableJarEntry> jarEntries = Lists.newArrayList();
            for (ReadableEntry entry : entries) {
                if (entry instanceof ReadableJarEntry) {
                    jarEntries.add((ReadableJarEntry) entry);
                } else {
                    writer.write(entry.getJarPath(), entry.contents);
                }
            }
            copyJarFiles(writer, jarEntries);

            // Close all open files, the moveFile below might need to copy instead of just rename.
            closer.close();

            // Rename the file (or copy if it can't be renamed)
            target.delete();
            Files.move(tmp, target);
        } catch (IOException e) {
            throw closer.rethrow(e);
        } finally {
            closer.close();
        }
    } finally {
        tmp.delete();
    }
    return target;
}