Example usage for com.google.common.collect ImmutableSet contains

List of usage examples for com.google.common.collect ImmutableSet contains

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.android.tools.idea.editors.theme.ThemeEditorUtils.java

/**
 * Visits every ResourceFolderRepository. It visits every resource in order, meaning that the later calls may override resources from
 * previous ones./* w  w w  . jav a 2  s .  c o m*/
 */
public static void acceptResourceResolverVisitor(final @NotNull AndroidFacet mainFacet,
        final @NotNull ResourceFolderVisitor visitor) {
    // Get all the dependencies of the module in reverse order (first one is the lowest priority one)
    List<AndroidFacet> dependencies = Lists
            .reverse(AndroidUtils.getAllAndroidDependencies(mainFacet.getModule(), true));

    // The order of iteration here is important since the resources from the mainFacet will override those in the dependencies.
    for (AndroidFacet dependency : Iterables.concat(dependencies, ImmutableList.of(mainFacet))) {
        AndroidModuleModel androidModel = AndroidModuleModel.get(dependency);
        if (androidModel == null) {
            // For non gradle module, get the main source provider
            SourceProvider provider = dependency.getMainSourceProvider();
            for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(
                    dependency, provider)) {
                visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), true);
            }
        } else {
            // For gradle modules, get all source providers and go through them
            // We need to iterate the providers in the returned to make sure that they correctly override each other
            List<SourceProvider> activeProviders = androidModel.getActiveSourceProviders();
            for (SourceProvider provider : activeProviders) {
                for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(
                        dependency, provider)) {
                    visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(),
                            true);
                }
            }

            // Not go through all the providers that are not in the activeProviders
            ImmutableSet<SourceProvider> selectedProviders = ImmutableSet.copyOf(activeProviders);
            for (SourceProvider provider : androidModel.getAllSourceProviders()) {
                if (!selectedProviders.contains(provider)) {
                    for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(
                            dependency, provider)) {
                        visitor.visitResourceFolder(resourceRepository, dependency.getName(),
                                provider.getName(), false);
                    }
                }
            }
        }
    }
}

From source file:com.facebook.buck.step.fs.UnzipStep.java

@VisibleForTesting
static void extractZipFile(String zipFile, String destination, ImmutableSet<String> filesToExtract,
        boolean overwriteExistingFiles) throws IOException {
    // Create output directory is not exists
    File folder = new File(destination);
    // TODO UnzipStep could be a CompositeStep with a MakeCleanDirectoryStep for the output dir.
    if (!folder.exists() && !folder.mkdirs()) {
        throw new IOException(String.format("Folder %s could not be created.", folder.toString()));
    }//from  w w  w  .j  a  v  a 2 s . c om

    try (ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFile))) {
        for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
            String fileName = entry.getName();
            // If filesToExtract is not empty, check if current entry is contained.
            if (!filesToExtract.isEmpty() && !filesToExtract.contains(fileName)) {
                continue;
            }
            File target = new File(folder, fileName);
            if (target.exists() && !overwriteExistingFiles) {
                continue;
            }
            if (entry.isDirectory()) {
                // Create the directory and all its parent directories
                if (!target.mkdirs()) {
                    throw new IOException(String.format("Folder %s could not be created.", target.toString()));
                }
            } else {
                // Create parent folder
                File parentFolder = target.getParentFile();
                if (!parentFolder.exists() && !parentFolder.mkdirs()) {
                    throw new IOException(
                            String.format("Folder %s could not be created.", parentFolder.toString()));
                }
                // Write file
                try (FileOutputStream out = new FileOutputStream(target)) {
                    ByteStreams.copy(zip, out);
                }
            }
        }
    }
}

From source file:org.jetbrains.jet.lang.types.lang.KotlinBuiltIns.java

private static boolean setContainsClassOf(ImmutableSet<ClassDescriptor> set, JetType type) {
    //noinspection SuspiciousMethodCalls
    return set.contains(type.getConstructor().getDeclarationDescriptor());
}

From source file:org.elasticsearch.gateway.GatewayMetaState.java

public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state,
        ImmutableSet<String> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException(
                "cluster state does not contain this node - cannot write index meta state");
    }/*from www  .j  a  v a 2 s.  c om*/
    Set<String> indices = new HashSet<>();
    for (MutableShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && state.metaData().getIndices()
                .get(indexMetaData.getIndex()).state().equals(IndexMetaData.State.CLOSE)) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}

From source file:it.unibz.krdb.sql.DBMetadataExtractor.java

/**
 * Retrieve the table and view list from the JDBC driver (works for most database engines, e.g., MySQL and PostgreSQL)
 *///from  w w w . java  2  s. c  o  m
