List of usage examples for com.google.common.collect ImmutableSetMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:org.projectbuendia.client.models.LocationTree.java
/** * Creates a {@link LocationTree} from a {@link TypedCursor} of {@link Location}s. * If there are no locations in the local database, the location tree will have a null * root node (i.e. getRoot() == null).// w w w . j a v a 2s . c o m * <p/> * <p>Callers must call {@link #close} when done with an instance of this class. * @throws IllegalArgumentException if the location tree contains multiple root nodes or if the * the location tree has no root node or if the location tree * contains any nodes whose parents are missing */ public static LocationTree forTypedCursor(TypedCursor<Location> cursor) { Location root = null; Map<String, Location> uuidsToLocations = new HashMap<>(); Map<String, Location> uuidsToParents = new HashMap<>(); ImmutableSetMultimap.Builder<String, Location> uuidsToChildrenBuilder = ImmutableSetMultimap.builder(); // First, create mappings from location UUIDs to the locations themselves and to their // children. for (Location location : cursor) { if (location.parentUuid == null) { if (root != null) { LOG.w("Creating location tree with multiple root nodes. Both location '" + root.name + "' (UUID '" + root.uuid + "') and location '" + location.name + "' (UUID '" + location.uuid + "') have " + "no parent nodes. The first location will be considered " + "the root node."); } root = location; } else { uuidsToChildrenBuilder.put(location.parentUuid, location); } uuidsToLocations.put(location.uuid, location); } if (root == null) { LOG.w("Creating a location tree with no root node. This tree has no data."); return new LocationTree(cursor, null, uuidsToLocations, uuidsToParents, uuidsToChildrenBuilder.build()); } // Then, create a mapping from location UUIDs to their parents. for (Location location : uuidsToLocations.values()) { if (location.parentUuid == null) continue; Location parent = uuidsToLocations.get(location.parentUuid); if (parent == null) { // TODO: Consider making this a warning rather than an exception. throw new IllegalArgumentException( "Unable to create tree because a location's parent does not exist. " + "Location '" + location.name + "' (UUID '" + location.uuid + "' points to parent location with UUID '" + location.parentUuid + "', which does not exist."); } uuidsToParents.put(location.uuid, parent); } return new LocationTree(cursor, root, uuidsToLocations, uuidsToParents, uuidsToChildrenBuilder.build()); }
From source file:org.tensorics.core.tensor.lang.OngoingDimensionFlattening.java
private SetMultimap<Position, S> intoSetMultimap() { ImmutableSetMultimap.Builder<Position, S> builder = ImmutableSetMultimap.builder(); DimensionStripper dimensionStripper = Positions.stripping(dimensionsToFlatten); for (java.util.Map.Entry<Position, S> entry : TensorInternals.mapFrom(tensor).entrySet()) { Position newPosition = dimensionStripper.apply(entry.getKey()); builder.put(newPosition, entry.getValue()); }/* ww w . ja va 2s . c om*/ return builder.build(); }
From source file:org.tensorics.core.tensor.variance.CoContraDimensionPairs.java
public static Map<Class<?>, Collection<CoContraDimensionPair>> mapOutByContravariantPart( List<CoContraDimensionPair> allPairs) { ImmutableSetMultimap.Builder<Class<?>, CoContraDimensionPair> builder = ImmutableSetMultimap.builder(); for (CoContraDimensionPair pair : allPairs) { builder.putAll(pair.contravariant(), pair); }/* w w w . ja va 2 s . c o m*/ return builder.build().asMap(); }
From source file:co.cask.tigon.internal.app.runtime.flow.FlowUtils.java
/** * Configures all queues being used in a flow. * * @return A Multimap from flowletId to QueueName where the flowlet is a consumer of. */// w ww. j a v a 2 s . co m public static Multimap<String, QueueName> configureQueue(Program program, FlowSpecification flowSpec, QueueAdmin queueAdmin) { // Generate all queues specifications Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecs = new SimpleQueueSpecificationGenerator() .create(flowSpec); // For each queue in the flow, gather a map of consumer groupId to number of instances Table<QueueName, Long, Integer> queueConfigs = HashBasedTable.create(); // For storing result from flowletId to queue. ImmutableSetMultimap.Builder<String, QueueName> resultBuilder = ImmutableSetMultimap.builder(); // Loop through each flowlet for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) { String flowletId = entry.getKey(); long groupId = FlowUtils.generateConsumerGroupId(program, flowletId); int instances = entry.getValue().getInstances(); // For each queue that the flowlet is a consumer, store the number of instances for this flowlet for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.column(flowletId).values())) { queueConfigs.put(queueSpec.getQueueName(), groupId, instances); resultBuilder.put(flowletId, queueSpec.getQueueName()); } } try { // For each queue in the flow, configure it through QueueAdmin for (Map.Entry<QueueName, Map<Long, Integer>> row : queueConfigs.rowMap().entrySet()) { LOG.info("Queue config for {} : {}", row.getKey(), row.getValue()); queueAdmin.configureGroups(row.getKey(), row.getValue()); } return resultBuilder.build(); } catch (Exception e) { LOG.error("Failed to configure queues", e); throw Throwables.propagate(e); } }
From source file:com.google.devtools.build.xcode.xcodegen.Resources.java
public static Resources fromTargetControls(FileSystem fileSystem, PBXBuildFiles pbxBuildFiles, Iterable<TargetControl> targetControls) { ImmutableSetMultimap.Builder<TargetControl, PBXBuildFile> buildFiles = new ImmutableSetMultimap.Builder<>(); for (TargetControl targetControl : targetControls) { List<PBXBuildFile> targetBuildFiles = new ArrayList<>(); Iterable<String> simpleImports = Iterables.concat(targetControl.getXcassetsDirList(), targetControl.getBundleImportList()); // Add .bundle, .xcassets directories to the Project Navigator so they are visible from within // Xcode. // Bundle imports are handled very similarly to asset catalogs, so we just add them with the // same logic. Xcode's automatic file type detection logic is smart enough to see it is a // bundle and link it properly, and add the {@code lastKnownFileType} property. for (String simpleImport : simpleImports) { targetBuildFiles.add(pbxBuildFiles.getStandalone(FileReference.of(simpleImport, SourceTree.GROUP))); }/*from ww w .j a v a 2 s . com*/ Iterables.addAll(targetBuildFiles, pbxBuildFiles.get(AggregateReferenceType.PBXVariantGroup, RelativePaths.fromStrings(fileSystem, targetControl.getGeneralResourceFileList()))); // If this target is a binary, save the build files. Otherwise, we don't need them. The file // references we generated with fileObjects will be added to the main group later. if (!Equaling.of(ProductType.STATIC_LIBRARY, XcodeprojGeneration.productType(targetControl))) { buildFiles.putAll(targetControl, targetBuildFiles); } } return new Resources(buildFiles.build()); }
From source file:dagger.internal.codegen.IncompatiblyScopedBindingsValidation.java
@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { ImmutableSetMultimap.Builder<ComponentNode, BindingNode> incompatibleBindingNodes = ImmutableSetMultimap .builder();//from www . ja v a 2 s . c om for (BindingNode bindingNode : bindingGraph.bindingNodes()) { bindingNode.binding().scope().ifPresent(scope -> { if (scope.isReusable()) { return; } ComponentNode componentNode = bindingGraph.componentNode(bindingNode.componentPath()).get(); if (!componentNode.scopes().contains(scope)) { incompatibleBindingNodes.put(componentNode, bindingNode); } }); } Multimaps.asMap(incompatibleBindingNodes.build()) .forEach((componentNode, bindingNodes) -> diagnosticReporter.reportComponent(ERROR, componentNode, incompatibleBindingScopesError(componentNode, bindingNodes))); }
From source file:com.google.errorprone.bugpatterns.apidiff.ApiDiff.java
/** Converts a {@link Diff} to a {@link ApiDiff}. */ public static ApiDiff fromProto(Diff diff) { ImmutableSet.Builder<String> unsupportedClasses = ImmutableSet.builder(); ImmutableSetMultimap.Builder<String, ClassMemberKey> unsupportedMembersByClass = ImmutableSetMultimap .builder();//from w w w . j a v a 2 s.c o m for (ApiDiffProto.ClassDiff c : diff.getClassDiffList()) { switch (c.getDiffCase()) { case EVERYTHING_DIFF: unsupportedClasses.add(c.getEverythingDiff().getClassName()); break; case MEMBER_DIFF: ApiDiffProto.MemberDiff memberDiff = c.getMemberDiff(); for (ApiDiffProto.ClassMember member : memberDiff.getMemberList()) { unsupportedMembersByClass.put(memberDiff.getClassName(), ClassMemberKey.create(member.getIdentifier(), member.getMemberDescriptor())); } break; default: throw new AssertionError(c.getDiffCase()); } } return new AutoValue_ApiDiff(unsupportedClasses.build(), unsupportedMembersByClass.build()); }
From source file:com.facebook.buck.rules.TargetGraph.java
public TargetGraph(MutableDirectedGraph<TargetNode<?, ?>> graph, ImmutableMap<BuildTarget, TargetNode<?, ?>> index, ImmutableSet<TargetGroup> groups) { super(graph); this.targetsToNodes = index; ImmutableSetMultimap.Builder<BuildTarget, TargetGroup> builder = ImmutableSetMultimap.builder(); for (TargetGroup group : groups) { for (BuildTarget target : group) { if (targetsToNodes.containsKey(target)) { builder.put(target, group); }// w w w . j av a2 s . c o m } } this.groupsByBuildTarget = builder.build(); verifyVisibilityIntegrity(); }
From source file:com.sun.tools.hat.internal.server.RefsByTypeQuery.java
@Override public void run() { ClassResolver resolver = new ClassResolver(snapshot, true); JavaClass clazz = resolver.apply(query); Collection<JavaClass> referrers = Collections2.transform(params.get("referrer"), resolver); ImmutableSetMultimap.Builder<JavaClass, JavaHeapObject> rfrBuilder = ImmutableSetMultimap.builder(); final ImmutableSetMultimap.Builder<JavaClass, JavaHeapObject> rfeBuilder = ImmutableSetMultimap.builder(); for (final JavaHeapObject instance : Misc.getInstances(clazz, false, referrers)) { if (instance.getId() == -1) { continue; }//from w w w . j av a2s . c om for (JavaHeapObject ref : instance.getReferers()) { JavaClass cl = ref.getClazz(); if (cl == null) { System.out.println("null class for " + ref); continue; } rfrBuilder.put(cl, instance); } instance.visitReferencedObjects(obj -> rfeBuilder.put(obj.getClazz(), instance)); } // for each instance startHtml("References by Type"); out.println("<p align='center'>"); printClass(clazz); if (clazz.getId() != -1) { println("[" + clazz.getIdString() + "]"); } out.println("</p>"); printBreadcrumbs(path, null, null, clazz, referrers, null); ImmutableMultiset<JavaClass> referrersStat = rfrBuilder.build().keys(); if (!referrersStat.isEmpty()) { out.println("<h3 align='center'>Referrers by Type</h3>"); print(referrersStat, clazz, referrers, true); } ImmutableMultiset<JavaClass> refereesStat = rfeBuilder.build().keys(); if (!refereesStat.isEmpty()) { out.println("<h3 align='center'>Referees by Type</h3>"); print(refereesStat, clazz, referrers, false); } endHtml(); }
From source file:com.github.rinde.rinsim.core.model.ModelManager.java
@SuppressWarnings("unchecked") ModelManager(ImmutableSet<? extends Model<?>> ms) { models = (ImmutableSet<Model<?>>) ms; final ImmutableSetMultimap.Builder<Class<?>, Model<?>> builder = ImmutableSetMultimap.builder(); builder.put(ModelReceiver.class, new ModelReceiverModel(this)); final Set<UserInterface> uis = new LinkedHashSet<>(); for (final Model<?> m : models) { final Class<?> suptype = m.getSupportedType(); checkNotNull(suptype, "Model.getSupportedType() must return a non-null, model: %s.", m); builder.put(suptype, m);/*from w w w.j a va 2s . co m*/ if (m instanceof UserInterface) { uis.add((UserInterface) m); } } checkState(uis.size() <= 1, "At most one implementor of %s can be defined, found %s.", UserInterface.class, uis); if (uis.isEmpty()) { userInterface = Optional.absent(); } else { userInterface = Optional.of(uis.iterator().next()); } registry = builder.build(); for (final Model<?> m : models) { doRegister(m); } }