List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:org.locationtech.geogig.geotools.plumbing.ExportDiffOp.java
private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old, final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) { final SimpleFeatureType featureType = addChangeTypeAttribute(database.getFeatureType(metadataId)); final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType); final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() { @Override//from w w w . ja v a 2s .c o m @Nullable public SimpleFeature apply(final DiffEntry input) { NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject(); if (nodeRef == null) { return null; } final RevFeature revFeature = database.getFeature(nodeRef.objectId()); ImmutableList<Optional<Object>> values = revFeature.getValues(); for (int i = 0; i < values.size(); i++) { String name = featureType.getDescriptor(i + 1).getLocalName(); Object value = values.get(i).orNull(); featureBuilder.set(name, value); } featureBuilder.set(CHANGE_TYPE_NAME, input.changeType().name().charAt(0)); Feature feature = featureBuilder.buildFeature(nodeRef.name()); feature.getUserData().put(Hints.USE_PROVIDED_FID, true); feature.getUserData().put(RevFeature.class, revFeature); feature.getUserData().put(RevFeatureType.class, revFeatureType); if (feature instanceof SimpleFeature) { return (SimpleFeature) feature; } return null; } }; Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature); UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull()); return filterNulls; }
From source file:com.google.errorprone.refaster.UPlaceholderExpression.java
static UPlaceholderExpression create(PlaceholderMethod placeholder, Iterable<? extends UExpression> arguments) { ImmutableList<UVariableDecl> placeholderParams = placeholder.parameters().asList(); ImmutableList<UExpression> argumentsList = ImmutableList.copyOf(arguments); ImmutableMap.Builder<UVariableDecl, UExpression> builder = ImmutableMap.builder(); for (int i = 0; i < placeholderParams.size(); i++) { builder.put(placeholderParams.get(i), argumentsList.get(i)); }//from w w w.ja v a 2 s . c om return new AutoValue_UPlaceholderExpression(placeholder, builder.build()); }
From source file:se.kth.climate.fast.netcdf.aligner.VariableFit.java
public static VariableFit fromDataDescriptors(ImmutableList<DataDescriptor> dds) { DataDescriptor firstDD = dds.get(0); // use first descriptor for records as that one has the largest number of records per variable ImmutableMap.Builder<String, Long> rfvb = ImmutableMap.builder(); for (String varName : firstDD.vars) { rfvb.put(varName, firstDD.variableSize(varName)); }/* w w w . ja v a 2s. c o m*/ return new VariableFit(rfvb.build(), dds.size(), dds); }
From source file:com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder.java
/** * Creates a nested set from a given list of items. *//*www.j a v a 2 s . co m*/ @SuppressWarnings("unchecked") public static <E> NestedSet<E> wrap(Order order, Iterable<E> wrappedItems) { ImmutableList<E> wrappedList = ImmutableList.copyOf(wrappedItems); if (wrappedList.isEmpty()) { return order.emptySet(); } else if (order == Order.STABLE_ORDER && wrappedList == wrappedItems && wrappedList.size() > 1) { NestedSet<?> cached = immutableListCache.get(wrappedList); if (cached != null) { return (NestedSet<E>) cached; } NestedSet<E> built = new NestedSetBuilder<E>(order).addAll(wrappedList).build(); immutableListCache.putIfAbsent(wrappedList, built); return built; } else { return new NestedSetBuilder<E>(order).addAll(wrappedList).build(); } }
From source file:com.google.errorprone.refaster.UPlaceholderStatement.java
static UPlaceholderStatement create(PlaceholderMethod placeholder, Iterable<? extends UExpression> arguments, ControlFlowVisitor.Result implementationFlow) { ImmutableList<UVariableDecl> placeholderParams = placeholder.parameters().asList(); ImmutableList<UExpression> argumentsList = ImmutableList.copyOf(arguments); ImmutableMap.Builder<UVariableDecl, UExpression> builder = ImmutableMap.builder(); for (int i = 0; i < placeholderParams.size(); i++) { builder.put(placeholderParams.get(i), argumentsList.get(i)); }// w ww . j a v a 2s .c om return new AutoValue_UPlaceholderStatement(placeholder, builder.build(), implementationFlow); }
From source file:org.eclipse.sw360.commonIO.TypeMappings.java
@NotNull public static Map<Integer, Risk> getIntegerRiskMap(LicenseService.Iface licenseClient, Map<Integer, RiskCategory> riskCategoryMap, InputStream in, User user) throws TException { List<CSVRecord> riskRecords = ImportCSV.readAsCSVRecords(in); final List<Risk> risksToAdd = ConvertRecord.convertRisks(riskRecords, riskCategoryMap); final List<Risk> risks = CommonUtils.nullToEmptyList(licenseClient.getRisks()); Map<Integer, Risk> riskMap = Maps.newHashMap(Maps.uniqueIndex(risks, getRiskIdentifier())); final ImmutableList<Risk> filteredList = getElementsWithIdentifiersNotInMap(getRiskIdentifier(), riskMap, risksToAdd);/* w w w .j av a 2s . c o m*/ List<Risk> addedRisks = null; if (filteredList.size() > 0) { addedRisks = licenseClient.addRisks(filteredList, user); } if (addedRisks != null) riskMap.putAll(Maps.uniqueIndex(addedRisks, getRiskIdentifier())); return riskMap; }
From source file:org.eclipse.sw360.commonIO.TypeMappings.java
@NotNull public static <T, U> Map<U, T> getIdentifierToTypeMapAndWriteMissingToDatabase( LicenseService.Iface licenseClient, InputStream in, Class<T> clazz, Class<U> uClass, User user) throws TException { Map<U, T> typeMap;/* w w w .j a va2 s. com*/ List<CSVRecord> records = ImportCSV.readAsCSVRecords(in); final List<T> recordsToAdd = simpleConvert(records, clazz); final List<T> fullList = CommonUtils.nullToEmptyList(getAllFromDB(licenseClient, clazz)); typeMap = Maps.newHashMap(Maps.uniqueIndex(fullList, getIdentifier(clazz, uClass))); final ImmutableList<T> filteredList = getElementsWithIdentifiersNotInMap(getIdentifier(clazz, uClass), typeMap, recordsToAdd); List<T> added = null; if (filteredList.size() > 0) { added = addAlltoDB(licenseClient, clazz, filteredList, user); } if (added != null) typeMap.putAll(Maps.uniqueIndex(added, getIdentifier(clazz, uClass))); return typeMap; }
From source file:com.google.devtools.build.lib.query2.engine.BinaryOperatorExpression.java
/** * Evaluates an expression of the form "e1 + e2 + ... + eK" by evaluating all the subexpressions * in parallel./*from w w w . j ava 2s . c o m*/ */ private static <T> void parEvalPlus(ImmutableList<QueryExpression> operands, final QueryEnvironment<T> env, final VariableContext<T> context, final ThreadSafeCallback<T> callback, ForkJoinPool forkJoinPool) throws QueryException, InterruptedException { ArrayList<QueryTask> queryTasks = new ArrayList<>(operands.size()); for (final QueryExpression operand : operands) { queryTasks.add(new QueryTask() { @Override public void execute() throws QueryException, InterruptedException { env.eval(operand, context, callback); } }); } ParallelQueryUtils.executeQueryTasksAndWaitInterruptiblyFailFast(queryTasks, forkJoinPool); }
From source file:com.facebook.buck.artifact_cache.ArtifactCaches.java
private static ArtifactCache newInstanceInternal(ArtifactCacheBuckConfig buckConfig, BuckEventBus buckEventBus, ProjectFilesystem projectFilesystem, Optional<String> wifiSsid, ListeningExecutorService httpWriteExecutorService, boolean distributedBuildModeEnabled) { ImmutableSet<ArtifactCacheBuckConfig.ArtifactCacheMode> modes = buckConfig.getArtifactCacheModes(); if (modes.isEmpty()) { return new NoopArtifactCache(); }//from ww w. j a v a2 s .co m ImmutableList.Builder<ArtifactCache> builder = ImmutableList.builder(); for (ArtifactCacheBuckConfig.ArtifactCacheMode mode : modes) { switch (mode) { case dir: builder.add(createDirArtifactCache(Optional.of(buckEventBus), buckConfig.getDirCache(), projectFilesystem)); break; case http: initializeDistributedCaches(buckConfig, buckEventBus, projectFilesystem, wifiSsid, httpWriteExecutorService, builder, distributedBuildModeEnabled, HTTP_PROTOCOL); break; case thrift_over_http: initializeDistributedCaches(buckConfig, buckEventBus, projectFilesystem, wifiSsid, httpWriteExecutorService, builder, distributedBuildModeEnabled, THRIFT_PROTOCOL); break; } } ImmutableList<ArtifactCache> artifactCaches = builder.build(); ArtifactCache result; if (artifactCaches.size() == 1) { // Don't bother wrapping a single artifact cache in MultiArtifactCache. result = artifactCaches.get(0); } else { result = new MultiArtifactCache(artifactCaches); } // Always support reading two-level cache stores (in case we performed any in the past). result = new TwoLevelArtifactCacheDecorator(result, projectFilesystem, buckEventBus, buckConfig.getTwoLevelCachingEnabled(), buckConfig.getTwoLevelCachingMinimumSize(), buckConfig.getTwoLevelCachingMaximumSize()); return result; }
From source file:org.geogit.api.NodeRef.java
public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); ImmutableList<String> parent = split(parentPath); ImmutableList<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { appendChild(strippedChildPath, child.get(i)); }/*from w ww.ja v a2s . c om*/ return strippedChildPath; }