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

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

Introduction

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

Prototype

public static <T> Predicate<T> in(Collection<? extends T> target) 

Source Link

Document

Returns a predicate that evaluates to true if the object reference being tested is a member of the given collection.

Usage

From source file:com.google.devtools.build.lib.rules.objc.ObjcProvider.java

/** Returns the list of .a files required for linking that arise from objc libraries. */
ImmutableList<Artifact> getObjcLibraries() {
    // JRE libraries must be ordered after all regular objc libraries.
    NestedSet<Artifact> jreLibs = get(JRE_LIBRARY);
    return ImmutableList.<Artifact>builder()
            .addAll(Iterables.filter(get(LIBRARY), Predicates.not(Predicates.in(jreLibs.toSet()))))
            .addAll(jreLibs).build();//  w w  w. j  a v  a2s . c  om
}

From source file:com.google.devtools.build.lib.rules.objc.CompilationSupport.java

/**
 * Registers an action to create an archive artifact by fully (statically) linking all transitive
 * dependencies of this rule *except* for dependencies given in {@code avoidsDeps}.
 *
 * @param objcProvider provides all compiling and linking information to create this artifact
 * @param outputArchive the output artifact for this action
 * @param avoidsDeps list of providers with dependencies that should not be linked into the output
 *     artifact/*ww w.  j  av a2 s  .  co m*/
 */
public CompilationSupport registerFullyLinkActionWithAvoids(ObjcProvider objcProvider, Artifact outputArchive,
        Iterable<ObjcProvider> avoidsDeps) throws InterruptedException {
    ImmutableSet.Builder<Artifact> avoidsDepsArtifacts = ImmutableSet.builder();

    for (ObjcProvider avoidsProvider : avoidsDeps) {
        avoidsDepsArtifacts.addAll(avoidsProvider.getObjcLibraries())
                .addAll(avoidsProvider.get(IMPORTED_LIBRARY)).addAll(avoidsProvider.getCcLibraries());
    }
    ImmutableList<Artifact> depsArtifacts = ImmutableList.<Artifact>builder()
            .addAll(objcProvider.getObjcLibraries()).addAll(objcProvider.get(IMPORTED_LIBRARY))
            .addAll(objcProvider.getCcLibraries()).build();

    Iterable<Artifact> inputArtifacts = Iterables.filter(depsArtifacts,
            Predicates.not(Predicates.in(avoidsDepsArtifacts.build())));
    return registerFullyLinkAction(objcProvider, inputArtifacts, outputArchive);
}

From source file:org.apache.ambari.server.controller.internal.BlueprintConfigurationProcessor.java

/**
 * Drop every configuration property from advised configuration that is not found in the stack defaults.
 * @param advisedConfigurations advised configuration instance
 *//*w  ww .  j a v  a2s  .  c o  m*/
private void doFilterStackDefaults(Map<String, AdvisedConfiguration> advisedConfigurations) {
    Blueprint blueprint = clusterTopology.getBlueprint();
    Configuration stackDefaults = blueprint.getStack().getConfiguration(blueprint.getServices());
    Map<String, Map<String, String>> stackDefaultProps = stackDefaults.getProperties();
    for (Map.Entry<String, AdvisedConfiguration> adConfEntry : advisedConfigurations.entrySet()) {
        AdvisedConfiguration advisedConfiguration = adConfEntry.getValue();
        if (stackDefaultProps.containsKey(adConfEntry.getKey())) {
            Map<String, String> defaultProps = stackDefaultProps.get(adConfEntry.getKey());
            Map<String, String> outFilteredProps = Maps.filterKeys(advisedConfiguration.getProperties(),
                    Predicates.not(Predicates.in(defaultProps.keySet())));
            advisedConfiguration.getProperties().keySet()
                    .removeAll(Sets.newCopyOnWriteArraySet(outFilteredProps.keySet()));

            if (advisedConfiguration.getPropertyValueAttributes() != null) {
                Map<String, ValueAttributesInfo> outFilteredValueAttrs = Maps.filterKeys(
                        advisedConfiguration.getPropertyValueAttributes(),
                        Predicates.not(Predicates.in(defaultProps.keySet())));
                advisedConfiguration.getPropertyValueAttributes().keySet()
                        .removeAll(Sets.newCopyOnWriteArraySet(outFilteredValueAttrs.keySet()));
            }
        } else {
            advisedConfiguration.getProperties().clear();
        }
    }
}