private static List<RelationID> getTableListDefault(DatabaseMetaData md, ImmutableSet<String> ignoredSchemas)
        throws SQLException {
    List<RelationID> relationIds = new LinkedList<>();
    try (ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE", "VIEW" })) {
        while (rs.next()) {
            // String catalog = rs.getString("TABLE_CAT"); // not used
            String schema = rs.getString("TABLE_SCHEM");
            String table = rs.getString("TABLE_NAME");
            if (ignoredSchemas.contains(schema)) {
                continue;
            }
            RelationID id = RelationID.createRelationIdFromDatabaseRecord(schema, table);
            relationIds.add(id);
        }
    }
    return relationIds;
}

From source file:com.facebook.buck.features.haskell.HaskellGhciDescription.java

private static NativeLinkableInput getOmnibusNativeLinkableInput(BuildTarget baseTarget,
        CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, Iterable<NativeLinkable> body,
        Iterable<NativeLinkable> deps) {

    List<NativeLinkableInput> nativeLinkableInputs = new ArrayList<>();

    // Topologically sort the body nodes, so that they're ready to add to the link line.
    ImmutableSet<BuildTarget> bodyTargets = RichStream.from(body).map(NativeLinkable::getBuildTarget)
            .toImmutableSet();/*w w w  . j ava  2 s. co m*/
    ImmutableList<NativeLinkable> topoSortedBody = NativeLinkables
            .getTopoSortedNativeLinkables(body,
                    nativeLinkable -> RichStream
                            .from(Iterables.concat(
                                    nativeLinkable.getNativeLinkableExportedDepsForPlatform(cxxPlatform,
                                            graphBuilder),
                                    nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform, graphBuilder)))
                            .filter(l -> bodyTargets.contains(l.getBuildTarget())));

    // Add the link inputs for all omnibus nodes.
    for (NativeLinkable nativeLinkable : topoSortedBody) {

        // We link C/C++ libraries whole...
        if (nativeLinkable instanceof CxxLibrary) {
            NativeLinkable.Linkage link = nativeLinkable.getPreferredLinkage(cxxPlatform, graphBuilder);
            nativeLinkableInputs.add(nativeLinkable.getNativeLinkableInput(cxxPlatform,
                    NativeLinkables.getLinkStyle(link, Linker.LinkableDepType.STATIC_PIC), true, graphBuilder));
            LOG.verbose("%s: linking C/C++ library %s whole into omnibus", baseTarget,
                    nativeLinkable.getBuildTarget());
            continue;
        }

        // Link prebuilt C/C++ libraries statically.
        if (nativeLinkable instanceof PrebuiltCxxLibrary) {
            nativeLinkableInputs.add(NativeLinkables.getNativeLinkableInput(cxxPlatform,
                    Linker.LinkableDepType.STATIC_PIC, nativeLinkable, graphBuilder));
            LOG.verbose("%s: linking prebuilt C/C++ library %s into omnibus", baseTarget,
                    nativeLinkable.getBuildTarget());
            continue;
        }

        throw new IllegalStateException(String.format("%s: unexpected rule type in omnibus link %s(%s)",
                baseTarget, nativeLinkable.getClass(), nativeLinkable.getBuildTarget()));
    }

    // Link in omnibus deps dynamically.
    ImmutableList<NativeLinkable> depLinkables = NativeLinkables.getNativeLinkables(cxxPlatform, graphBuilder,
            deps, LinkableDepType.SHARED);
    for (NativeLinkable linkable : depLinkables) {
        nativeLinkableInputs.add(NativeLinkables.getNativeLinkableInput(cxxPlatform, LinkableDepType.SHARED,
                linkable, graphBuilder));
    }

    return NativeLinkableInput.concat(nativeLinkableInputs);
}

From source file:com.facebook.buck.apple.AppleDescriptions.java

