List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:com.google.errorprone.refaster.BlockTemplate.java
private Choice<List<BlockTemplateMatch>> matchesStartingAnywhere(JCBlock block, int offset, final ImmutableList<? extends StatementTree> statements, final Context context) { Choice<List<BlockTemplateMatch>> choice = Choice.none(); for (int i = 0; i < statements.size(); i++) { choice = choice.or(matchesStartingAtBeginning(block, offset + i, statements.subList(i, statements.size()), context)); }/* w w w . j av a 2 s. c om*/ return choice.or(Choice.of(List.<BlockTemplateMatch>nil())); }
From source file:com.facebook.buck.event.listener.RenderingConsole.java
private String renderFullFrame(ImmutableList<String> logLines, ImmutableList<String> lines, int previousNumLinesPrinted) { int currentNumLines = lines.size(); Iterable<String> renderedLines = Iterables.concat( MoreIterables.zipAndConcat(Iterables.cycle(ansi.clearLine()), logLines, Iterables.cycle(ansi.clearToTheEndOfLine() + System.lineSeparator())), ansi.asNoWrap(MoreIterables.zipAndConcat(Iterables.cycle(ansi.clearLine()), lines, Iterables.cycle(ansi.clearToTheEndOfLine() + System.lineSeparator())))); // Number of lines remaining to clear because of old output once we displayed // the new output. int remainingLinesToClear = previousNumLinesPrinted > currentNumLines ? previousNumLinesPrinted - currentNumLines : 0;/*from w ww .ja v a 2 s . com*/ StringBuilder fullFrame = new StringBuilder(); // We move the cursor back to the top. for (int i = 0; i < previousNumLinesPrinted; i++) { fullFrame.append(ansi.cursorPreviousLine(1)); } // We display the new output. for (String part : renderedLines) { fullFrame.append(part); } // We clear the remaining lines of the old output. for (int i = 0; i < remainingLinesToClear; i++) { fullFrame.append(ansi.clearLine()); fullFrame.append(System.lineSeparator()); } // We move the cursor at the end of the new output. for (int i = 0; i < remainingLinesToClear; i++) { fullFrame.append(ansi.cursorPreviousLine(1)); } return fullFrame.toString(); }
From source file:com.facebook.buck.rules.modern.builders.MultiThreadedBlobUploader.java
private void processUploads() { processMissing();//from w w w . ja v a 2s . c o m ImmutableMap.Builder<String, PendingUpload> dataBuilder = ImmutableMap.builder(); int size = 0; while (size < uploadSizeLimit && !waitingUploads.isEmpty()) { PendingUpload data = waitingUploads.poll(); if (data == null) { break; } dataBuilder.put(data.getHash(), data); size += data.uploadData.digest.getSize(); } ImmutableMap<String, PendingUpload> data = dataBuilder.build(); if (!data.isEmpty()) { try { ImmutableList.Builder<UploadData> blobsBuilder = ImmutableList.builder(); for (PendingUpload entry : data.values()) { blobsBuilder.add(entry.uploadData); } ImmutableList<UploadData> blobs = data.values().stream().map(e -> e.uploadData) .collect(ImmutableList.toImmutableList()); ImmutableList<UploadResult> results = asyncBlobUploader.batchUpdateBlobs(blobs); Preconditions.checkState(results.size() == blobs.size()); results.forEach(result -> { PendingUpload pendingUpload = Preconditions.checkNotNull(data.get(result.digest.getHash())); if (result.status == 0) { pendingUpload.future.set(null); } else { pendingUpload.future.setException(new IOException( String.format("Failed uploading with message: %s", result.message))); } }); data.forEach((k, pending) -> pending.future.setException(new RuntimeException("idk"))); } catch (Exception e) { data.forEach((k, pending) -> pending.future.setException(e)); } } if (!waitingMissingCheck.isEmpty() || !waitingUploads.isEmpty()) { uploadService.submit(this::processUploads); } }
From source file:de.metas.ui.web.quickinput.QuickInputDescriptorFactoryService.java
private IQuickInputDescriptorFactory getQuickInputDescriptorFactory( final IQuickInputDescriptorFactory.MatchingKey matchingKey) { final ImmutableList<IQuickInputDescriptorFactory> matchingFactories = factories.get(matchingKey); if (matchingFactories.isEmpty()) { return null; }//from w ww. j a va2 s .c o m if (matchingFactories.size() > 1) { logger.warn("More than one factory found for {}. Using the first one: {}", matchingFactories); } return matchingFactories.get(0); }
From source file:com.github.explainable.sql.table.BaseTable.java
@Nonnull @Override//from www . ja va 2 s.c o m public ImmutableList<BaseColumn> columns() { if (columns == null) { ImmutableList<String> fieldNames = relation.columnNames(); ImmutableList<PrimitiveType> types = relation.type().columnTypes(); ImmutableList.Builder<BaseColumn> columnsBuilder = ImmutableList.builder(); for (int i = 0; i < fieldNames.size(); i++) { columnsBuilder.add(new BaseColumn(fieldNames.get(i), this, types.get(i))); } columns = columnsBuilder.build(); } return columns; }
From source file:org.apache.kylin.query.relnode.visitor.TupleFilterVisitor.java
private TupleFilter dealWithTrivialExpr(RexCall call) { ImmutableList<RexNode> operators = call.operands; if (operators.size() != 2) { return null; }/*from w w w .ja v a2 s . com*/ BigDecimal left = null; BigDecimal right = null; for (RexNode rexNode : operators) { if (!(rexNode instanceof RexLiteral)) { return null;// only trivial expr with constants } RexLiteral temp = (RexLiteral) rexNode; if (temp.getType().getFamily() != SqlTypeFamily.NUMERIC || !(temp.getValue() instanceof BigDecimal)) { return null;// only numeric constants now } if (left == null) { left = (BigDecimal) temp.getValue(); } else { right = (BigDecimal) temp.getValue(); } } Preconditions.checkNotNull(left); Preconditions.checkNotNull(right); switch (call.op.getKind()) { case PLUS: return new ConstantTupleFilter(left.add(right).toString()); case MINUS: return new ConstantTupleFilter(left.subtract(right).toString()); case TIMES: return new ConstantTupleFilter(left.multiply(right).toString()); case DIVIDE: return new ConstantTupleFilter(left.divide(right).toString()); default: return null; } }
From source file:com.github.rinde.gpem17.evo.FitnessEvaluator.java
@Override public void evaluatePopulation(EvolutionState state) { SetMultimap<GPNodeHolder, IndividualHolder> mapping = getGPFitnessMapping(state); int fromIndex; if (useDifferentScenariosEveryGen) { fromIndex = state.generation * numScenariosPerGen; } else {/* w w w . ja va2s. c om*/ fromIndex = 0; } int toIndex; int compSize; if (state.generation == state.numGenerations - 1) { compSize = compositeSize * 5; toIndex = fromIndex + numScenariosInLastGen; } else { compSize = compositeSize; toIndex = fromIndex + numScenariosPerGen; } System.out.println( scenariosDir + " " + paths.subList(fromIndex, toIndex).toString().replace(scenariosDir + "/", "")); String[] args; if (distributed) { args = new String[] { "--jppf", "--repetitions", "1", "--composite-size", Integer.toString(compSize) }; } else { args = new String[] { "--repetitions", "1" }; } File generationDir = new File(((StatsLogger) state.statistics).experimentDirectory, "generation" + state.generation); List<GPProgram<GpGlobal>> programs = new ArrayList<>(); List<GPNodeHolder> nodes = ImmutableList.copyOf(mapping.keySet()); for (GPNodeHolder node : nodes) { final GPProgram<GpGlobal> prog = GPProgramParser .convertToGPProgram((GPBaseNode<GpGlobal>) node.trees[0].child); programs.add(prog); } ExperimentResults results = Evaluate.execute(programs, false, FileProvider.builder().add(paths.subList(fromIndex, toIndex)), generationDir, false, Converter.INSTANCE, false, reauctOpt, objectiveFunction, null, false, false, 0L, args); Map<MASConfiguration, GPNodeHolder> configMapping = new LinkedHashMap<>(); ImmutableList<MASConfiguration> configs = results.getConfigurations().asList(); verify(configs.size() == nodes.size()); for (int i = 0; i < configs.size(); i++) { configMapping.put(configs.get(i), nodes.get(i)); } List<GPComputationResult> convertedResults = new ArrayList<>(); for (SimulationResult sr : results.getResults()) { StatisticsDTO stats = ((SimResult) sr.getResultObject()).getStats(); double cost = objectiveFunction.computeCost(stats); float fitness = (float) cost; if (!objectiveFunction.isValidResult(stats)) { // if the simulation is terminated early, we give a huge penalty, which // we reduce based on how far the simulation actually got. fitness = Float.MAX_VALUE - stats.simulationTime; } String id = configMapping.get(sr.getSimArgs().getMasConfig()).string; convertedResults.add(SingleResult.create((float) fitness, id, sr)); } processResults(state, mapping, convertedResults); }
From source file:com.facebook.buck.util.ClassLoaderCache.java
public synchronized ClassLoader getClassLoaderForClassPath(@Nullable ClassLoader parentClassLoader, ImmutableList<URL> classPath) { Map<ImmutableList<URL>, ClassLoader> cacheForParent = getCacheForParent(parentClassLoader); ClassLoader classLoader = cacheForParent.get(classPath); if (classLoader == null) { URL[] urls = classPath.toArray(new URL[classPath.size()]); classLoader = new URLClassLoader(urls, parentClassLoader); cacheForParent.put(classPath, classLoader); }//from w ww. ja va 2 s. c o m return classLoader; }
From source file:com.hmaimi.jodis.RoundRobinJedisPool.java
private void resetPools() { ImmutableList<PooledObject> pools = this.pools; Map<String, PooledObject> addr2Pool = Maps.newHashMapWithExpectedSize(pools.size()); for (PooledObject pool : pools) { addr2Pool.put(pool.addr, pool);/*from w ww . j a v a 2 s. c o m*/ } ImmutableList.Builder<PooledObject> builder = ImmutableList.builder(); for (ChildData childData : watcher.getCurrentData()) { try { JsonNode proxyInfo = MAPPER.readTree(childData.getData()); if (!CODIS_PROXY_STATE_ONLINE.equals(proxyInfo.get(JSON_NAME_CODIS_PROXY_STATE).asText())) { continue; } String addr = proxyInfo.get(JSON_NAME_CODIS_PROXY_ADDR).asText(); PooledObject pool = addr2Pool.remove(addr); if (pool == null) { LOG.info("Add new proxy: " + addr); String[] hostAndPort = addr.split(":"); pool = new PooledObject(addr, new JedisPool(poolConfig, hostAndPort[0], Integer.parseInt(hostAndPort[1]))); } builder.add(pool); } catch (Exception e) { LOG.warn("parse " + childData.getPath() + " failed", e); } } this.pools = builder.build(); for (PooledObject pool : addr2Pool.values()) { LOG.info("Remove proxy: " + pool.addr); pool.pool.close(); } }
From source file:ru.adios.budgeter.activities.BalancesTransferActivity.java
@Nullable private long[] transformLongList(ImmutableList<Long> list) { int listSize = list.size(); if (listSize == 0) { return null; }/* www. ja v a 2 s. c om*/ final long[] res = new long[listSize]; for (int i1 = 0; i1 < listSize; i1++) { final Long i = list.get(i1); res[i1] = i != null ? i : -1; } return res; }