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:co.cask.cdap.common.utils.DirUtils.java

/**
 * Returns list of files under the given directory that matches the give set of file name extension.
 * An empty list will be returned if the given file is not a directory.
 *//*from www.  j  a  v  a  2s. c  om*/
public static List<File> listFiles(File directory, Iterable<String> extensions) {
    final ImmutableSet<String> allowedExtensions = ImmutableSet.copyOf(extensions);

    return listFiles(directory, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return allowedExtensions.contains(Files.getFileExtension(name));
        }
    });
}

From source file:com.spectralogic.ds3autogen.c.converters.SourceConverter.java

/**
 * All Request query parameters that are Enums require a _get_enum_str() function to be generated
 *//*from w ww .j av a 2 s.  c  om*/
public static ImmutableSet<Enum> filterQueryParamEnums(final ImmutableList<Enum> allEnums,
        final ImmutableList<Request> allRequests) {
    final ImmutableSet<String> enumTypes = allEnums.stream().map(Enum::getName)
            .collect(GuavaCollectors.immutableSet());

    final ImmutableSet.Builder<Enum> queryEnumsBuilder = ImmutableSet.builder();
    for (final Request currentRequest : allRequests) {
        currentRequest.getRequiredQueryParams().stream()
                .filter(currentRequiredParam -> enumTypes.contains(currentRequiredParam.getParameterType()))
                .forEach(currentRequiredParam -> allEnums.stream().filter(
                        currentEnum -> currentEnum.getName().equals(currentRequiredParam.getParameterType()))
                        .forEach(queryEnumsBuilder::add));
        currentRequest.getOptionalQueryParams().stream()
                .filter(currentOptionalParam -> enumTypes.contains(currentOptionalParam.getParameterType()))
                .forEach(currentOptionalParam -> allEnums.stream().filter(
                        currentEnum -> currentEnum.getName().equals(currentOptionalParam.getParameterType()))
                        .forEach(queryEnumsBuilder::add));
    }
    return queryEnumsBuilder.build();
}

From source file:com.facebook.buck.cxx.toolchain.CxxPlatformsProviderFactory.java

private static Optional<UnresolvedCxxPlatform> augmentSystemPlatform(Platform platform,
        ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatformsMap, CxxPlatform defaultHostCxxPlatform,
        ImmutableSet<Flavor> possibleHostFlavors, Flavor flavor, CxxBuckConfig cxxConfig) {
    UnresolvedCxxPlatform baseUnresolvedCxxPlatform = cxxSystemPlatformsMap.get(flavor);
    CxxPlatform baseCxxPlatform;//from  www  .  ja  v a2  s .c om
    if (baseUnresolvedCxxPlatform == null) {
        if (possibleHostFlavors.contains(flavor)) {
            // If a flavor is for an alternate host, it's safe to skip.
            return Optional.empty();
        }
        LOG.info("Applying \"%s\" overrides to default host platform", flavor);
        baseCxxPlatform = defaultHostCxxPlatform;
    } else {
        if (!(baseUnresolvedCxxPlatform instanceof StaticUnresolvedCxxPlatform)) {
            throw new HumanReadableException("Cannot override non-static cxx platform %s", flavor);
        }
        baseCxxPlatform = ((StaticUnresolvedCxxPlatform) baseUnresolvedCxxPlatform).getCxxPlatform();
    }

    StaticUnresolvedCxxPlatform augmentedPlatform = new StaticUnresolvedCxxPlatform(
            CxxPlatforms.copyPlatformWithFlavorAndConfig(baseCxxPlatform, platform, cxxConfig, flavor));
    return Optional.of(augmentedPlatform);
}

From source file:com.google.devtools.build.lib.buildtool.SymlinkForest.java

/**
 * Returns the longest prefix from a given set of 'prefixes' that are
 * contained in 'path'. I.e the closest ancestor directory containing path.
 * Returns null if none found.//w  ww  .j a v a2  s. co  m
 * @param path
 * @param prefixes
 */
@VisibleForTesting
static PackageIdentifier longestPathPrefix(PackageIdentifier path, ImmutableSet<PackageIdentifier> prefixes) {
    for (int i = path.getPackageFragment().segmentCount(); i >= 0; i--) {
        PackageIdentifier prefix = createInRepo(path, path.getPackageFragment().subFragment(0, i));
        if (prefixes.contains(prefix)) {
            return prefix;
        }
    }
    return null;
}

From source file:com.facebook.presto.operator.annotations.FunctionsParserHelper.java