private static BuildRule getFlavoredBinaryRule(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,
        CxxPlatform defaultCxxPlatform, TargetGraph targetGraph, ImmutableSet<Flavor> flavors,
        BuildRuleResolver resolver, BuildTarget binary) throws NoSuchBuildTargetException {

    // Don't flavor genrule deps.
    if (targetGraph.get(binary).getDescription() instanceof AbstractGenruleDescription) {
        return resolver.requireRule(binary);
    }//from   w ww.ja  va2  s . com

    // Cxx targets must have one Platform Flavor set otherwise nothing gets compiled.
    if (flavors.contains(AppleDescriptions.FRAMEWORK_FLAVOR)) {
        flavors = ImmutableSet.<Flavor>builder().addAll(flavors).add(CxxDescriptionEnhancer.SHARED_FLAVOR)
                .build();
    }
    flavors = ImmutableSet.copyOf(Sets.difference(flavors,
            ImmutableSet.of(AppleDescriptions.FRAMEWORK_FLAVOR, AppleBinaryDescription.APP_FLAVOR)));
    if (!cxxPlatformFlavorDomain.containsAnyOf(flavors)) {
        flavors = new ImmutableSet.Builder<Flavor>().addAll(flavors).add(defaultCxxPlatform.getFlavor())
                .build();
    }

    BuildTarget.Builder buildTargetBuilder = BuildTarget.builder(binary.getUnflavoredBuildTarget())
            .addAllFlavors(flavors);
    if (!(AppleLibraryDescription.LIBRARY_TYPE.getFlavor(flavors).isPresent())) {
        buildTargetBuilder.addAllFlavors(binary.getFlavors());
    } else {
        buildTargetBuilder.addAllFlavors(
                Sets.difference(binary.getFlavors(), AppleLibraryDescription.LIBRARY_TYPE.getFlavors()));
    }
    BuildTarget buildTarget = buildTargetBuilder.build();

    final TargetNode<?, ?> binaryTargetNode = targetGraph.get(buildTarget);

    if (binaryTargetNode.getDescription() instanceof AppleTestDescription) {
        return resolver.getRule(binary);
    }

    // If the binary target of the AppleBundle is an AppleLibrary then the build flavor
    // must be specified.
    if (binaryTargetNode.getDescription() instanceof AppleLibraryDescription
            && (Sets.intersection(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS, buildTarget.getFlavors())
                    .size() != 1)) {
        throw new HumanReadableException(
                "AppleExtension bundle [%s] must have exactly one of these flavors: [%s].",
                binaryTargetNode.getBuildTarget().toString(),
                Joiner.on(", ").join(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS));
    }

    if (!StripStyle.FLAVOR_DOMAIN.containsAnyOf(buildTarget.getFlavors())) {
        buildTarget = buildTarget.withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
    }

    return resolver.requireRule(buildTarget);
}

From source file:it.unibz.inf.ontop.sql.DBMetadataExtractor.java

/**
 * Retrieve the table and view list from the JDBC driver (works for most database engines, e.g., MySQL and PostgreSQL)
 *///from   w  w w .jav a  2 s  . c  o m
private static List<RelationID> getTableListDefault(DatabaseMetaData md, ImmutableSet<String> ignoredSchemas,
        QuotedIDFactory idfac) throws SQLException {
    List<RelationID> relationIds = new LinkedList<>();
    try (ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE", "VIEW" })) {
        while (rs.next()) {
            // String catalog = rs.getString("TABLE_CAT"); // not used
            String schema = rs.getString("TABLE_SCHEM");
            String table = rs.getString("TABLE_NAME");
            if (ignoredSchemas.contains(schema)) {
                continue;
            }
            RelationID id = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, table);
            relationIds.add(id);
        }
    }
    return relationIds;
}

From source file:com.facebook.buck.cli.ExopackageInstaller.java

/**
 * @param output  Output of "ls" command.
 * @param requiredHashes  Hashes of dex files required for this apk.
 * @param foundHashesBuilder  Builder to receive hashes that we need and were found.
 * @param toDeleteBuilder  Builder to receive files that we need to delete.
 *///w  w  w  .j av a2 s.c o m
@VisibleForTesting
static void scanSecondaryDexDir(String output, ImmutableSet<String> requiredHashes,
        ImmutableSet.Builder<String> foundHashesBuilder, ImmutableSet.Builder<String> toDeleteBuilder) {
    Pattern dexFilePattern = Pattern.compile("secondary-([0-9a-f]+)\\.[\\w.-]*");

    for (String line : Splitter.on("\r\n").split(output)) {
        if (line.equals("metadata.txt") || line.startsWith(AgentUtil.TEMP_PREFIX)) {
            toDeleteBuilder.add(line);
            continue;
        }

        Matcher m = dexFilePattern.matcher(line);
        if (m.matches()) {
            if (requiredHashes.contains(m.group(1))) {
                foundHashesBuilder.add(m.group(1));
            } else {
                toDeleteBuilder.add(line);
            }
        }
    }
}

From source file:org.springframework.ide.eclipse.boot.dash.livexp.DisposingFactory.java

public synchronized V createOrGet(K key) {
    ImmutableSet<K> valid = getValidKeys();
    if (valid.contains(key)) {
        enableValidKeyTracking();/*from   ww w.  j ava  2s.c om*/
        V instance = cachedInstances.get(key);
        if (instance == null) {
            instance = create(key);
            if (instance != null) {
                cachedInstances.put(key, instance);
            }
        }
        return instance;
    }
    return null;
}