List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:org.apache.brooklyn.location.jclouds.networking.SecurityGroupEditor.java
/** * Find a security group with the given name. As we use jclouds, groups are created with names prefixed * with {@link #JCLOUDS_PREFIX_REGEX}. For convenience this method accepts names either with or without * the prefix./* www . j a va 2 s .c om*/ * @param name Name of the group to find. * @return An optional of the group. * @throws AmbiguousGroupName in the unexpected case that the cloud returns more than one matching group. */ public Optional<SecurityGroup> findSecurityGroupByName(final String name) { final Iterable<SecurityGroup> groupsMatching = findSecurityGroupsMatching(new Predicate<SecurityGroup>() { final String rawName = name.replaceAll(JCLOUDS_PREFIX_REGEX, ""); @Override public boolean apply(final SecurityGroup input) { return input.getName().replaceAll(JCLOUDS_PREFIX_REGEX, "").equals(rawName); } }); final ImmutableList<SecurityGroup> matches = ImmutableList.copyOf(groupsMatching); if (matches.size() == 0) { return Optional.absent(); } else if (matches.size() == 1) { return Optional.of(matches.get(0)); } else { throw new AmbiguousGroupName("Unexpected result of multiple groups matching " + name); } }
From source file:org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.java
@Override public void build(IBuildContext buildContext, IProgressMonitor monitor) throws CoreException { ImmutableList<IXtextBuilderParticipant> participants = getParticipants(); if (participants.isEmpty()) return;/*ww w . j av a 2s . c o m*/ SubMonitor progress = SubMonitor.convert(monitor, participants.size()); progress.subTask(Messages.RegistryBuilderParticipant_InvokingBuildParticipants); for (IXtextBuilderParticipant participant : participants) { if (progress.isCanceled()) throw new OperationCanceledException(); participant.build(buildContext, progress.newChild(1)); } }
From source file:google.registry.rdap.RdapDomainSearchAction.java
/** * Output JSON for a list of domains./*from w w w . ja v a2 s. c om*/ * * <p>The isTruncated parameter should be true if the search found more results than are in the * list, meaning that the truncation notice should be added. */ private RdapSearchResults makeSearchResults(ImmutableList<DomainResource> domains, boolean isTruncated, DateTime now) { OutputDataType outputDataType = (domains.size() > 1) ? OutputDataType.SUMMARY : OutputDataType.FULL; ImmutableList.Builder<ImmutableMap<String, Object>> jsonBuilder = new ImmutableList.Builder<>(); for (DomainResource domain : domains) { jsonBuilder.add(rdapJsonFormatter.makeRdapJsonForDomain(domain, false, rdapLinkBase, rdapWhoisServer, now, outputDataType)); } return RdapSearchResults.create(jsonBuilder.build(), isTruncated); }
From source file:org.apache.hadoop.hbase.regionserver.DefaultStoreFileManager.java
@Override public Collection<StoreFile> getUnneededFiles(long maxTs, List<StoreFile> filesCompacting) { Collection<StoreFile> expiredStoreFiles = null; ImmutableList<StoreFile> files = storefiles; // 1) We can never get rid of the last file which has the maximum seqid. // 2) Files that are not the latest can't become one due to (1), so the rest are fair game. for (int i = 0; i < files.size() - 1; ++i) { StoreFile sf = files.get(i);/*from w w w .j a v a2 s . c om*/ long fileTs = sf.getReader().getMaxTimestamp(); if (fileTs < maxTs && !filesCompacting.contains(sf)) { LOG.info("Found an expired store file: " + sf.getPath() + " whose maxTimeStamp is " + fileTs + ", which is below " + maxTs); if (expiredStoreFiles == null) { expiredStoreFiles = new ArrayList<StoreFile>(); } expiredStoreFiles.add(sf); } } return expiredStoreFiles; }
From source file:org.pentaho.di.trans.dataservice.optimization.paramgen.ui.ParameterGenerationModel.java
protected void updateParameterMap() { ImmutableList<PushDownOptimizationMeta> list = dialogModel .getPushDownOptimizations(ParameterGeneration.class); Map<String, PushDownOptimizationMeta> map = Maps.newHashMapWithExpectedSize(list.size()); for (PushDownOptimizationMeta meta : list) { ParameterGeneration parameterGeneration = (ParameterGeneration) meta.getType(); String parameterName = parameterGeneration.getParameterName(); // If parameter already exists, add a unique suffix int offset = 0; while (map.containsKey(parameterName)) { parameterName = String.format("%s_%d", parameterGeneration.getParameterName(), ++offset); }/*w w w .j ava 2s .c o m*/ if (offset > 0) { parameterGeneration.setParameterName(parameterName); } map.put(parameterName, meta); } setParameterMap(map); if (!map.containsKey(getSelectedParameter())) { setSelectedParameter(null); } }
From source file:org.jenkinsci.plugins.workflow.support.concurrent.ListFuture.java
/** * Constructor.//from w ww . ja v a2 s . c om * * @param futures all the futures to build the list from * @param allMustSucceed whether a single failure or cancellation should * propagate to this future * @param listenerExecutor used to run listeners on all the passed in * futures. */ ListFuture(final ImmutableList<? extends ListenableFuture<? extends V>> futures, final boolean allMustSucceed, final Executor listenerExecutor) { this.futures = futures; this.values = Lists.newArrayListWithCapacity(futures.size()); this.allMustSucceed = allMustSucceed; this.remaining = new AtomicInteger(futures.size()); init(listenerExecutor); }
From source file:com.google.template.soy.jssrc.internal.NullSafeAccumulator.java
/** * Returns a code chunk representing the entire access chain. Null-safe accesses in the chain * generate code to make sure the chain is non-null before performing the access. *//*from w ww . jav a 2 s . c o m*/ CodeChunk.WithValue result(CodeChunk.Generator codeGenerator) { // First generate a list of every partial evaluation of the chain. ImmutableList<CodeChunk.WithValue> intermediateValues = buildIntermediateValues(); Preconditions.checkState(intermediateValues.size() == chain.size() + 1); // Walk backwards through the intermediate values. For any null-safe link in the chain, // test the intermediate value against null before dereferencing it. // For example, to translate a?.b.c, the rightmost link is not null-safe, so it translates to // a.b.c. The next link is null-safe, so it translates to a == null ? null : a.b.c. CodeChunk.WithValue cur = intermediateValues.get(intermediateValues.size() - 1); for (int i = intermediateValues.size() - 2; i >= 0; --i) { CodeChunk.WithValue chunk = intermediateValues.get(i); boolean nullSafe = chain.get(i).nullSafe; if (nullSafe) { cur = ifExpression(chunk.doubleEqualsNull(), LITERAL_NULL).else_(cur).build(codeGenerator); } } if (unpackFunction == null) { return cur; } else if (!isRepeated) { // It's okay if the whole chain evals to null. The unpack functions accept null. return unpackFunction.call(cur); } else { return GOOG_ARRAY_MAP.call(cur, unpackFunction); } }
From source file:uk.ac.ebi.atlas.search.baseline.BaselineExpressionDao.java
public ImmutableList<BaselineExperimentExpression> fetchAverageExpressionByExperimentAssayGroup( final Collection<String> geneIds) { if (geneIds.isEmpty()) { return ImmutableList.of(); }//from w w w . j av a 2 s. c o m LOGGER.debug(String.format("fetchAverageExpressionByExperimentAssayGroup for %s genes", geneIds.size())); Stopwatch stopwatch = Stopwatch.createStarted(); try { DatabaseQuery<Object> baselineExpressionQuery = buildSelect(geneIds); final ImmutableList.Builder<BaselineExperimentExpression> builder = ImmutableList.builder(); final MutableInt numberOfGenesExpressedInCurrentExperiment = new MutableInt(0); jdbcTemplate.query(baselineExpressionQuery.getQuery(), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String experimentAccession = rs.getString(BaselineQueryBuilder.EXPERIMENT); String assayGroupId = rs.getString(BaselineQueryBuilder.ASSAY_GROUP_ID); if (assayGroupId == null) { // every-time we see a null assaygroupid, this is the beginning of rows for another experiment // and this row will contain the experiment level totals double numberOfGenesExpressed = rs.getInt(BaselineQueryBuilder.NUMBER_GENES_EXPRESSED); numberOfGenesExpressedInCurrentExperiment.setValue(numberOfGenesExpressed); return; } double expression = baselineExpressionLevelRounder .round(rs.getDouble(BaselineQueryBuilder.EXPRESSION) / numberOfGenesExpressedInCurrentExperiment.intValue()); BaselineExperimentExpression bslnExpression = BaselineExperimentExpression .create(experimentAccession, assayGroupId, expression); builder.add(bslnExpression); } }, baselineExpressionQuery.getParameters().toArray()); ImmutableList<BaselineExperimentExpression> results = builder.build(); stopwatch.stop(); LOGGER.debug(String.format( "fetchAverageExpressionByExperimentAssayGroup returned %s results in %.2f seconds", results.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS) / 1000D)); return results; } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw e; } }
From source file:com.qubole.presto.udfs.sqlFunction.hiveUdfs.Nvl.java
@Override public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { if (arity != 2) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "There must be two arguments"); }/*from ww w . ja v a2 s . c om*/ Type type = types.get("T"); ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); if (type.getJavaType() == long.class) { builder.add(Long.class); builder.add(Long.class); } else if (type.getJavaType() == double.class) { builder.add(Double.class); builder.add(Double.class); } else if (type.getJavaType() == boolean.class) { builder.add(Boolean.class); builder.add(Boolean.class); } else { builder.add(type.getJavaType()); builder.add(type.getJavaType()); } ImmutableList<Class<?>> stackTypes = builder.build(); Class<?> clazz = ifNull(stackTypes); MethodHandle nvlMethodHandle = methodHandle(clazz, "nvl", stackTypes.toArray(new Class<?>[stackTypes.size()])); return new ScalarFunctionImplementation(true, ImmutableList.of(true, true), nvlMethodHandle, isDeterministic()); }
From source file:com.opengamma.strata.pricer.impl.credit.isda.IsdaModelDatasetsSheetReader.java
private String[] readHeaderRow() { // Read in the header row ImmutableList<String> rawRow = csvFile.headers(); final List<LocalDate> parSpreadDates = new ArrayList<>(); // Normalise read-in headers (to lower case) and set as columns String[] columns = new String[rawRow.size()]; for (int i = 0; i < rawRow.size(); i++) { columns[i] = rawRow.get(i).trim(); // if a date add to list of spread dates try {/*w w w . ja v a 2 s . c o m*/ final LocalDate date = LocalDate.parse(columns[i], DATE_TIME_PARSER); parSpreadDates.add(date); continue; } catch (Exception ex) { columns[i] = columns[i].toLowerCase(Locale.ENGLISH); // lowercase non dates } } _parSpreadDates = parSpreadDates.toArray(new LocalDate[parSpreadDates.size()]); _curveTenors = new ZonedDateTime[_parSpreadDates.length]; for (int j = 0; j < _parSpreadDates.length; j++) { _curveTenors[j] = ZonedDateTime.of(_parSpreadDates[j], LOCAL_TIME, TIME_ZONE); } ArgChecker.notEmpty(_parSpreadDates, "par spread dates"); ArgChecker.notEmpty(_curveTenors, "curve tenors"); return columns; }