From source file:org.obeonetwork.dsl.uml2.core.api.services.ReusedDescriptionServices.java

/**
 * Get non selectable elements. Those elements are already displayed in the
 * diagram./*from   w w w .j  a va  2  s.  c o  m*/
 *
 * @param diagram
 *            Diagram
 * @return Already displayed nodes in diagram
 */
@SuppressWarnings("rawtypes")
private Predicate getNonSelectablePredicate(DDiagram diagram) {
    return Predicates.in(UIServices.INSTANCE.getDisplayedNodes(diagram));
}

From source file:com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.java

/**
 * Parses the options from .rc files for a command invocation. It works in one of two modes;
 * either it loads the non-config options, or the config options that are specified in the {@code
 * configs} parameter./*ww  w  . j  a v a 2s. co  m*/
 *
 * <p>This method adds every option pertaining to the specified command to the options parser. To
 * do that, it needs the command -> option mapping that is generated from the .rc files.
 *
 * <p>It is not as trivial as simply taking the list of options for the specified command because
 * commands can inherit arguments from each other, and we have to respect that (e.g. if an option
 * is specified for 'build', it needs to take effect for the 'test' command, too).
 *
 * <p>Note that the order in which the options are parsed is well-defined: all options from the
 * same rc file are parsed at the same time, and the rc files are handled in the order in which
 * they were passed in from the client.
 *
 * @param rcfileNotes note message that would be printed during parsing
 * @param commandAnnotation the command for which options should be parsed.
 * @param optionsParser parser to receive parsed options.
 * @param optionsMap .rc files in structured format: a list of pairs, where the first part is the
 *     name of the rc file, and the second part is a multimap of command name (plus config, if
 *     present) to the list of options for that command
 * @param configs the configs for which to parse options; if {@code null}, non-config options are
 *     parsed
 * @param unknownConfigs optional; a collection that the method will populate with the config
 *     values in {@code configs} that none of the .rc files had entries for
 * @throws OptionsParsingException
 */
protected static void parseOptionsForCommand(List<String> rcfileNotes, Command commandAnnotation,
        OptionsParser optionsParser, List<Pair<String, ListMultimap<String, String>>> optionsMap,
        @Nullable Collection<String> configs, @Nullable Collection<String> unknownConfigs)
        throws OptionsParsingException {
    Set<String> knownConfigs = new HashSet<>();
    for (String commandToParse : getCommandNamesToParse(commandAnnotation)) {
        for (Pair<String, ListMultimap<String, String>> entry : optionsMap) {
            List<String> allOptions = new ArrayList<>();
            if (configs == null) {
                allOptions.addAll(entry.second.get(commandToParse));
            } else {
                for (String config : configs) {
                    Collection<String> values = entry.second.get(commandToParse + ":" + config);
                    if (!values.isEmpty()) {
                        allOptions.addAll(values);
                        knownConfigs.add(config);
                    }
                }
            }
            processOptionList(optionsParser, commandToParse, commandAnnotation.name(), rcfileNotes, entry.first,
                    allOptions);
        }
    }
    if (unknownConfigs != null && configs != null && configs.size() > knownConfigs.size()) {
        Iterables.addAll(unknownConfigs,
                Iterables.filter(configs, Predicates.not(Predicates.in(knownConfigs))));
    }
}

From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java

private List<Entry<Cell, byte[]>> getPostfilteredWithLocalWrites(final String tableName,
        final SortedMap<Cell, byte[]> postFiltered, final RangeRequest rangeRequest,
        List<RowResult<Value>> prePostFilter, final byte[] endRowExclusive) {
    Map<Cell, Value> prePostFilterCells = Cells.convertRowResultsToCells(prePostFilter);
    Collection<Entry<Cell, byte[]>> postFilteredCells = Collections2.filter(postFiltered.entrySet(), Predicates
            .compose(Predicates.in(prePostFilterCells.keySet()), MapEntries.<Cell, byte[]>getKeyFunction()));
    Collection<Entry<Cell, byte[]>> localWritesInRange = getLocalWritesForRange(tableName,
            rangeRequest.getStartInclusive(), endRowExclusive).entrySet();
    return ImmutableList.copyOf(mergeInLocalWrites(postFilteredCells.iterator(), localWritesInRange.iterator(),
            rangeRequest.isReverse()));/*ww  w .j av a2  s .  co  m*/
}

