List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:org.prebake.service.tools.ext.JunitHtmlReportGenerator.java
private static ImmutableMultimap<String, Map<?, ?>> groupBy(Iterable<Map<?, ?>> tests, Function<Map<?, ?>, String> keyFn) { ImmutableMultimap.Builder<String, Map<?, ?>> b = ImmutableMultimap.builder(); for (Map<?, ?> test : tests) { String name = keyFn.apply(test); if (name != null) { b.put(name, test);/*from www . ja v a2s .c o m*/ } } return b.build(); }
From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java
public ImmutableMultimap<BuildTarget, PBXTarget> getBuildTargetToGeneratedTargetMap() { Preconditions.checkState(projectGenerated, "Must have called createXcodeProjects"); ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMap = ImmutableMultimap.builder(); for (Map.Entry<TargetNode<?, ?>, PBXTarget> entry : targetNodeToGeneratedProjectTargetBuilder.build() .entries()) {/* www. ja v a2 s.c o m*/ buildTargetToPbxTargetMap.put(entry.getKey().getBuildTarget(), entry.getValue()); } return buildTargetToPbxTargetMap.build(); }
From source file:com.facebook.buck.features.apple.project.WorkspaceAndProjectGenerator.java
private void generateProject(Map<Path, ProjectGenerator> projectGenerators, ListeningExecutorService listeningExecutorService, WorkspaceGenerator workspaceGenerator, ImmutableSet<BuildTarget> targetsInRequiredProjects, ImmutableSetMultimap.Builder<PBXProject, PBXTarget> generatedProjectToPbxTargetsBuilder, ImmutableMap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder, ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder) throws IOException, InterruptedException { ImmutableMultimap.Builder<Cell, BuildTarget> projectCellToBuildTargetsBuilder = ImmutableMultimap.builder(); for (TargetNode<?> targetNode : projectGraph.getNodes()) { BuildTarget buildTarget = targetNode.getBuildTarget(); projectCellToBuildTargetsBuilder.put(rootCell.getCell(buildTarget), buildTarget); }//from www.j a v a2 s . c o m ImmutableMultimap<Cell, BuildTarget> projectCellToBuildTargets = projectCellToBuildTargetsBuilder.build(); List<ListenableFuture<GenerationResult>> projectGeneratorFutures = new ArrayList<>(); for (Cell projectCell : projectCellToBuildTargets.keySet()) { ImmutableMultimap.Builder<Path, BuildTarget> projectDirectoryToBuildTargetsBuilder = ImmutableMultimap .builder(); ImmutableSet<BuildTarget> cellRules = ImmutableSet.copyOf(projectCellToBuildTargets.get(projectCell)); for (BuildTarget buildTarget : cellRules) { projectDirectoryToBuildTargetsBuilder.put(buildTarget.getBasePath(), buildTarget); } ImmutableMultimap<Path, BuildTarget> projectDirectoryToBuildTargets = projectDirectoryToBuildTargetsBuilder .build(); Path relativeTargetCell = rootCell.getRoot().relativize(projectCell.getRoot()); for (Path projectDirectory : projectDirectoryToBuildTargets.keySet()) { ImmutableSet<BuildTarget> rules = filterRulesForProjectDirectory(projectGraph, ImmutableSet.copyOf(projectDirectoryToBuildTargets.get(projectDirectory))); if (Sets.intersection(targetsInRequiredProjects, rules).isEmpty()) { continue; } boolean isMainProject = workspaceArguments.getSrcTarget().isPresent() && rules.contains(workspaceArguments.getSrcTarget().get()); projectGeneratorFutures.add(listeningExecutorService.submit(() -> { GenerationResult result = generateProjectForDirectory(projectGenerators, projectCell, projectDirectory, rules, isMainProject, targetsInRequiredProjects); // convert the projectPath to relative to the target cell here result = GenerationResult.of(relativeTargetCell.resolve(result.getProjectPath()), result.isProjectGenerated(), result.getRequiredBuildTargets(), result.getXcconfigPaths(), result.getFilesToCopyInXcode(), result.getBuildTargetToGeneratedTargetMap(), result.getGeneratedProjectToPbxTargets()); return result; })); } } List<GenerationResult> generationResults; try { generationResults = Futures.allAsList(projectGeneratorFutures).get(); } catch (ExecutionException e) { Throwables.throwIfInstanceOf(e.getCause(), IOException.class); Throwables.throwIfUnchecked(e.getCause()); throw new IllegalStateException("Unexpected exception: ", e); } for (GenerationResult result : generationResults) { if (!result.isProjectGenerated()) { continue; } workspaceGenerator.addFilePath(result.getProjectPath()); processGenerationResult(generatedProjectToPbxTargetsBuilder, buildTargetToPbxTargetMapBuilder, targetToProjectPathMapBuilder, result); } }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
private static void buildWorkspaceSchemes(Optional<BuildTarget> mainTarget, TargetGraph projectGraph, boolean includeProjectTests, boolean includeDependenciesTests, ImmutableSet<TargetNode<AppleTestDescription.Arg>> groupableTests, String workspaceName, XcodeWorkspaceConfigDescription.Arg workspaceArguments, ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder, ImmutableSetMultimap.Builder<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNodeBuilder, ImmutableSetMultimap.Builder<String, TargetNode<?>> buildForTestNodesBuilder, ImmutableMultimap.Builder<AppleTestBundleParamsKey, TargetNode<AppleTestDescription.Arg>> groupedTestsBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> ungroupedTestsBuilder) { ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> extraTestNodesBuilder = ImmutableSetMultimap .builder();/*w w w .ja v a 2 s . c om*/ addWorkspaceScheme(projectGraph, workspaceName, workspaceArguments, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, extraTestNodesBuilder); addExtraWorkspaceSchemes(projectGraph, workspaceArguments.extraSchemes.get(), schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, extraTestNodesBuilder); ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode = schemeNameToSrcTargetNodeBuilder .build(); ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> extraTestNodes = extraTestNodesBuilder .build(); ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> selectedTestsBuilder = ImmutableSetMultimap .builder(); buildWorkspaceSchemeTests(mainTarget, projectGraph, includeProjectTests, includeDependenciesTests, schemeNameToSrcTargetNode, extraTestNodes, selectedTestsBuilder, buildForTestNodesBuilder); ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> selectedTests = selectedTestsBuilder .build(); groupSchemeTests(groupableTests, selectedTests, groupedTestsBuilder, ungroupedTestsBuilder); }
From source file:com.github.avarabyeu.restendpoint.http.HttpClientRestEndpoint.java
/** * Executes {@link org.apache.http.client.methods.HttpUriRequest} * * @param rq - Request/*from ww w. j a v a 2s . c o m*/ * @param callback - Callback to be applied on response * @param <RS> type of response * @return - Serialized Response Body * @throws RestEndpointIOException IO exception */ private <RS> Will<Response<RS>> executeInternal(final HttpUriRequest rq, final HttpEntityCallback<RS> callback) throws RestEndpointIOException { final SettableFuture<Response<RS>> future = SettableFuture.create(); httpClient.execute(rq, new FutureCallback<org.apache.http.HttpResponse>() { @Override public void completed(final org.apache.http.HttpResponse response) { try { if (errorHandler.hasError(response)) { errorHandler.handle(rq, response); } HttpEntity entity = response.getEntity(); Header[] allHeaders = response.getAllHeaders(); ImmutableMultimap.Builder<String, String> headersBuilder = ImmutableMultimap.builder(); for (Header header : allHeaders) { for (HeaderElement element : header.getElements()) { headersBuilder.put(header.getName(), null == element.getValue() ? "" : element.getValue()); } } Response<RS> rs = new Response<RS>(rq.getURI().toASCIIString(), response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), headersBuilder.build(), callback.callback(entity)); future.set(rs); } catch (SerializerException e) { future.setException(e); } catch (IOException e) { future.setException(new RestEndpointIOException("Unable to execute request", e)); } catch (Exception e) { future.setException(e); } } @Override public void failed(final Exception ex) { future.setException(new RestEndpointIOException("Unable to execute request", ex)); } @Override public void cancelled() { final TimeoutException timeoutException = new TimeoutException(); future.setException(timeoutException); } }); return Wills.forListenableFuture(future); }
From source file:org.sosy_lab.cpachecker.util.LoopStructure.java
/** * Build loop-structure information for a CFA. * Do not call this method outside of the frontend, * use {@link org.sosy_lab.cpachecker.cfa.CFA#getLoopStructure()} instead. * @throws ParserException If the structure of the CFA is too complex for determining loops. *//* w w w. ja v a2 s. c o m*/ public static LoopStructure getLoopStructure(MutableCFA cfa) throws ParserException { ImmutableMultimap.Builder<String, Loop> loops = ImmutableMultimap.builder(); for (String functionName : cfa.getAllFunctionNames()) { SortedSet<CFANode> nodes = cfa.getFunctionNodes(functionName); loops.putAll(functionName, findLoops(nodes, cfa.getLanguage())); } return new LoopStructure(loops.build()); }
From source file:grakn.core.graql.reasoner.atom.binary.RelationAtom.java
/** * @return map of pairs role type - Id predicate describing the role player playing this role (substitution) *///from ww w. ja v a 2s .co m @Memoized public Multimap<Role, String> getRoleConceptIdMap() { ImmutableMultimap.Builder<Role, String> builder = ImmutableMultimap.builder(); getRolePredicateMap(IdPredicate.class).entries() .forEach(e -> builder.put(e.getKey(), e.getValue().getPredicateValue())); return builder.build(); }
From source file:grakn.core.graql.reasoner.atom.binary.RelationAtom.java
private Multimap<Role, Type> getRoleTypeMap(boolean inferTypes) { ImmutableMultimap.Builder<Role, Type> builder = ImmutableMultimap.builder(); Multimap<Role, Variable> roleMap = getRoleVarMap(); SetMultimap<Variable, Type> varTypeMap = getParentQuery().getVarTypeMap(inferTypes); roleMap.entries().stream().sorted(Comparator.comparing(e -> e.getKey().label())) .flatMap(e -> varTypeMap.get(e.getValue()).stream().map(type -> new Pair<>(e.getKey(), type))) .sorted(Comparator.comparing(Pair::hashCode)).forEach(p -> builder.put(p.getKey(), p.getValue())); 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 w w . java 2 s. c om*/ newTasks.addAll(stage.scheduleSplits(node, splits, noMoreSplits.build())); } return newTasks.build(); }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
public ProjectGenerator(XCodeDescriptions xcodeDescriptions, TargetGraph targetGraph, AppleDependenciesCache dependenciesCache, ProjectGenerationStateCache projGenerationStateCache, Set<BuildTarget> initialTargets, Cell cell, Path outputDirectory, String projectName, String buildFileName, ProjectGeneratorOptions options, RuleKeyConfiguration ruleKeyConfiguration, boolean isMainProject, Optional<BuildTarget> workspaceTarget, ImmutableSet<BuildTarget> targetsInRequiredProjects, FocusedModuleTargetMatcher focusModules, CxxPlatform defaultCxxPlatform, ImmutableSet<Flavor> appleCxxFlavors, Function<? super TargetNode<?>, ActionGraphBuilder> actionGraphBuilderForNode, BuckEventBus buckEventBus, HalideBuckConfig halideBuckConfig, CxxBuckConfig cxxBuckConfig, AppleConfig appleConfig, SwiftBuckConfig swiftBuckConfig, Optional<ImmutableMap<BuildTarget, TargetNode<?>>> sharedLibraryToBundle) { this.xcodeDescriptions = xcodeDescriptions; this.targetGraph = targetGraph; this.dependenciesCache = dependenciesCache; this.projGenerationStateCache = projGenerationStateCache; this.initialTargets = ImmutableSet.copyOf(initialTargets); this.projectCell = cell; this.projectFilesystem = cell.getFilesystem(); this.outputDirectory = outputDirectory; this.projectName = projectName; this.buildFileName = buildFileName; this.options = options; this.ruleKeyConfiguration = ruleKeyConfiguration; this.isMainProject = isMainProject; this.workspaceTarget = workspaceTarget; this.targetsInRequiredProjects = targetsInRequiredProjects; this.defaultCxxPlatform = defaultCxxPlatform; this.appleCxxFlavors = appleCxxFlavors; this.actionGraphBuilderForNode = actionGraphBuilderForNode; this.defaultPathResolver = DefaultSourcePathResolver .from(new SourcePathRuleFinder(new SingleThreadedActionGraphBuilder(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer(), cell.getCellProvider()))); this.buckEventBus = buckEventBus; this.projectPath = outputDirectory.resolve(projectName + ".xcodeproj"); this.pathRelativizer = new PathRelativizer(outputDirectory, this::resolveSourcePath); this.sharedLibraryToBundle = sharedLibraryToBundle; LOG.debug("Output directory %s, profile fs root path %s, repo root relative to output dir %s", this.outputDirectory, projectFilesystem.getRootPath(), this.pathRelativizer.outputDirToRootRelative(Paths.get("."))); this.project = new PBXProject(projectName); this.headerSymlinkTrees = new ArrayList<>(); this.targetNodeToGeneratedProjectTargetBuilder = ImmutableMultimap.builder(); this.targetNodeToProjectTarget = CacheBuilder.newBuilder() .build(new CacheLoader<TargetNode<?>, Optional<PBXTarget>>() { @Override//from w ww . j av a 2s. c o m public Optional<PBXTarget> load(TargetNode<?> key) throws Exception { return generateProjectTarget(key); } }); targetConfigNamesBuilder = ImmutableSet.builder(); this.halideBuckConfig = halideBuckConfig; this.cxxBuckConfig = cxxBuckConfig; this.appleConfig = appleConfig; this.swiftBuckConfig = swiftBuckConfig; this.focusModules = focusModules; gidGenerator = new GidGenerator(); }