List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.cost.HiveAlgorithmsUtil.java
public double computeBucketMapJoinCPUCost(ImmutableList<Double> cardinalities, ImmutableBitSet streaming) { // Hash-join//from w ww.j a v a 2 s . c o m double cpuCost = 0.0; for (int i = 0; i < cardinalities.size(); i++) { double cardinality = cardinalities.get(i); if (!streaming.get(i)) { cpuCost += cardinality * cpuCost; } cpuCost += cardinality * cpuCost; } return cpuCost; }
From source file:com.palantir.docker.compose.execution.DefaultDockerCompose.java
private String[] constructFullDockerComposeExecArguments(DockerComposeExecOption dockerComposeExecOption, String containerName, DockerComposeExecArgument dockerComposeExecArgument) { ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("exec") .addAll(dockerComposeExecOption.options()).add(containerName) .addAll(dockerComposeExecArgument.arguments()).build(); return fullArgs.toArray(new String[fullArgs.size()]); }
From source file:com.google.cloud.bigtable.grpc.io.ChannelPool.java
/** * Performs a simple round robin on the list of {@link InstrumentedChannel}s in the {@code channels} * list. This method should not be synchronized, if possible, to reduce bottlenecks. * * @return A {@link InstrumentedChannel} that can be used for a single RPC call. *///from ww w . ja v a2s. co m private InstrumentedChannel getNextChannel() { int currentRequestNum = requestCount.getAndIncrement(); ImmutableList<InstrumentedChannel> channelsList = channels.get(); int index = Math.abs(currentRequestNum % channelsList.size()); return channelsList.get(index); }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.cost.HiveAlgorithmsUtil.java
public double computeSortMergeCPUCost(ImmutableList<Double> cardinalities, ImmutableBitSet sorted) { // Sort-merge join double cpuCost = 0.0; for (int i = 0; i < cardinalities.size(); i++) { double cardinality = cardinalities.get(i); if (!sorted.get(i)) { // Sort cost cpuCost += computeSortCPUCost(cardinality); }//from w w w . j a v a 2s . co m // Merge cost cpuCost += cardinality * cpuCost; } return cpuCost; }
From source file:com.facebook.buck.parser.TargetSpecResolver.java
private Multimap<Path, Integer> groupSpecsByBuildFile(Cell rootCell, ImmutableList<TargetNodeSpec> orderedSpecs) { Multimap<Path, Integer> perBuildFileSpecs = LinkedHashMultimap.create(); for (int index = 0; index < orderedSpecs.size(); index++) { TargetNodeSpec spec = orderedSpecs.get(index); Path cellPath = spec.getBuildFileSpec().getCellPath(); Cell cell = rootCell.getCell(cellPath); try (SimplePerfEvent.Scope perfEventScope = SimplePerfEvent.scope(eventBus, PerfEventId.of("FindBuildFiles"), "targetNodeSpec", spec)) { BuildFileSpec buildFileSpec = spec.getBuildFileSpec(); ProjectFilesystemView projectFilesystemView = cell.getFilesystemViewForSourceFiles(); if (!buildFileSpec.isRecursive()) { // If spec is not recursive, i.e. //path/to:something, then we only need to look for // build file under base path Path buildFile = projectFilesystemView .resolve(buildFileSpec.getBasePath().resolve(cell.getBuildFileName())); perBuildFileSpecs.put(buildFile, index); } else { // For recursive spec, i.e. //path/to/... we use cached file tree Path basePath = spec.getBuildFileSpec().getBasePath(); // sometimes spec comes with absolute path as base path, sometimes it is relative to // cell path // TODO(sergeyb): find out why if (basePath.isAbsolute()) { basePath = cellPath.relativize(basePath); }/*from w w w. ja v a 2 s.co m*/ FileTree fileTree = graphEngineForRecursiveSpecPerRoot.getUnchecked(cellPath) .computeUnchecked(ImmutableFileTreeKey.of(basePath)); for (Path path : FileTreeFileNameIterator.ofIterable(fileTree, cell.getBuildFileName())) { perBuildFileSpecs.put(projectFilesystemView.resolve(path), index); } } } } return perBuildFileSpecs; }
From source file:google.registry.loadtest.LoadTestAction.java
@Override public void run() { validateAndLogRequest();//from ww w . j av a 2s .com DateTime initialStartSecond = DateTime.now(UTC).plusSeconds(delaySeconds); ImmutableList.Builder<String> preTaskXmls = new ImmutableList.Builder<>(); ImmutableList.Builder<String> contactNamesBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder<String> hostPrefixesBuilder = new ImmutableList.Builder<>(); for (int i = 0; i < successfulDomainCreatesPerSecond; i++) { String contactName = getRandomLabel(MAX_CONTACT_LENGTH); String hostPrefix = getRandomLabel(ARBITRARY_VALID_HOST_LENGTH); contactNamesBuilder.add(contactName); hostPrefixesBuilder.add(hostPrefix); preTaskXmls.add(xmlContactCreateTmpl.replace("%contact%", contactName), xmlHostCreateTmpl.replace("%host%", hostPrefix)); } enqueue(createTasks(preTaskXmls.build(), DateTime.now(UTC))); ImmutableList<String> contactNames = contactNamesBuilder.build(); ImmutableList<String> hostPrefixes = hostPrefixesBuilder.build(); ImmutableList.Builder<TaskOptions> tasks = new ImmutableList.Builder<>(); for (int offsetSeconds = 0; offsetSeconds < runSeconds; offsetSeconds++) { DateTime startSecond = initialStartSecond.plusSeconds(offsetSeconds); // The first "failed" creates might actually succeed if the object doesn't already exist, but // that shouldn't affect the load numbers. tasks.addAll( createTasks(createNumCopies(xmlContactCreateFail, failedContactCreatesPerSecond), startSecond)); tasks.addAll(createTasks(createNumCopies(xmlHostCreateFail, failedHostCreatesPerSecond), startSecond)); tasks.addAll( createTasks(createNumCopies(xmlDomainCreateFail, failedDomainCreatesPerSecond), startSecond)); // We can do infos on the known existing objects. tasks.addAll(createTasks(createNumCopies(xmlContactInfo, contactInfosPerSecond), startSecond)); tasks.addAll(createTasks(createNumCopies(xmlHostInfo, hostInfosPerSecond), startSecond)); tasks.addAll(createTasks(createNumCopies(xmlDomainInfo, domainInfosPerSecond), startSecond)); // The domain check template uses "example.TLD" which won't exist, and one existing domain. tasks.addAll(createTasks(createNumCopies(xmlDomainCheck, domainChecksPerSecond), startSecond)); // Do successful creates on random names tasks.addAll( createTasks(transform(createNumCopies(xmlContactCreateTmpl, successfulContactCreatesPerSecond), randomNameReplacer("%contact%", MAX_CONTACT_LENGTH)), startSecond)); tasks.addAll(createTasks(transform(createNumCopies(xmlHostCreateTmpl, successfulHostCreatesPerSecond), randomNameReplacer("%host%", ARBITRARY_VALID_HOST_LENGTH)), startSecond)); tasks.addAll(createTasks( FluentIterable.from(createNumCopies(xmlDomainCreateTmpl, successfulDomainCreatesPerSecond)) .transform(randomNameReplacer("%domain%", MAX_DOMAIN_LABEL_LENGTH)) .transform(listNameReplacer("%contact%", contactNames)) .transform(listNameReplacer("%host%", hostPrefixes)).toList(), startSecond)); } ImmutableList<TaskOptions> taskOptions = tasks.build(); enqueue(taskOptions); logger.infofmt("Added %d total load test tasks", taskOptions.size()); }
From source file:com.hmaimi.jodis.RoundRobinJedisPool.java
/** * Get a jedis instance from pool.//from w w w.ja v a2 s . c o m * <p> * We do not have a returnResource method, just close the jedis instance * returned directly. * * @return */ public Jedis getResource() { ImmutableList<PooledObject> pools = this.pools; if (pools.isEmpty()) { throw new JedisException("Proxy list empty"); } for (;;) { int current = nextIdx.get(); int next = current >= pools.size() - 1 ? 0 : current + 1; if (nextIdx.compareAndSet(current, next)) { return pools.get(next).pool.getResource(); } } }
From source file:net.hydromatic.optiq.prepare.OptiqCatalogReader.java
private List<SqlOperator> toOps(final String name, final ImmutableList<TableFunction> tableFunctions) { return new AbstractList<SqlOperator>() { public SqlOperator get(int index) { return toOp(name, tableFunctions.get(index)); }/* ww w.j a va 2 s . c o m*/ public int size() { return tableFunctions.size(); } }; }
From source file:org.sosy_lab.cpachecker.cpa.composite.CompositePrecisionAdjustment.java
public CompositePrecisionAdjustment(ImmutableList<PrecisionAdjustment> precisionAdjustments) { this.precisionAdjustments = precisionAdjustments; ImmutableList.Builder<StateProjectionFunction> stateProjectionFunctions = ImmutableList.builder(); ImmutableList.Builder<PrecisionProjectionFunction> precisionProjectionFunctions = ImmutableList.builder(); for (int i = 0; i < precisionAdjustments.size(); i++) { stateProjectionFunctions.add(new StateProjectionFunction(i)); precisionProjectionFunctions.add(new PrecisionProjectionFunction(i)); }/*from www . j a va 2 s .com*/ this.stateProjectionFunctions = stateProjectionFunctions.build(); this.precisionProjectionFunctions = precisionProjectionFunctions.build(); }
From source file:com.kolich.curacao.CuracaoControllerInvoker.java
@Override public final Object call() throws Exception { // The path within the application represents the part of the URI // without the Servlet context, if any. For example, if the Servlet // content is "/foobar" and the incoming request was GET:/foobar/baz, // then this method will return just "/baz". final String pathWithinApplication = pathHelper_.getPathWithinApplication(ctx_); logger__.debug("Computed path within application context " + "(requestUri={}, computedPath={})", ctx_.comment_, pathWithinApplication); // Attach the path within the application to the mutable context. ctx_.setPathWithinApplication(pathWithinApplication); // Get a list of all supported application routes based on the // incoming HTTP request method. final ImmutableList<CuracaoInvokable> candidates = ctx_.requestMappingTable_ .getRoutesByHttpMethod(ctx_.method_); logger__.debug("Found {} controller candidates for request: {}:{}", candidates.size(), ctx_.method_, pathWithinApplication);/* w ww. j a v a 2s. co m*/ // Check if we found any viable candidates for the incoming HTTP // request method. If we didn't find any, immediately bail letting // the user know this incoming HTTP request method just isn't // supported by the implementation. if (candidates.isEmpty()) { throw new PathNotFoundException( "Found 0 (zero) controller " + "candidates for request: " + ctx_.comment_); } // For each viable option, need to compare the path provided // with the attached invokable method annotation to decide // if that path matches the request. CuracaoInvokable invokable = null; Map<String, String> pathVars = null; for (final CuracaoInvokable i : candidates) { // O(n) logger__.debug("Checking invokable method candidate: {}", i); // Get the matcher instance from the invokable. final CuracaoPathMatcher matcher = i.matcher_.instance_; // The matcher will return 'null' if the provided pattern did not // match the path within application. pathVars = matcher.match(ctx_, // The path mapping registered with the invokable. i.mapping_, // The path within the application. pathWithinApplication); if (pathVars != null) { // Matched! logger__.debug("Extracted path variables: {}", pathVars); invokable = i; break; } } // If we found ~some~ method that supports the incoming HTTP request // type, but no proper annotated controller method that matches // the request path, that means we've got nothing. if (invokable == null) { throw new PathNotFoundException( "Found no invokable controller " + "method worthy of servicing request: " + ctx_.comment_); } // Attach extracted path variables from the matcher onto the mutable context. ctx_.setPathVariables(pathVars); // Invoke each of the request filters attached to the controller // method invokable, in order. Any filter may throw an exception, // which is totally fair and will be handled by the upper-layer. for (final InvokableClassWithInstance<? extends CuracaoRequestFilter> filter : invokable.filters_) { filter.instance_.filter(ctx_); } // Build the parameter list to be passed into the controller method // via reflection. final Object[] parameters = buildPopulatedParameterList(invokable); // Reflection invoke the discovered "controller" method. final Object invokedResult = invokable.method_.invoke( // The controller class. invokable.controller_.instance_, // Method arguments/parameters. parameters); // A set of hard coded controller return type pre-processors. That is, // we take the type/object that the controller returned once invoked // and see if we need to do anything special with it in this request // context (using the thread that's handling the _REQUEST_). Object o = invokedResult; if (invokedResult instanceof Callable) { o = ((Callable<?>) invokedResult).call(); } else if (invokedResult instanceof Future) { o = ((Future<?>) invokedResult).get(); } return o; }