From source file:com.google.devtools.build.lib.query2.SkyQueryEnvironment.java

@Override
public Set<Target> getTransitiveClosure(Set<Target> targets) throws InterruptedException {
    Set<Target> visited = new HashSet<>();
    Collection<Target> current = targets;
    while (!current.isEmpty()) {
        Collection<Target> toVisit = Collections2.filter(current, Predicates.not(Predicates.in(visited)));
        current = getFwdDeps(toVisit);/*from ww w .  j av a 2 s.  c o m*/
        visited.addAll(toVisit);
    }
    return ImmutableSet.copyOf(visited);
}

From source file:com.google.devtools.build.lib.rules.objc.ObjcProvider.java

@SuppressWarnings("unchecked")
private <T> void addTransitiveAndAvoid(ObjcProvider.Builder objcProviderBuilder, Key<T> key,
        Iterable<ObjcProvider> avoidProviders) {
    HashSet<T> avoidItemsSet = new HashSet<T>();
    for (ObjcProvider avoidProvider : avoidProviders) {
        avoidItemsSet.addAll(avoidProvider.getPropagable(key).toList());
    }// ww w.j a v a2s.co m
    addTransitiveAndFilter(objcProviderBuilder, key, Predicates.not(Predicates.in(avoidItemsSet)));
}

From source file:com.google.devtools.build.lib.rules.objc.LegacyCompilationSupport.java

private CommandLine linkCommandLine(ExtraLinkArgs extraLinkArgs, ObjcProvider objcProvider,
        Artifact linkedBinary, Optional<Artifact> dsymBundleZip, Iterable<Artifact> ccLibraries,
        Iterable<Artifact> bazelBuiltLibraries, Optional<Artifact> linkmap) {
    Iterable<String> libraryNames = libraryNames(objcProvider);

    CustomCommandLine.Builder commandLine = CustomCommandLine.builder()
            .addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath());
    if (objcProvider.is(USES_CPP)) {
        commandLine.add(CLANG_PLUSPLUS).add("-stdlib=libc++").add("-std=gnu++11");
    } else {// www  . ja  v  a2  s  .c o m
        commandLine.add(CLANG);
    }

    // Do not perform code stripping on tests because XCTest binary is linked not as an executable
    // but as a bundle without any entry point.
    boolean isTestTarget = TargetUtils.isTestRule(ruleContext.getRule());
    if (objcConfiguration.shouldStripBinary() && !isTestTarget) {
        commandLine.add("-dead_strip").add("-no_dead_strip_inits_and_terms");
    }

    Iterable<Artifact> ccLibrariesToForceLoad = Iterables.filter(ccLibraries, ALWAYS_LINKED_CC_LIBRARY);

    ImmutableSet<Artifact> forceLinkArtifacts = ImmutableSet.<Artifact>builder()
            .addAll(objcProvider.get(FORCE_LOAD_LIBRARY)).addAll(ccLibrariesToForceLoad).build();

    Artifact inputFileList = intermediateArtifacts.linkerObjList();
    Iterable<Artifact> objFiles = Iterables.concat(bazelBuiltLibraries, objcProvider.get(IMPORTED_LIBRARY),
            ccLibraries);
    // Clang loads archives specified in filelists and also specified as -force_load twice,
    // resulting in duplicate symbol errors unless they are deduped.
    objFiles = Iterables.filter(objFiles, Predicates.not(Predicates.in(forceLinkArtifacts)));

    registerObjFilelistAction(objFiles, inputFileList);

    if (objcConfiguration.shouldPrioritizeStaticLibs()) {
        commandLine.add("-filelist").add(inputFileList.getExecPathString());
    }

    AppleBitcodeMode bitcodeMode = appleConfiguration.getBitcodeMode();
    commandLine.add(bitcodeMode.getCompileAndLinkFlags());

    if (bitcodeMode == AppleBitcodeMode.EMBEDDED) {
        commandLine.add("-Xlinker").add("-bitcode_verify");
        commandLine.add("-Xlinker").add("-bitcode_hide_symbols");
        // TODO(b/32910627): Add Bitcode symbol maps outputs.
    }

    commandLine.add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration))
            .add("-Xlinker").add("-objc_abi_version").add("-Xlinker").add("2")
            // Set the rpath so that at runtime dylibs can be loaded from the bundle root's "Frameworks"
            // directory.
            .add("-Xlinker").add("-rpath").add("-Xlinker").add("@executable_path/Frameworks")
            .add("-fobjc-link-runtime").add(DEFAULT_LINKER_FLAGS)
            .addBeforeEach("-framework", frameworkNames(objcProvider))
            .addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK)))
            .addFormatEach("-l%s", libraryNames);

    if (!objcConfiguration.shouldPrioritizeStaticLibs()) {
        commandLine.add("-filelist").add(inputFileList.getExecPathString());
    }

    commandLine.addExecPath("-o", linkedBinary).addBeforeEachExecPath("-force_load", forceLinkArtifacts)
            .add(extraLinkArgs).add(objcProvider.get(ObjcProvider.LINKOPT));

    if (buildConfiguration.isCodeCoverageEnabled()) {
        if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) {
            commandLine.add(LINKER_LLVM_COVERAGE_FLAGS);
        } else {
            commandLine.add(LINKER_COVERAGE_FLAGS);
        }
    }

    for (String linkopt : attributes.linkopts()) {
        commandLine.add("-Wl," + linkopt);
    }

    if (linkmap.isPresent()) {
        commandLine.add("-Xlinker -map").add("-Xlinker " + linkmap.get().getExecPath());
    }

    // Call to dsymutil for debug symbol generation must happen in the link action.
    // All debug symbol information is encoded in object files inside archive files. To generate
    // the debug symbol bundle, dsymutil will look inside the linked binary for the encoded
    // absolute paths to archive files, which are only valid in the link action.
    if (dsymBundleZip.isPresent()) {
        PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundleZip.get().getExecPath());
        commandLine.add("&&").addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()).add(DSYMUTIL)
                .add(linkedBinary.getExecPathString()).add("-o " + dsymPath)
                .add("&& zipped_bundle=${PWD}/" + dsymBundleZip.get().getShellEscapedExecPathString())
                .add("&& cd " + dsymPath).add("&& /usr/bin/zip -q -r \"${zipped_bundle}\" .");
    }

    return commandLine.build();
}

