List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:edu.buaa.satla.analysis.util.LoopStructure.java
private ImmutableSet<String> collectLoopCondVars() { ImmutableSet.Builder<String> result = ImmutableSet.builder(); for (Loop l : loops.values()) { // Get all variables that are used in exit-conditions for (CFAEdge e : l.getOutgoingEdges()) { if (e instanceof CAssumeEdge) { CExpression expr = ((CAssumeEdge) e).getExpression(); result.addAll(VariableClassification.getVariablesOfExpression(expr)); }/*from ww w. j a v a2 s. c o m*/ } } return result.build(); }
From source file:org.sosy_lab.cpachecker.util.LoopStructure.java
private ImmutableSet<String> collectLoopCondVars() { ImmutableSet.Builder<String> result = ImmutableSet.builder(); for (Loop l : loops.values()) { // Get all variables that are used in exit-conditions for (CFAEdge e : l.getOutgoingEdges()) { if (e instanceof CAssumeEdge) { CExpression expr = ((CAssumeEdge) e).getExpression(); result.addAll(CIdExpressionCollectorVisitor.getVariablesOfExpression(expr)); }//w ww. j ava 2 s. c o m } } return result.build(); }
From source file:zipkin.storage.cassandra.CassandraSpanConsumer.java
/** * This fans out into many requests, last count was 8 * spans.size. If any of these fail, the * returned future will fail. Most callers drop or log the result. *///from w w w. j av a 2 s . co m @Override public ListenableFuture<Void> accept(List<Span> rawSpans) { ImmutableSet.Builder<ListenableFuture<?>> futures = ImmutableSet.builder(); ImmutableList.Builder<Span> spans = ImmutableList.builder(); for (Span span : rawSpans) { // indexing occurs by timestamp, so derive one if not present. Long timestamp = guessTimestamp(span); spans.add(span); futures.add(storeSpan(span.traceId, timestamp != null ? timestamp : 0L, String.format("%s%d_%d_%d", span.traceIdHigh == 0 ? "" : span.traceIdHigh + "_", span.id, span.annotations.hashCode(), span.binaryAnnotations.hashCode()), // store the raw span without any adjustments ByteBuffer.wrap(Codec.THRIFT.writeSpan(span)))); for (String serviceName : span.serviceNames()) { // SpanStore.getServiceNames futures.add(storeServiceName(serviceName)); if (!span.name.isEmpty()) { // SpanStore.getSpanNames futures.add(storeSpanName(serviceName, span.name)); } } } futures.addAll(indexer.index(spans.build())); return transform(Futures.allAsList(futures.build()), TO_VOID); }
From source file:com.facebook.presto.hive.metastore.ThriftHiveMetastore.java
private Set<HivePrivilegeInfo> getUserPrivileges(HivePrincipal hivePrincipal, HiveObjectRef objectReference) { checkArgument(hivePrincipal.getPrincipalType() == USER, "Expected USER PrincipalType but found ROLE"); try {// www . j av a2s. c o m return retry().stopOnIllegalExceptions().run("getPrivilegeSet", stats.getGetPrivilegeSet().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { ImmutableSet.Builder<HivePrivilegeInfo> privileges = ImmutableSet.builder(); String principalName = hivePrincipal.getPrincipalName(); PrincipalPrivilegeSet privilegeSet = client.getPrivilegeSet(objectReference, principalName, null); if (privilegeSet != null) { Map<String, List<PrivilegeGrantInfo>> userPrivileges = privilegeSet.getUserPrivileges(); if (userPrivileges != null) { privileges.addAll(toGrants(userPrivileges.get(principalName))); } Map<String, List<PrivilegeGrantInfo>> rolePrivilegesMap = privilegeSet.getRolePrivileges(); if (rolePrivilegesMap != null) { for (List<PrivilegeGrantInfo> rolePrivileges : rolePrivilegesMap.values()) { privileges.addAll(toGrants(rolePrivileges)); } } // We do not add the group permissions as Hive does not seem to process these } return privileges.build(); } })); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } catch (Exception e) { throw propagate(e); } }
From source file:com.facebook.buck.cli.BuckConfig.java
/** * A set of paths to subtrees that do not contain source files, build files or files that could * affect either (buck-out, .idea, .buckd, buck-cache, .git, etc.). May return absolute paths * as well as relative paths./* ww w . ja va2 s. com*/ */ public ImmutableSet<Path> getIgnorePaths() { final ImmutableMap<String, String> projectConfig = getEntriesForSection("project"); final String ignoreKey = "ignore"; ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); builder.add(Paths.get(BuckConstant.BUCK_OUTPUT_DIRECTORY)); builder.add(Paths.get(".idea")); // Take care not to ignore absolute paths. Path buckdDir = Paths.get(System.getProperty(BUCK_BUCKD_DIR_KEY, ".buckd")); Path cacheDir = getCacheDir(); for (Path path : ImmutableList.of(buckdDir, cacheDir)) { if (!path.toString().isEmpty()) { builder.add(path); } } if (projectConfig.containsKey(ignoreKey)) { builder.addAll(MorePaths.asPaths( Splitter.on(',').omitEmptyStrings().trimResults().split(projectConfig.get(ignoreKey)))); } // Normalize paths in order to eliminate trailing '/' characters and whatnot. return builder.build(); }
From source file:io.prestosql.execution.scheduler.SourcePartitionedScheduler.java
private Set<RemoteTask> assignSplits(Multimap<Node, Split> splitAssignment, Multimap<Node, Lifespan> noMoreSplitsNotification) { ImmutableSet.Builder<RemoteTask> newTasks = ImmutableSet.builder(); ImmutableSet<Node> nodes = ImmutableSet.<Node>builder().addAll(splitAssignment.keySet()) .addAll(noMoreSplitsNotification.keySet()).build(); for (Node node : nodes) { // source partitioned tasks can only receive broadcast data; otherwise it would have a different distribution ImmutableMultimap<PlanNodeId, Split> splits = ImmutableMultimap.<PlanNodeId, Split>builder() .putAll(partitionedNode, splitAssignment.get(node)).build(); ImmutableMultimap.Builder<PlanNodeId, Lifespan> noMoreSplits = ImmutableMultimap.builder(); if (noMoreSplitsNotification.containsKey(node)) { noMoreSplits.putAll(partitionedNode, noMoreSplitsNotification.get(node)); }//from w ww . j a v a 2s . c om newTasks.addAll(stage.scheduleSplits(node, splits, noMoreSplits.build())); } return newTasks.build(); }
From source file:com.google.devtools.build.lib.rules.cpp.FdoSupport.java
/** * Returns the auxiliary files that need to be added to the {@link CppCompileAction}. */// ww w . java 2s .co m private Iterable<Artifact> getAuxiliaryInputs(RuleContext ruleContext, AnalysisEnvironment env, PathFragment sourceName, PathFragment sourceExecPath, boolean usePic, LipoContextProvider lipoContextProvider) { // If --fdo_optimize was not specified, we don't have any additional inputs. if (fdoProfile == null) { return ImmutableSet.of(); } else if (fdoMode == FdoMode.AUTO_FDO || fdoMode == FdoMode.LLVM_FDO) { ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder(); PathFragment profileRootRelativePath = fdoMode == FdoMode.LLVM_FDO ? getLLVMProfileRootRelativePath(fdoProfile) : getAutoProfileRootRelativePath(fdoProfile); Artifact artifact = env.getDerivedArtifact(fdoPath.getRelative(profileRootRelativePath), fdoRoot); env.registerAction(new FdoStubAction(ruleContext.getActionOwner(), artifact)); auxiliaryInputs.add(artifact); if (lipoContextProvider != null) { auxiliaryInputs.addAll(getAutoFdoImports(ruleContext, sourceExecPath, lipoContextProvider)); } return auxiliaryInputs.build(); } else { ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder(); PathFragment objectName = FileSystemUtils.replaceExtension(sourceName, usePic ? ".pic.o" : ".o"); Label lipoLabel = ruleContext.getLabel(); auxiliaryInputs.addAll(getGcdaArtifactsForObjectFileName(ruleContext, env, objectName, lipoLabel)); if (lipoContextProvider != null) { for (PathFragment importedFile : getImports(getNonLipoObjDir(ruleContext, lipoLabel), objectName)) { if (CppFileTypes.COVERAGE_DATA.matches(importedFile.getBaseName())) { Artifact gcdaArtifact = getGcdaArtifactsForGcdaPath(ruleContext, env, importedFile); if (gcdaArtifact == null) { ruleContext.ruleError(String.format( ".gcda file %s is not in the FDO zip (referenced by source file %s)", importedFile, sourceName)); } else { auxiliaryInputs.add(gcdaArtifact); } } else { Artifact importedArtifact = lipoContextProvider.getSourceArtifactMap().get(importedFile); if (importedArtifact != null) { auxiliaryInputs.add(importedArtifact); } else { ruleContext.ruleError(String.format("cannot find source file '%s' referenced from '%s'", importedFile, objectName)); } } } } return auxiliaryInputs.build(); } }
From source file:io.prestosql.plugin.accumulo.AccumuloClient.java
private Collection<Range> splitByTabletBoundaries(String tableName, Collection<Range> ranges) throws org.apache.accumulo.core.client.TableNotFoundException, AccumuloException, AccumuloSecurityException {/* w w w . j ava 2 s . c o m*/ ImmutableSet.Builder<Range> rangeBuilder = ImmutableSet.builder(); for (Range range : ranges) { // if start and end key are equivalent, no need to split the range if (range.getStartKey() != null && range.getEndKey() != null && range.getStartKey().equals(range.getEndKey())) { rangeBuilder.add(range); } else { // Call out to Accumulo to split the range on tablets rangeBuilder.addAll( connector.tableOperations().splitRangeByTablets(tableName, range, Integer.MAX_VALUE)); } } return rangeBuilder.build(); }
From source file:org.lanternpowered.server.data.IValueContainer.java
@SuppressWarnings("unchecked") @Override//from w w w .j a v a 2 s. com default Set<ImmutableValue<?>> getValues() { final ImmutableSet.Builder<ImmutableValue<?>> values = ImmutableSet.builder(); // Check local registrations for (KeyRegistration<?, ?> entry : getValueCollection().getAll()) { final Key key = entry.getKey(); final Optional<BaseValue> optValue = getValue(key); optValue.ifPresent(baseValue -> values.add(ValueHelper.toImmutable(baseValue))); } // Check for global registrations for (ValueProcessorKeyRegistration<?, ?> registration : LanternValueFactory.get().getKeyRegistrations()) { final Optional<BaseValue> optValue = ((Processor) registration).getValueFrom(this); optValue.ifPresent(baseValue -> values.add(ValueHelper.toImmutable(baseValue))); } // Check if custom data is supported by this container if (this instanceof AdditionalContainerHolder) { final AdditionalContainerCollection<?> containers = ((AdditionalContainerHolder<?>) this) .getAdditionalContainers(); containers.getAll().forEach(manipulator -> values.addAll(manipulator.getValues())); } return values.build(); }
From source file:com.facebook.buck.core.model.targetgraph.impl.TargetNodeFactory.java
@SuppressWarnings("unchecked") private <T, U extends BaseDescription<T>> TargetNode<T> create(U description, T constructorArg, ProjectFilesystem filesystem, BuildTarget buildTarget, ImmutableSet<BuildTarget> declaredDeps, ImmutableSet<VisibilityPattern> visibilityPatterns, ImmutableSet<VisibilityPattern> withinViewPatterns, CellPathResolver cellRoots) throws NoSuchBuildTargetException { ImmutableSortedSet.Builder<BuildTarget> extraDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<BuildTarget> targetGraphOnlyDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSet.Builder<Path> pathsBuilder = ImmutableSet.builder(); // Scan the input to find possible BuildTargetPaths, necessary for loading dependent rules. for (ParamInfo info : CoercedTypeCache.INSTANCE .getAllParamInfo(typeCoercerFactory, description.getConstructorArgType()).values()) { if (info.isDep() && info.isInput() && info.hasElementTypes(BuildTarget.class, SourcePath.class, Path.class) && !info.getName().equals("deps")) { detectBuildTargetsAndPathsForConstructorArg(buildTarget, cellRoots, info.isTargetGraphOnlyDep() ? targetGraphOnlyDepsBuilder : extraDepsBuilder, pathsBuilder, info, constructorArg); }/* www. ja v a 2 s. co m*/ } if (description instanceof ImplicitDepsInferringDescription) { ((ImplicitDepsInferringDescription<T>) description).findDepsForTargetFromConstructorArgs(buildTarget, cellRoots, constructorArg, extraDepsBuilder, targetGraphOnlyDepsBuilder); } if (description instanceof ImplicitInputsInferringDescription) { pathsBuilder.addAll(((ImplicitInputsInferringDescription<T>) description) .inferInputsFromConstructorArgs(buildTarget.getUnflavoredBuildTarget(), constructorArg)); } ImmutableSet<Path> paths = pathsBuilder.build(); pathsChecker.checkPaths(filesystem, buildTarget, paths); // This method uses the TargetNodeFactory, rather than just calling withBuildTarget, // because // ImplicitDepsInferringDescriptions may give different results for deps based on flavors. // // Note that this method strips away selected versions, and may be buggy because of it. return ImmutableTargetNode.of(buildTarget, this, description, constructorArg, filesystem, paths, declaredDeps, extraDepsBuilder.build(), targetGraphOnlyDepsBuilder.build(), cellRoots, visibilityPatterns, withinViewPatterns, Optional.empty()); }