List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:com.google.caliper.runner.ExperimentingRunnerModule.java
@Provides ImmutableSet<Instrument> provideInstruments(Injector injector, CaliperOptions options, final CaliperConfig config) throws InvalidCommandException { ImmutableSet.Builder<Instrument> builder = ImmutableSet.builder(); ImmutableSet<String> configuredInstruments = config.getConfiguredInstruments(); for (final String instrumentName : options.instrumentNames()) { if (!configuredInstruments.contains(instrumentName)) { throw new InvalidCommandException( "%s is not a configured instrument (%s). " + "use --print-config to see the configured instruments.", instrumentName, configuredInstruments); }/* www .j a va 2s .com*/ final InstrumentConfig instrumentConfig = config.getInstrumentConfig(instrumentName); Injector instrumentInjector = injector.createChildInjector(new AbstractModule() { @Override protected void configure() { bind(InstrumentConfig.class).toInstance(instrumentConfig); } @Provides @InstrumentOptions ImmutableMap<String, String> provideInstrumentOptions(InstrumentConfig config) { return config.options(); } @Provides @InstrumentName String provideInstrumentName() { return instrumentName; } }); String className = instrumentConfig.className(); try { Class<? extends Instrument> clazz = Util.lenientClassForName(className) .asSubclass(Instrument.class); builder.add(instrumentInjector.getInstance(clazz)); } catch (ClassNotFoundException e) { throw new InvalidCommandException("Cannot find instrument class '%s'", className); } catch (ProvisionException e) { throw new InvalidInstrumentException("Could not create the instrument %s", className); } } return builder.build(); }
From source file:com.facebook.buck.features.halide.HalideLibraryDescription.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> flavors) { return getCxxPlatformsProvider().getUnresolvedCxxPlatforms().containsAnyOf(flavors) || flavors.contains(HALIDE_COMPILE_FLAVOR) || flavors.contains(HALIDE_COMPILER_FLAVOR) || StripStyle.FLAVOR_DOMAIN.containsAnyOf(flavors); }
From source file:com.google.errorprone.bugpatterns.EqualsWrongThing.java
@Override public Description matchMethod(MethodTree tree, VisitorState state) { if (!equalsMethodDeclaration().matches(tree, state)) { return NO_MATCH; }//from www . jav a 2s . c om ClassSymbol classSymbol = getSymbol(tree).enclClass(); Set<ComparisonSite> suspiciousComparisons = new HashSet<>(); new TreeScanner<Void, Void>() { @Override public Void visitBinary(BinaryTree node, Void unused) { if (node.getKind() == Kind.EQUAL_TO || node.getKind() == Kind.NOT_EQUAL_TO) { getDubiousComparison(classSymbol, node, node.getLeftOperand(), node.getRightOperand()) .ifPresent(suspiciousComparisons::add); } return super.visitBinary(node, null); } @Override public Void visitMethodInvocation(MethodInvocationTree node, Void unused) { if (COMPARISON_METHOD.matches(node, state)) { getDubiousComparison(classSymbol, node, node.getArguments().get(0), node.getArguments().get(1)) .ifPresent(suspiciousComparisons::add); } if (instanceEqualsInvocation().matches(node, state)) { ExpressionTree receiver = getReceiver(node); if (receiver != null) { // Special-case super, for odd cases like `super.equals(this)`. if (!receiver.toString().equals("super")) { getDubiousComparison(classSymbol, node, receiver, node.getArguments().get(0)) .ifPresent(suspiciousComparisons::add); } } } return super.visitMethodInvocation(node, null); } }.scan(tree, null); // Fast path return. if (suspiciousComparisons.isEmpty()) { return NO_MATCH; } // Special case where comparisons are made of (a, b) and (b, a) to imply that order doesn't // matter. ImmutableSet<ComparisonPair> suspiciousPairs = suspiciousComparisons.stream().map(ComparisonSite::pair) .collect(toImmutableSet()); suspiciousComparisons.stream().filter(p -> !suspiciousPairs.contains(p.pair().reversed())) .map(c -> buildDescription(c.tree()).setMessage(String .format("Suspicious comparison between `%s` and `%s`", c.pair().lhs(), c.pair().rhs())) .build()) .forEach(state::reportMatch); return NO_MATCH; }
From source file:uk.ac.york.mondo.integration.api.EffectiveMetamodelRuleset.java
/** * Undoes the effects of a {@link #include(String, String, ImmutableSet)} or {@link #exclude(String, String, ImmutableSet)} call. *///w ww .j av a2 s . c om public void reset(String mmURI, String type, String slot) { ImmutableSet<String> oldInclusions = inclusions.remove(mmURI, type); if (oldInclusions != null) { if (!oldInclusions.contains(slot)) { inclusions.put(mmURI, type, oldInclusions); } else { inclusions.put(mmURI, type, copyWithout(slot, oldInclusions)); } } ImmutableSet<String> oldExclusions = inclusions.remove(mmURI, type); if (oldExclusions != null) { if (!oldExclusions.contains(slot)) { inclusions.put(mmURI, type, oldExclusions); } else { inclusions.put(mmURI, type, copyWithout(slot, oldExclusions)); } } }
From source file:com.facebook.buck.cxx.CxxTestDescription.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> flavors) { if (flavors.isEmpty()) { return true; }/*ww w.j a v a 2 s.c om*/ if (flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)) { return true; } if (flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) { return true; } if (StripStyle.FLAVOR_DOMAIN.containsAnyOf(flavors)) { return true; } if (LinkerMapMode.FLAVOR_DOMAIN.containsAnyOf(flavors)) { return true; } for (Flavor flavor : cxxPlatforms.getFlavors()) { if (flavors.equals(ImmutableSet.of(flavor))) { return true; } } return false; }
From source file:com.google.security.zynamics.binnavi.yfileswrap.disassembly.types.TypeDependenceGraph.java
/** * Determines the set of base types that are affected by an update to the given member. If the * change would result in an illegal state of the type system, the changes are not performed. * * @return The dependence result of the change. *///from ww w.j av a 2 s . c o m public DependenceResult updateMember(final BaseType parentType, final BaseType oldMemberType, final BaseType newMemberType) { Preconditions.checkNotNull(parentType, "IE02767: Parent type can not be null."); Preconditions.checkNotNull(oldMemberType, "IE02768: Old member type can not be null."); Preconditions.checkNotNull(newMemberType, "IE02769: New member type can not be null."); final ImmutableSet<BaseType> affectedTypes = determineDependentTypes(parentType); if (affectedTypes.contains(parentType)) { return new DependenceResult(false, affectedTypes); } else { // TODO: check first if new member is valid and doesn't create a cycle. deleteMember(parentType, oldMemberType); addMember(parentType, newMemberType); return new DependenceResult(true, affectedTypes); } }
From source file:google.registry.flows.domain.DomainFlowUtils.java
static void validateRegistrantAllowedOnTld(String tld, String registrantContactId) throws RegistrantNotAllowedException { ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds(); // Empty whitelist or null registrantContactId are ignored. if (registrantContactId != null && !whitelist.isEmpty() && !whitelist.contains(registrantContactId)) { throw new RegistrantNotAllowedException(registrantContactId); }//from w w w .j av a 2 s . c o m }
From source file:com.facebook.buck.android.APKModuleGraph.java
private boolean isInRootModule(BuildTarget depTarget) { ImmutableSet<BuildTarget> rootTargets = rootAPKModuleSupplier.get().getBuildTargets(); return rootTargets != null && rootTargets.contains(depTarget); }
From source file:com.facebook.buck.android.AndroidPackageableCollector.java
public AndroidPackageableCollection build() { collectionBuilder.setBuildConfigs(ImmutableMap.copyOf(buildConfigs)); final ImmutableSet<HasJavaClassHashes> javaClassProviders = javaClassHashesProviders.build(); collectionBuilder.addAllJavaLibrariesToDex(javaClassProviders.stream().map(HasBuildTarget::getBuildTarget) .collect(MoreCollectors.toImmutableSet())); collectionBuilder.setClassNamesToHashesSupplier(Suppliers.memoize(() -> { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); for (HasJavaClassHashes hasJavaClassHashes : javaClassProviders) { builder.putAll(hasJavaClassHashes.getClassNamesToHashes()); }/*from w w w. jav a 2 s . c o m*/ return builder.build(); })); ImmutableSet<BuildTarget> resources = ImmutableSet.copyOf(resourcesWithNonEmptyResDir.build()); for (BuildTarget buildTarget : resourcesWithAssets.build()) { if (!resources.contains(buildTarget)) { resourceDetailsBuilder.addResourcesWithEmptyResButNonEmptyAssetsDir(buildTarget); } } // Reverse the resource directories/targets collections because we perform a post-order // traversal of the action graph, and we need to return these collections topologically // sorted. resourceDetailsBuilder.setResourceDirectories( resourceDirectories.build().reverse().stream().distinct().collect(Collectors.toList())); resourceDetailsBuilder.setResourcesWithNonEmptyResDir(resourcesWithNonEmptyResDir.build().reverse()); collectionBuilder.setResourceDetails(resourceDetailsBuilder.build()); return collectionBuilder.build(); }
From source file:com.google.template.soy.passes.CheckProtoInitCallsPass.java
private void checkProto(ProtoInitNode node, SoyProtoType soyType) { // Check that all proto required fields are present. // TODO(user): Consider writing a soyProtoTypeImpl.getRequiredFields() Set<String> givenParams = Sets.newHashSet(node.getParamNames()); for (FieldDescriptor field : soyType.getDescriptor().getFields()) { if (field.isRequired() && !givenParams.contains(field.getName())) { errorReporter.report(node.getSourceLocation(), MISSING_REQUIRED_FIELD, field.getName()); }//from w w w .j a va2 s .c om } ImmutableSet<String> fields = soyType.getFieldNames(); for (int i = 0; i < node.numChildren(); i++) { String fieldName = node.getParamNames().get(i); ExprNode expr = node.getChild(i); // Check that each arg exists in the proto. if (!fields.contains(fieldName)) { String extraErrorMessage = SoyErrors.getDidYouMeanMessageForProtoFields(fields, fieldName); errorReporter.report(expr.getSourceLocation(), FIELD_DOES_NOT_EXIST, fieldName, extraErrorMessage); continue; } // Check that the arg type is not null and that it matches the expected field type. SoyType argType = expr.getType(); if (argType.equals(NullType.getInstance())) { errorReporter.report(expr.getSourceLocation(), NULL_ARG_TYPE, fieldName); } SoyType fieldType = soyType.getFieldType(fieldName); // Let args with unknown or error types pass if (argType.equals(UnknownType.getInstance()) || argType.equals(ErrorType.getInstance())) { return; } // Same for List<?>, for repeated fields if (fieldType.getKind() == Kind.LIST && argType.getKind() == Kind.LIST) { SoyType argElementType = ((ListType) argType).getElementType(); if (argElementType == null || argElementType.equals(UnknownType.getInstance())) { return; } } SoyType expectedType = SoyTypes.makeNullable(fieldType); if (!expectedType.isAssignableFrom(argType)) { errorReporter.report(expr.getSourceLocation(), ARGUMENT_TYPE_MISMATCH, fieldName, expectedType, argType); } } }