public static Map<String, Class<?>> getDeclaredSpecializedTypeParameters(Method method,
        Set<TypeParameter> typeParameters) {
    Map<String, Class<?>> specializedTypeParameters = new HashMap<>();
    TypeParameterSpecialization[] typeParameterSpecializations = method
            .getAnnotationsByType(TypeParameterSpecialization.class);
    ImmutableSet<String> typeParameterNames = typeParameters.stream().map(TypeParameter::value)
            .collect(toImmutableSet());//  ww w  .  j a  v a  2 s.c om
    for (TypeParameterSpecialization specialization : typeParameterSpecializations) {
        checkArgument(typeParameterNames.contains(specialization.name()),
                "%s does not match any declared type parameters (%s) [%s]", specialization.name(),
                typeParameters, method);
        Class<?> existingSpecialization = specializedTypeParameters.get(specialization.name());
        checkArgument(
                existingSpecialization == null
                        || existingSpecialization.equals(specialization.nativeContainerType()),
                "%s has conflicting specializations %s and %s [%s]", specialization.name(),
                existingSpecialization, specialization.nativeContainerType(), method);
        specializedTypeParameters.put(specialization.name(), specialization.nativeContainerType());
    }
    return specializedTypeParameters;
}

From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java

/**
 * Removes all unused types from the Ds3Type map. Types are considered to be used if
 * they are used within a Ds3Request, and/or if they are used within another type that
 * is also used./*from  www .  j  a  v  a  2 s  . c o m*/
 * @param types A Ds3Type map
 * @param requests A list of Ds3Requests
 */
public static ImmutableMap<String, Ds3Type> removeUnusedTypes(final ImmutableMap<String, Ds3Type> types,
        final ImmutableList<Ds3Request> requests) {
    if (isEmpty(types) || isEmpty(requests)) {
        return ImmutableMap.of();
    }

    final ImmutableSet.Builder<String> usedTypesBuilder = ImmutableSet.builder();
    usedTypesBuilder.addAll(getUsedTypesFromRequests(requests));
    usedTypesBuilder.addAll(getUsedTypesFromAllTypes(types, usedTypesBuilder.build()));
    final ImmutableSet<String> usedTypes = usedTypesBuilder.build();

    final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder();
    for (final Map.Entry<String, Ds3Type> entry : types.entrySet()) {
        if (usedTypes.contains(entry.getKey())) {
            builder.put(entry.getKey(), entry.getValue());
        }
    }
    return builder.build();
}

From source file:com.facebook.buck.model.macros.MacroFinder.java

public static Optional<MacroMatchResult> match(ImmutableSet<String> macros, String blob) throws MacroException {

    MacroFinderAutomaton macroFinder = new MacroFinderAutomaton(blob);
    if (!macroFinder.hasNext()) {
        return Optional.empty();
    }/*from   w ww .j  a v a 2  s  . c o  m*/
    MacroMatchResult result = macroFinder.next();
    if (!result.isEscaped() && result.getStartIndex() == 0 && result.getEndIndex() == blob.length()
            && !macros.contains(result.getMacroType())) {
        throw new MacroException(
                String.format("expanding %s: no such macro \"%s\"", blob, result.getMacroType()));
    }
    return Optional.of(result);
}

From source file:com.facebook.buck.model.macros.MacroFinder.java

public static ImmutableList<MacroMatchResult> findAll(ImmutableSet<String> macros, String blob)
        throws MacroException {

    ImmutableList.Builder<MacroMatchResult> results = ImmutableList.builder();
    MacroFinderAutomaton matcher = new MacroFinderAutomaton(blob);
    while (matcher.hasNext()) {
        MacroMatchResult matchResult = matcher.next();
        if (matchResult.isEscaped()) {
            continue;
        }//from  w ww.j  a v  a  2 s .com
        if (!macros.contains(matchResult.getMacroType())) {
            throw new MacroException(String.format("no such macro \"%s\"", matchResult.getMacroType()));
        }
        results.add(matchResult);
    }

    return results.build();
}

From source file:com.google.caliper.runner.instrument.InstrumentModule.java

@Provides
static ImmutableSet<InstrumentedMethod> provideInstrumentedMethods(CaliperOptions options,
        BenchmarkClassModel benchmarkClass, ImmutableSet<Instrument> instruments)
        throws InvalidBenchmarkException {
    ImmutableSet.Builder<InstrumentedMethod> builder = ImmutableSet.builder();
    ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames();
    Set<String> unusedBenchmarkNames = new HashSet<String>(benchmarkMethodNames);
    for (Instrument instrument : instruments) {
        for (MethodModel method : findAllBenchmarkMethods(benchmarkClass, instrument)) {
            if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.name())) {
                builder.add(instrument.createInstrumentedMethod(method));
                unusedBenchmarkNames.remove(method.name());
            }/*www . j a  v  a 2s .  c  o  m*/
        }
    }
    if (!unusedBenchmarkNames.isEmpty()) {
        throw new InvalidBenchmarkException("Invalid benchmark method(s) specified in options: %s",
                unusedBenchmarkNames);
    }
    return builder.build();
}

From source file:com.google.devtools.build.android.dexer.ZipEntryPredicates.java

public static Predicate<ZipEntry> classFileFilter(final ImmutableSet<String> classFileNames) {
    return new Predicate<ZipEntry>() {
        @Override/*from  w ww. j av a 2s  . c om*/
        public boolean apply(ZipEntry input) {
            String filename = input.getName();
            if (filename.endsWith(".class.dex")) {
                // Chop off file suffix generated by DexBuilder
                filename = filename.substring(0, filename.length() - ".dex".length());
            }
            return filename.endsWith(".class") && classFileNames.contains(filename);
        }
    };
}