List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java
private void generateCombinedProject(String workspaceName, Path outputDirectory, WorkspaceGenerator workspaceGenerator, ImmutableSet<BuildTarget> targetsInRequiredProjects, ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder, ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder, Optional<BuildTarget> targetToBuildWithBuck) throws IOException { LOG.debug("Generating a combined project"); ProjectGenerator generator = new ProjectGenerator(projectGraph, dependenciesCache, targetsInRequiredProjects, rootCell, outputDirectory.getParent(), workspaceName, buildFileName, projectGeneratorOptions, targetToBuildWithBuck, buildWithBuckFlags, focusModules, executableFinder, environment, cxxPlatforms, defaultCxxPlatform, sourcePathResolverForNode, buckEventBus, halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig); combinedProjectGenerator = Optional.of(generator); generator.createXcodeProjects();/*w w w . j a v a2 s .c o m*/ GenerationResult result = GenerationResult.of(generator.getProjectPath(), generator.isProjectGenerated(), generator.getRequiredBuildTargets(), generator.getBuildTargetToGeneratedTargetMap()); workspaceGenerator.addFilePath(result.getProjectPath(), Optional.empty()); processGenerationResult(buildTargetToPbxTargetMapBuilder, targetToProjectPathMapBuilder, result); }
From source file:com.continuuity.weave.internal.appmaster.ApplicationMasterService.java
private Queue<RunnableContainerRequest> initContainerRequests() { // Orderly stores container requests. Queue<RunnableContainerRequest> requests = Lists.newLinkedList(); // For each order in the weaveSpec, create container request for each runnable. for (WeaveSpecification.Order order : weaveSpec.getOrders()) { // Group container requests based on resource requirement. ImmutableMultimap.Builder<Resource, RuntimeSpecification> builder = ImmutableMultimap.builder(); for (String runnableName : order.getNames()) { RuntimeSpecification runtimeSpec = weaveSpec.getRunnables().get(runnableName); Resource capability = createCapability(runtimeSpec.getResourceSpecification()); builder.put(capability, runtimeSpec); }//from ww w .j ava 2 s .c om requests.add(new RunnableContainerRequest(order.getType(), builder.build())); } return requests; }
From source file:org.caleydo.view.domino.internal.band.CrossBand.java
private static Multimap<Integer, Integer> computeLookup(List<Integer> s) { Builder<Integer, Integer> b = ImmutableMultimap.builder(); for (int i = 0; i < s.size(); ++i) { b.put(s.get(i), i);/*from w ww . j av a2s . c o m*/ } return b.build(); }
From source file:com.github.rinde.rinsim.central.arrays.ArraysSolverValidator.java
/** * Validates the {@link SolutionObject}s that are produced by a * {@link MultiVehicleArraysSolver}. If any of the {@link SolutionObject}s is * infeasible, an {@link IllegalArgumentException} is thrown. * @param sols The {@link SolutionObject}s that are validated. * @param travelTime Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * ./*from www . j a v a 2s . co m*/ * @param releaseDates Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param dueDates Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param servicePairs Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param serviceTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param vehicleTravelTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param inventories Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param remainingServiceTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param currentDestinations Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @return The solution as is supplied, used for method chaining. */ public static SolutionObject[] validateOutputs(SolutionObject[] sols, int[][] travelTime, int[] releaseDates, int[] dueDates, int[][] servicePairs, int[] serviceTimes, int[][] vehicleTravelTimes, int[][] inventories, int[] remainingServiceTimes, int[] currentDestinations) { final int n = travelTime.length; final ImmutableSet.Builder<Integer> routeSetBuilder = ImmutableSet.builder(); int visitedLocations = 0; for (final SolutionObject sol : sols) { routeSetBuilder.addAll(toSet(sol.route)); visitedLocations += sol.route.length - 2; } final Set<Integer> routeSet = routeSetBuilder.build(); final Set<Integer> locationSet = ContiguousSet.create(Range.closedOpen(0, travelTime.length), DiscreteDomain.integers()); checkArgument(visitedLocations == n - 2, "The number of visits in routes should equal the number of locations, " + "expected: %s, observed: %s.", n - 2, visitedLocations); // checks duplicates and missing locations checkArgument(routeSet.size() == n, "Every location should appear exactly once in one route. Missing " + "location: %s.", Sets.difference(locationSet, routeSet)); // checks for completeness of tour checkArgument(routeSet.equals(locationSet), "Not all locations are serviced, there is probably a non-existing " + "location in the route. Set difference: %s.", Sets.difference(routeSet, locationSet)); final ImmutableMultimap.Builder<Integer, Integer> inventoryBuilder = ImmutableMultimap.builder(); for (int i = 0; i < inventories.length; i++) { inventoryBuilder.put(inventories[i][0], inventories[i][1]); } final Multimap<Integer, Integer> inventoryMap = inventoryBuilder.build(); for (int v = 0; v < sols.length; v++) { final SolutionObject sol = sols[v]; /* * CHECK SERVICE SEQUENCE */ checkArgument(sol.route[0] == 0, "The route should always start with the vehicle start location: 0, " + "actual:%s.", sol.route[0]); checkArgument(sol.route[sol.route.length - 1] == n - 1, "The route should always finish with the depot."); if (currentDestinations[v] != 0) { checkArgument(sol.route[1] == currentDestinations[v], "Vehicle %s has a current destination %s, as such this must be the " + "first point to visit (at index 1). The route: %s.", v, currentDestinations[v], Arrays.toString(sol.route)); } final Set<Integer> locs = ImmutableSet.copyOf(Ints.asList(sol.route)); final Collection<Integer> inventory = inventoryMap.get(v); for (final Integer i : inventory) { checkArgument(locs.contains(i), "Every location in the inventory of a vehicle should occur in its " + "route, route for vehicle %s does not contain location %s.", v, i); } // check service pairs ordering, pickups should be visited before // their corresponding delivery location final Map<Integer, Integer> pairs = newHashMap(); for (int i = 0; i < servicePairs.length; i++) { pairs.put(servicePairs[i][0], servicePairs[i][1]); } final Set<Integer> seen = newHashSet(); final Set<Integer> set = newHashSet(Ints.asList(sol.route)); for (int i = 1; i < sol.route.length - 1; i++) { if (pairs.containsKey(sol.route[i])) { checkArgument(!seen.contains(pairs.get(sol.route[i])), "Pickups should be visited before their corresponding deliveries." + " Location %s should be visited after location %s.", pairs.get(sol.route[i]), sol.route[i]); checkArgument(set.contains(pairs.get(sol.route[i])), "Vehicle %s: this route should contain both the pickup and " + "delivery location, found %s, didn't find %s.", v, sol.route[i], pairs.get(sol.route[i])); } seen.add(sol.route[i]); } /* * CHECK ARRIVAL TIMES */ checkArgument(sol.arrivalTimes.length == sol.route.length, "Number of arrival times should equal number of locations."); checkArgument(sol.arrivalTimes[0] == 0, "The first arrival time should be 0, was %s.", sol.arrivalTimes[0]); // check feasibility final int[] minArrivalTimes = ArraysSolvers.computeArrivalTimes(sol.route, travelTime, remainingServiceTimes[v], vehicleTravelTimes[v], serviceTimes, releaseDates); for (int i = 1; i < sol.route.length; i++) { checkArgument(sol.arrivalTimes[i] >= minArrivalTimes[i], "Vehicle %s, route index %s, arrivalTime (%s) needs to be greater " + "or equal to minArrivalTime (%s).", v, i, sol.arrivalTimes[i], minArrivalTimes[i]); } /* * CHECK OBJECTIVE VALUE */ // sum travel time final int totalTravelTime = ArraysSolvers.computeTotalTravelTime(sol.route, travelTime, vehicleTravelTimes[v]); // sum tardiness final int tardiness = ArraysSolvers.computeRouteTardiness(sol.route, sol.arrivalTimes, serviceTimes, dueDates, remainingServiceTimes[v]); checkArgument(sol.objectiveValue == totalTravelTime + tardiness, "Vehicle %s: incorrect objective value (%s), it should be travel " + "time + tardiness = %s + %s = %s.", v, sol.objectiveValue, totalTravelTime, tardiness, totalTravelTime + tardiness); } return sols; }
From source file:it.cnr.istc.stlab.lizard.core.OntologyProjectGenerationRecipe.java
public void generateSwaggerDescription(String swaggerFolder) { LizardConfiguration l = LizardConfiguration.getInstance(); ImmutableMultimap.Builder<String, AbstractOntologyCodeClass> builderMap = new ImmutableMultimap.Builder<>(); AbstractOntologyCodeClass thingClass = this.ontologyModel.getOntologyClass( this.ontologyModel.asOntModel().getOntClass(OWL2.Thing.getURI()), BeanOntologyCodeInterface.class); this.ontologyModel.getEntityMap().get(BeanOntologyCodeClass.class).values().forEach(occ -> { builderMap.put(occ.getPackageName(), occ); builderMap.put(occ.getPackageName(), thingClass); });//from ww w .ja va 2 s . c o m Multimap<String, AbstractOntologyCodeClass> map = builderMap.build(); map.keySet().forEach(pack -> { String ontologyBasePath = "/" + pack.replaceAll("\\.", "_"); new File(swaggerFolder + ontologyBasePath).mkdirs(); DescriptionGenerator dg = new DescriptionGenerator(); dg.setApiDescription("Rest services for accessing the api defined in the package " + pack + " for accessing the corresponding ontology."); dg.setApiTitle(pack); dg.setApiVersion(l.getApiVersion()); dg.setBasePath(ontologyBasePath); dg.setContactName(l.getContactName()); dg.setContanctEmail(l.getContanctEmail()); dg.setHost(l.getHost()); dg.setLicenseName(l.getLicenseName()); dg.setLicenseUrl(l.getLicenseUrl()); dg.setClasses(map.get(pack)); try { FileOutputStream fos = new FileOutputStream( new File(swaggerFolder + ontologyBasePath + "/swagger.json")); fos.write(dg.generateSwaggerJSONStringDescription().getBytes()); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }); }
From source file:com.twitter.aurora.scheduler.thrift.SchedulerThriftInterface.java
private static Multimap<String, IJobConfiguration> jobsByKey(JobStore jobStore, IJobKey jobKey) { ImmutableMultimap.Builder<String, IJobConfiguration> matches = ImmutableMultimap.builder(); for (String managerId : jobStore.fetchManagerIds()) { for (IJobConfiguration job : jobStore.fetchJobs(managerId)) { if (job.getKey().equals(jobKey)) { matches.put(managerId, job); }/*from w w w .j a v a2 s .c o m*/ } } return matches.build(); }
From source file:com.facebook.buck.android.ExopackageInstaller.java
/** * Parses a text file which is supposed to be in the following format: * "file_path_without_spaces file_hash ...." i.e. it parses the first two columns of each line * and ignores the rest of it.//from ww w.j a v a2 s . co m * * @return A multi map from the file hash to its path, which equals the raw path resolved against * {@code resolvePathAgainst}. */ @VisibleForTesting static ImmutableMultimap<String, Path> parseExopackageInfoMetadata(Path metadataTxt, Path resolvePathAgainst, ProjectFilesystem filesystem) throws IOException { ImmutableMultimap.Builder<String, Path> builder = ImmutableMultimap.builder(); for (String line : filesystem.readLines(metadataTxt)) { // ignore lines that start with '.' if (line.startsWith(".")) { continue; } List<String> parts = Splitter.on(' ').splitToList(line); if (parts.size() < 2) { throw new RuntimeException("Illegal line in metadata file: " + line); } builder.put(parts.get(1), resolvePathAgainst.resolve(parts.get(0))); } return builder.build(); }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
@VisibleForTesting static void groupSchemeTests(ImmutableSet<TargetNode<AppleTestDescription.Arg>> groupableTests, ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> selectedTests, ImmutableMultimap.Builder<AppleTestBundleParamsKey, TargetNode<AppleTestDescription.Arg>> groupedTestsBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> ungroupedTestsBuilder) { for (Map.Entry<String, TargetNode<AppleTestDescription.Arg>> testEntry : selectedTests.entries()) { String schemeName = testEntry.getKey(); TargetNode<AppleTestDescription.Arg> test = testEntry.getValue(); if (groupableTests.contains(test)) { Preconditions.checkState(test.getConstructorArg().canGroup(), "Groupable test should actually be groupable."); groupedTestsBuilder//from w ww .j av a2 s . co m .put(AppleTestBundleParamsKey.fromAppleTestDescriptionArg(test.getConstructorArg()), test); } else { ungroupedTestsBuilder.put(schemeName, test); } } }
From source file:edu.ksu.cis.santos.mdcf.dml.symbol.SymbolTable.java
/** * Retrieves a {@link Multimap} that relates a sub type's fully-qualified name * (either of {@link BasicType#name} or {@link Feature#name}) to its super * type's fully-qualified name (either of {@link BasicType#name} or * {@link Feature#name}).// w w w .j a va 2 s.co m * * @return an immutable {@link Multimap}. */ public Multimap<String, String> superTransitiveMap() { Multimap<String, String> result = null; if ((this._superMap == null) || ((result = this._superMap.get()) == null)) { final HashSet<String> seen = new HashSet<>(); final HashMultimap<String, String> m = HashMultimap.create(); for (final BasicType bt : basicTypes()) { superTransitive(seen, m, bt); } for (final Feature f : features()) { superTransitive(seen, m, f); } final ImmutableMultimap.Builder<String, String> superb = ImmutableMultimap.builder(); final ImmutableMultimap.Builder<String, String> subb = ImmutableMultimap.builder(); for (final String sub : m.keySet()) { final Set<String> sups = m.get(sub); for (final String sup : sups) { superb.put(sub, sup); subb.put(sup, sub); } } result = superb.build(); this._superMap = new SoftReference<Multimap<String, String>>(result); this._subMap = new SoftReference<Multimap<String, String>>(subb.build()); } return result; }
From source file:grakn.core.graql.reasoner.atom.binary.RelationAtom.java
/** * @return map containing roleType - (rolePlayer var - rolePlayer type) pairs *//*from w w w .j a va 2s. c om*/ @Memoized public Multimap<Role, Variable> getRoleVarMap() { ImmutableMultimap.Builder<Role, Variable> builder = ImmutableMultimap.builder(); TransactionOLTP graph = getParentQuery().tx(); getRelationPlayers().forEach(c -> { Variable varName = c.getPlayer().var(); Statement rolePattern = c.getRole().orElse(null); if (rolePattern != null) { //try directly String typeLabel = rolePattern.getType().orElse(null); Role role = typeLabel != null ? graph.getRole(typeLabel) : null; //try indirectly if (role == null && rolePattern.var().isReturned()) { IdPredicate rolePredicate = getIdPredicate(rolePattern.var()); if (rolePredicate != null) { Role r = graph.getConcept(rolePredicate.getPredicate()); if (r == null) throw GraqlCheckedException.idNotFound(rolePredicate.getPredicate()); role = r; } } if (role != null) builder.put(role, varName); } }); return builder.build(); }