List of usage examples for com.google.common.collect ImmutableSet equals
@Override public boolean equals(Object obj)
From source file:com.google.javascript.jscomp.newtypes.EnumType.java
static ImmutableSet<EnumType> union(ImmutableSet<EnumType> s1, ImmutableSet<EnumType> s2) { if (s1.isEmpty()) { return s2; }// ww w .j a v a 2s. co m if (s2.isEmpty() || s1.equals(s2)) { return s1; } return Sets.union(s1, s2).immutableCopy(); }
From source file:dagger.internal.codegen.BindingTypeMapper.java
/** * Returns the {@link BindingType} to use for a collection of requests of the same * {@link BindingKey}. This allows factories to only take a single argument for multiple requests * of the same key./* w w w.j a v a 2s .co m*/ */ BindingType getBindingType(Iterable<DependencyRequest> requests) { ImmutableSet<BindingType> classes = FluentIterable.from(requests) .transform(request -> getBindingType(request.kind())).toSet(); if (classes.size() == 1) { return getOnlyElement(classes); } else if (classes.equals(CONTRIBUTION_TYPES)) { return PROVISION; } else { throw new IllegalArgumentException("Bad set of framework classes: " + classes); } }
From source file:com.outerspacecat.cassandra.StaticSeededCluster.java
/** * Creates a new cluster./*from ww w.j av a 2 s. co m*/ * * @param name the name of the cluster. Must be non {@code null}. * @param keyspace the name of the keyspace to use for auto-discovering nodes. * Must be non {@code null}. * @param timeout the timeout in to use in milliseconds for both establishing * a connection and for reading and writing data. Will be used for both * contacting seeds and obtaining connections from discovered nodes. * Must be >= 0. 0 indicates an infinite timeout. * @param maxConnectionsPerNode the maximum number of connections allowed to * each node. Must be >= 0. * @param idleTimeout the amount of time in seconds before an unused * connection is considered idle. Must be >= 0. * @param seeds the seeds to use. Must be non {@code null}, contain at least * one element, and all elements must be non {@code null}. * @param port the port to use for both contacting seeds and obtaining * connections to nodes. Must be >= 1 and <= 65535. */ public StaticSeededCluster(final CharSequence name, final CharSequence keyspace, final int timeout, final int maxConnectionsPerNode, final int idleTimeout, final Iterable<InetAddress> seeds, final int port) { Preconditions.checkNotNull(name, "name required"); Preconditions.checkNotNull(keyspace, "keyspace required"); Preconditions.checkArgument(timeout >= 0, "timeout must be >= 0"); Preconditions.checkArgument(maxConnectionsPerNode >= 0, "maxConnectionsPerNode must be >= 0"); Preconditions.checkArgument(idleTimeout >= 0, "idleTimeout must be >= 0"); Preconditions.checkNotNull(seeds, "seeds required"); Preconditions.checkArgument(seeds.iterator().hasNext(), "seeds must be non empty"); Preconditions.checkArgument(port >= 1 && port <= 65535, "port must be >=1 and <= 65535"); final AtomicReference<ImmutableSet<String>> oldHosts = new AtomicReference<>(); exec.scheduleAtFixedRate(new Runnable() { @Override public void run() { for (InetAddress addr : seeds) { ImmutableSet.Builder<String> hostsBuilder = ImmutableSet.builder(); TSocket sock = new TSocket(addr.getHostAddress(), port, timeout); TTransport tr = new TFramedTransport(sock); try { tr.open(); } catch (TTransportException e) { continue; } Cassandra.Client client = new Cassandra.Client(new TBinaryProtocol(tr)); try { for (TokenRange range : client.describe_ring(keyspace.toString())) hostsBuilder.addAll(range.getEndpoints()); } catch (TException | InvalidRequestException e) { continue; } List<ConfiguredConnectionPoolDataSource<CassandraConnection>> dataSources = new ArrayList<>(); ImmutableSet<String> hosts = hostsBuilder.build(); if (hosts.equals(oldHosts.get())) return; oldHosts.set(hosts); for (String host : hosts) dataSources .add(DataSources.configure(host, new ThriftCassandraConnectionPoolDataSource( new InetSocketAddress(host, port), timeout), maxConnectionsPerNode, idleTimeout, 1)); ConnectionPool<CassandraConnection> pool = new ConnectionPool<>(name, dataSources); poolLock.lock(); try { StaticSeededCluster.this.pool = pool; poolInitialized.signalAll(); } finally { poolLock.unlock(); } Deque<HasConnectionPool.PoolChangedListener<CassandraConnection>> listeners = null; listenersLock.lock(); try { listeners = Queues.newArrayDeque(StaticSeededCluster.this.listeners); } finally { listenersLock.unlock(); } for (HasConnectionPool.PoolChangedListener<CassandraConnection> l : listeners) l.poolChanged(StaticSeededCluster.this); } } }, 0L, DEFAULT_REFRESH_PERIOD, TimeUnit.SECONDS); }
From source file:org.sosy_lab.cpachecker.cpa.deterministic.DeterministicVariablesState.java
@Override public DeterministicVariablesState join(DeterministicVariablesState pOther) { ImmutableSet<Wrapper<ASimpleDeclaration>> deterministicVariablesInboth = Sets .intersection(deterministicVariables, pOther.deterministicVariables).immutableCopy(); if (deterministicVariablesInboth.equals(pOther.deterministicVariables)) { return pOther; }/* w ww .ja va 2 s . c o m*/ return new DeterministicVariablesState(deterministicVariablesInboth); }
From source file:com.jeffreybosboom.lyne.Puzzle.java
private Puzzle set(Node a, Node b, Set<Node.Kind> possibilities) { //private because rules actually want to call restrict instead Pair<Node, Node> p = Pair.sorted(a, b); ImmutableSet<Node.Kind> currentPossibilities = possibilities(a, b); if (possibilities.isEmpty() || !currentPossibilities.containsAll(possibilities)) throw new ContradictionException(); if (currentPossibilities.equals(possibilities)) return this; return withEdgeSet(p, ImmutableSet.copyOf(possibilities)); }
From source file:com.google.devtools.build.lib.testutil.BazelPackageBuilderHelperForTesting.java
private synchronized void sanityCheckBazelPackageLoader(Package pkg, RuleClassProvider ruleClassProvider, SkylarkSemantics skylarkSemantics) { PackageIdentifier pkgId = pkg.getPackageIdentifier(); if (pkgId.equals(Label.EXTERNAL_PACKAGE_IDENTIFIER) || !pkg.getPackageIdentifier().getRepository().isMain() || PackageFunction.isDefaultsPackage(pkg.getPackageIdentifier())) { // TODO(nharmata): Support these packages. return;/*from w w w . j a v a 2 s. c o m*/ } int numNameSegments = pkg.getNameFragment().segmentCount(); PathFragment fullFilenameFragment = pkg.getFilename().asFragment(); int numFullFilenameFragmentSegments = fullFilenameFragment.segmentCount(); Path workspaceRoot = pkg.getFilename().getFileSystem().getPath( fullFilenameFragment.subFragment(0, numFullFilenameFragmentSegments - (numNameSegments + 1))); PackageLoader packageLoader = BazelPackageLoader.builder(workspaceRoot) .setSkylarkSemantics(skylarkSemantics).setRuleClassProvider(ruleClassProvider).build(); Package newlyLoadedPkg; try { newlyLoadedPkg = packageLoader.loadPackage(pkg.getPackageIdentifier()); } catch (InterruptedException e) { return; } catch (NoSuchPackageException e) { throw new IllegalStateException(e); } ImmutableSet<Label> targetsInPkg = ImmutableSet .copyOf(Iterables.transform(pkg.getTargets().values(), TARGET_TO_LABEL)); ImmutableSet<Label> targetsInNewlyLoadedPkg = ImmutableSet .copyOf(Iterables.transform(newlyLoadedPkg.getTargets().values(), TARGET_TO_LABEL)); if (!targetsInPkg.equals(targetsInNewlyLoadedPkg)) { throw new IllegalStateException(String.format( "The Package for %s had a different set of targets (<targetsInPkg> - " + "<targetsInNewlyLoadedPkg> = %s, <targetsInNewlyLoadedPkg> - <targetsInPkg> = %s) when " + "loaded normally during execution of the current test than it did when loaded via " + "BazelPackageLoader (done automatically by the BazelPackageBuilderHelperForTesting " + "hook). This either means: (i) Skyframe package loading semantics have diverged from " + "BazelPackageLoader semantics (ii) The test in question is doing something that " + "confuses BazelPackageBuilderHelperForTesting.", pkgId, Sets.difference(targetsInPkg, targetsInNewlyLoadedPkg), Sets.difference(targetsInNewlyLoadedPkg, targetsInPkg))); } }
From source file:dagger.internal.codegen.DependencyRequestMapper.java
/** * Returns the framework class to use for a collection of requests of the same {@link BindingKey}. * This allows factories to only take a single argument for multiple requests of the same key. *//*ww w. j a v a2 s . c o m*/ Class<?> getFrameworkClass(Iterable<DependencyRequest> requests) { ImmutableSet<Class<?>> classes = FluentIterable.from(requests) .transform(new Function<DependencyRequest, Class<?>>() { @Override public Class<?> apply(DependencyRequest request) { return getFrameworkClass(request); } }).toSet(); if (classes.size() == 1) { return getOnlyElement(classes); } else if (classes.equals(ImmutableSet.of(Producer.class, Provider.class))) { return Provider.class; } else { throw new IllegalStateException("Bad set of framework classes: " + classes); } }
From source file:com.facebook.buck.cxx.CxxTestDescription.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> flavors) { if (flavors.isEmpty()) { return true; }/*from ww w. j a va 2s . 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.ikanow.aleph2.analytics.storm.services.MockAnalyticsContext.java
@Override public String getAnalyticsContextSignature(final Optional<DataBucketBean> bucket, final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) { if (_state_name == State.IN_TECHNOLOGY) { // Returns a config object containing: // - set up for any of the services described // - all the rest of the configuration // - the bucket bean ID final Config full_config = ModuleUtils.getStaticConfig() .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME) .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service) ;/* w w w.j av a2s . c o m*/ final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service"); final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = ImmutableSet .<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder() .addAll(services.orElse(Collections.emptySet())) .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty())) .add(Tuples._2T(IManagementDbService.class, Optional.empty())) .add(Tuples._2T(ISearchIndexService.class, Optional.empty())) .add(Tuples._2T(ISecurityService.class, Optional.empty())) .add(Tuples._2T(IStorageService.class, Optional.empty())) .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)).build(); if (_mutable_state.service_manifest_override.isSet()) { if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) { throw new RuntimeException(ErrorUtils.SERVICE_RESTRICTIONS); } } else { _mutable_state.service_manifest_override.set(complete_services_set); } final Config config_no_services = full_config.withoutPath("service"); // Ugh need to add: core deps, core + underlying management db to this list final Config service_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW .map(clazz_name -> { final String config_path = clazz_name._2() .orElse(clazz_name._1().getSimpleName().substring(1)); return service_config.get().hasPath(config_path) ? Tuples._2T(config_path, service_config.get().getConfig(config_path)) : null; }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(), (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel) ); final Config config_subset_services = config_no_services.withValue("service", service_subset.root()); final Config last_call = Lambdas .get(() -> _mutable_state.library_configs.isSet() ? config_subset_services .withValue(__MY_MODULE_LIBRARY_ID, ConfigValueFactory .fromAnyRef(BeanTemplateUtils .toJson(new LibraryContainerBean( _mutable_state.library_configs.get().entrySet() .stream() .filter(kv -> kv.getValue().path_name() .equals(kv.getKey())) .map(kv -> kv.getValue()) .collect(Collectors.toList()))) .toString())) : config_subset_services) .withValue(__MY_BUCKET_ID, ConfigValueFactory.fromAnyRef(BeanTemplateUtils .toJson(bucket.orElseGet(() -> _mutable_state.bucket.get())).toString())) .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef( BeanTemplateUtils.toJson(_mutable_state.technology_config.get()).toString())); final String ret1 = last_call.root().render(ConfigRenderOptions.concise()); _mutable_state.signature_override.set(ret1); final String ret = this.getClass().getName() + ":" + ret1; this.overrideSavedContext(); // (FOR TESTING ONLY - ie BECAUSE THIS IS MOCK ANALYTIC CONTEXT) return ret; } else { throw new RuntimeException(ErrorUtils.TECHNOLOGY_NOT_MODULE); } }
From source file:com.ikanow.aleph2.analytics.hadoop.services.MockAnalyticsContext.java
@Override public String getAnalyticsContextSignature(final Optional<DataBucketBean> bucket, final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) { if (_state_name == State.IN_TECHNOLOGY) { // Returns a config object containing: // - set up for any of the services described // - all the rest of the configuration // - the bucket bean ID final Config full_config = ModuleUtils.getStaticConfig() .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME) .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service) ;/*from ww w .ja v a 2 s . c om*/ final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service"); final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = ImmutableSet .<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder() .addAll(services.orElse(Collections.emptySet())) .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty())) .add(Tuples._2T(IManagementDbService.class, Optional.empty())) .add(Tuples._2T(ISearchIndexService.class, Optional.empty())) .add(Tuples._2T(ISecurityService.class, Optional.empty())) .add(Tuples._2T(IStorageService.class, Optional.empty())) .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)).build(); if (_mutable_state.service_manifest_override.isSet()) { if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) { throw new RuntimeException(HadoopErrorUtils.SERVICE_RESTRICTIONS); } } else { _mutable_state.service_manifest_override.set(complete_services_set); } final Config config_no_services = full_config.withoutPath("service"); // Ugh need to add: core deps, core + underlying management db to this list final Config service_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW .map(clazz_name -> { final String config_path = clazz_name._2() .orElse(clazz_name._1().getSimpleName().substring(1)); return service_config.get().hasPath(config_path) ? Tuples._2T(config_path, service_config.get().getConfig(config_path)) : null; }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(), (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel) ); final Config config_subset_services = config_no_services.withValue("service", service_subset.root()); final Config last_call = Lambdas .get(() -> _mutable_state.library_configs.isSet() ? config_subset_services .withValue(__MY_MODULE_LIBRARY_ID, ConfigValueFactory .fromAnyRef(BeanTemplateUtils .toJson(new LibraryContainerBean( _mutable_state.library_configs.get().entrySet() .stream() .filter(kv -> kv.getValue().path_name() .equals(kv.getKey())) .map(kv -> kv.getValue()) .collect(Collectors.toList()))) .toString())) : config_subset_services) .withValue(__MY_BUCKET_ID, ConfigValueFactory.fromAnyRef(BeanTemplateUtils .toJson(bucket.orElseGet(() -> _mutable_state.bucket.get())).toString())) .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef( BeanTemplateUtils.toJson(_mutable_state.technology_config.get()).toString())); final String ret1 = last_call.root().render(ConfigRenderOptions.concise()); _mutable_state.signature_override.set(ret1); final String ret = this.getClass().getName() + ":" + ret1; this.overrideSavedContext(); // (FOR TESTING ONLY - ie BECAUSE THIS IS MOCK ANALYTIC CONTEXT) return ret; } else { throw new RuntimeException(HadoopErrorUtils.TECHNOLOGY_NOT_MODULE); } }