From source file:com.eucalyptus.autoscaling.AutoScalingService.java

public DescribeTagsResponseType describeTags(final DescribeTagsType request) throws EucalyptusCloudException {
    final DescribeTagsResponseType reply = request.getReply();

    //TODO: MaxRecords / NextToken support for DescribeTags

    final Collection<Predicate<Tag>> tagFilters = Lists.newArrayList();
    for (final Filter filter : request.filters()) {
        final Function<Tag, String> extractor = tagFilterExtractors.get(filter.getName());
        if (extractor == null) {
            throw new ValidationErrorException("Filter type " + filter.getName()
                    + " is not correct. Allowed Filter types are: auto-scaling-group key value propagate-at-launch");
        }/*  w  ww  . j  ava  2 s . c om*/
        final Function<String, String> tagValueConverter = Objects
                .firstNonNull(tagValuePreProcessors.get(filter.getName()), Functions.<String>identity());
        tagFilters.add(Predicates
                .compose(Predicates.in(Collections2.transform(filter.values(), tagValueConverter)), extractor));
    }

    final Context context = Contexts.lookup();

    final Ordering<Tag> ordering = Ordering.natural().onResultOf(Tags.resourceId())
            .compound(Ordering.natural().onResultOf(Tags.key()))
            .compound(Ordering.natural().onResultOf(Tags.value()));
    try {
        final TagDescriptionList tagDescriptions = new TagDescriptionList();
        for (final Tag tag : ordering
                .sortedCopy(Tags.list(context.getUserFullName().asAccountFullName(), Predicates.and(tagFilters),
                        Restrictions.conjunction(), Collections.<String, String>emptyMap()))) {
            if (Permissions.isAuthorized(PolicySpec.VENDOR_AUTOSCALING, tag.getResourceType(), tag.getKey(),
                    context.getAccount(),
                    PolicySpec.describeAction(PolicySpec.VENDOR_AUTOSCALING, tag.getResourceType()),
                    context.getUser())) {
                tagDescriptions.getMember().add(TypeMappers.transform(tag, TagDescription.class));
            }
        }
        if (!tagDescriptions.getMember().isEmpty()) {
            reply.getDescribeTagsResult().setTags(tagDescriptions);
        }
    } catch (AutoScalingMetadataNotFoundException e) {
        handleException(e);
    }

    return reply;
}