Java Code Examples for com.google.common.collect.Multimap#keySet()

The following examples show how to use com.google.common.collect.Multimap#keySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets duplicates of a given type based on a guard (predicate). A given function is used for converting an instance of type T
 * to a string which is used for checking for duplicates.
 *
 * @param <T>
 *          the generic type
 * @param predicate
 *          the predicate acting as a guard
 * @param function
 *          returns a string for an instance of type T
 * @param elements
 *          the elements to be checked
 * @return the duplicates
 */
private <T extends EObject> Iterable<T> getDuplicates(final Predicate<T> predicate, final Function<T, String> function, final Iterable<T> elements) {
  List<T> result = Lists.newArrayList();
  Multimap<String, T> multiMap = Multimaps.newMultimap(Maps.<String, Collection<T>> newHashMap(), new Supplier<Collection<T>>() {
    @Override
    public Collection<T> get() {
      return Lists.<T> newArrayList();
    }
  });
  for (final T candidate : elements) {
    if (predicate.apply(candidate)) {
      multiMap.put(function.apply(candidate), candidate);
    }
  }
  for (String elem : multiMap.keySet()) {
    final Collection<T> duplicates = multiMap.get(elem);
    if (duplicates.size() > 1) {
      result.addAll(duplicates);
    }
  }

  return result;
}
 
Example 2
Source File: ThirdEyeUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static String getSortedFiltersFromMultiMap(Multimap<String, String> filterMultiMap) {
  Set<String> filterKeySet = filterMultiMap.keySet();
  ArrayList<String> filterKeyList = new ArrayList<String>(filterKeySet);
  Collections.sort(filterKeyList);

  StringBuilder sb = new StringBuilder();
  for (String filterKey : filterKeyList) {
    ArrayList<String> values = new ArrayList<String>(filterMultiMap.get(filterKey));
    Collections.sort(values);
    for (String value : values) {
      sb.append(filterKey);
      sb.append(FILTER_VALUE_ASSIGNMENT_SEPARATOR);
      sb.append(value);
      sb.append(FILTER_CLAUSE_SEPARATOR);
    }
  }
  return StringUtils.chop(sb.toString());
}
 
Example 3
Source File: DefaultQueryPlanner.java    From datawave with Apache License 2.0 6 votes vote down vote up
protected Multimap<String,Type<?>> configureIndexedAndNormalizedFields(Multimap<String,Type<?>> fieldToDatatypeMap, Set<String> indexedFields,
                Set<String> reverseIndexedFields, Set<String> normalizedFields, ShardQueryConfiguration config, ASTJexlScript queryTree)
                throws DatawaveQueryException, TableNotFoundException, InstantiationException, IllegalAccessException {
    log.debug("config.getDatatypeFilter() = " + config.getDatatypeFilter());
    log.debug("fieldToDatatypeMap.keySet() is " + fieldToDatatypeMap.keySet());
    
    config.setIndexedFields(indexedFields);
    config.setReverseIndexedFields(reverseIndexedFields);
    
    log.debug("normalizedFields = " + normalizedFields);
    
    config.setQueryFieldsDatatypes(HashMultimap.create(Multimaps.filterKeys(fieldToDatatypeMap, input -> !normalizedFields.contains(input))));
    log.debug("IndexedFields Datatypes: " + config.getQueryFieldsDatatypes());
    
    config.setNormalizedFieldsDatatypes(HashMultimap.create(Multimaps.filterKeys(fieldToDatatypeMap, normalizedFields::contains)));
    log.debug("NormalizedFields Datatypes: " + config.getNormalizedFieldsDatatypes());
    if (log.isTraceEnabled()) {
        log.trace("Normalizers:");
        for (String field : fieldToDatatypeMap.keySet()) {
            log.trace(field + ": " + fieldToDatatypeMap.get(field));
        }
    }
    
    return fieldToDatatypeMap;
    
}
 
Example 4
Source File: DataFlowBranchWalker.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void visit(Node node) {
	if (node.effectInfos.isEmpty()) {
		return;
	}

	ControlFlowElement cfe = node.getControlFlowElement();
	Multimap<Symbol, Object> assgns = getDataFlowVisitorHost().getAssignmentRelationFactory().findAssignments(cfe);

	Set<Symbol> handledDataFlowSymbols = new HashSet<>();
	for (Symbol lhs : assgns.keySet()) {
		Collection<Object> rhss = assgns.get(lhs);
		boolean handledDataFlow = handleDataflow(lhs, rhss);
		if (handledDataFlow) {
			handledDataFlowSymbols.add(lhs);
		}
	}
	for (EffectInfo effect : node.effectInfos) {
		handleVisitEffect(cfe, effect, handledDataFlowSymbols);
	}
}
 
Example 5
Source File: TestAssignmentCreatorForC3.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
void verifyMappings(List<CoordinationProtos.NodeEndpoint> endpoints, Multimap<Integer, TestHardAssignmentCreator.TestWork> mappings, Map<String, String> expectedMappings) {
  boolean isInstanceAffinity = mappings.values().iterator().next().getAffinity().get(0).isInstanceAffinity();
  Map<Integer, String> fragmentIdToHostnameMap = Maps.newHashMap();
  int fragmentId = 0;
  for(CoordinationProtos.NodeEndpoint endpoint : endpoints) {
    fragmentIdToHostnameMap.put(fragmentId, getHostname(endpoint, isInstanceAffinity));
    fragmentId++;
  }

  for(Integer id : mappings.keySet()) {
    String hostname = fragmentIdToHostnameMap.get(id);
    for(TestHardAssignmentCreator.TestWork split : mappings.get(id)) {
      // This split is assigned to fragmentId id
      String splitId = split.getId();
      String expValue = expectedMappings.get(splitId);
      Assert.assertTrue("Split " + splitId + " should be assigned to " + expValue + " was assigned to " + hostname, expValue.equalsIgnoreCase(hostname));
    }
  }
}
 
Example 6
Source File: MachineService.java    From redis-manager with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, List<Machine>> getMachineWithGroup(Integer groupId) {
    try {
        List<Machine> machines = machineDao.selectMachineByGroupId(groupId);
        if (machines == null || machines.isEmpty()) {
            return null;
        }
        Multimap<String, Machine> machineMultimap = ArrayListMultimap.create();
        machines.forEach(machine -> machineMultimap.put(machine.getMachineGroupName(), machine));
        Map<String, List<Machine>> machineMap = new LinkedHashMap<>();
        Set<String> machineGroupNameSet = machineMultimap.keySet();
        machineGroupNameSet.forEach(machineGroupName -> machineMap.put(machineGroupName, new ArrayList<>(machineMultimap.get(machineGroupName))));
        return machineMap;
    } catch (Exception e) {
        logger.error("Get machine by group id failed, group id = " + groupId, e);
        return null;
    }
}
 
Example 7
Source File: JDTAwareEclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Since sourceTraces are relative the URI has to be computed with the currentSource as context
 */
@Override
public void flushSourceTraces(String generatorName) throws CoreException {
	Multimap<SourceRelativeURI, IPath> sourceTraces = getSourceTraces();
	if (sourceTraces != null) {
		Set<SourceRelativeURI> keys = sourceTraces.keySet();
		String source = getCurrentSource();
		IContainer container = Strings.isEmpty(source) ? getProject() : getProject().getFolder(source);
		for (SourceRelativeURI uri : keys) {
			if (uri != null && source != null) {
				Collection<IPath> paths = sourceTraces.get(uri);
				IFile sourceFile = container.getFile(new Path(uri.getURI().path()));
				if (sourceFile.exists()) {
					IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
					getTraceMarkers().installMarker(sourceFile, generatorName, tracePathArray);
				}
			}
		}
	}
	resetSourceTraces();
}
 
Example 8
Source File: LinkageCheckerRule.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private String dependencyPathsOfProblematicJars(
    ClassPathResult classPathResult, Multimap<SymbolProblem, ClassFile> symbolProblems) {
  ImmutableSet.Builder<ClassPathEntry> problematicJars = ImmutableSet.builder();
  for (SymbolProblem problem : symbolProblems.keySet()) {
    ClassFile containingClass = problem.getContainingClass();
    if (containingClass != null) {
      problematicJars.add(containingClass.getClassPathEntry());
    }

    for (ClassFile classFile : symbolProblems.get(problem)) {
      problematicJars.add(classFile.getClassPathEntry());
    }
  }

  return "Problematic artifacts in the dependency tree:\n"
      + classPathResult.formatDependencyPaths(problematicJars.build());
}
 
Example 9
Source File: QueryOptions.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Build a String-ified version of the Map to serialize to this SKVI.
 *
 * @param map
 * @return
 */
public static String buildFieldNormalizerString(Multimap<String,Type<?>> map) {
    StringBuilder sb = new StringBuilder();
    
    for (String fieldName : map.keySet()) {
        if (sb.length() > 0) {
            sb.append(';');
        }
        
        sb.append(fieldName).append(':');
        
        boolean first = true;
        for (Type<?> type : map.get(fieldName)) {
            if (!first) {
                sb.append(',');
            }
            
            sb.append(type.getClass().getName());
            first = false;
        }
    }
    
    return sb.toString();
}
 
Example 10
Source File: JsonLdSerializer.java    From schemaorg-java with Apache License 2.0 6 votes vote down vote up
/**
 * Build a schema.org object of specific type, throw exceptions if it is not valid JSON-LD
 * entity for schema.org type. Uses reflection to invoke newXXXBuilder method in CoreFactory or
 * GoogFactory to create a builder object based on the value of {@literal @type}. Only accept
 * value of {@literal @type} being full type name such as "http://schema.org/Thing" or short
 * type name such as "Thing". And then, call addXXX method to update the property multimap based
 * on key-value pairs got from JSON-LD string.
 */
private static Thing buildSchemaOrgObject(
    String typeName,
    Multimap<String, ValueType> properties,
    ListMultimap<String, Thing> reverseMap)
    throws JsonLdSyntaxException {
  try {
    Class<?> builderClass = findBuilderClass(typeName);
    Thing.Builder builder = (Thing.Builder) createBuilder(builderClass);
    for (String key : properties.keySet()) {
      setPropertyValues(builderClass, builder, key, properties.get(key), typeName);
    }
    setReverseMap(builder, reverseMap);
    return (Thing) (builderClass.getMethod("build").invoke(builder));
  } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
    // Should not get any exception here. If one is caught, it means something wrong with this
    // client library.
    throw new JsonLdSyntaxException(
        String.format("JSON-LD deserialize internal error for type %s.", typeName),
        e.getCause());
  }
}
 
Example 11
Source File: GroupingAccumuloWriter.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void writeMetaData(BatchWriterConfig bwConfig, final List<Map.Entry<Multimap<String,String>,UID>> data) throws MutationsRejectedException,
                TableNotFoundException {
    Text dtText = new Text(this.dataType);
    Map<String,RawMetaData> meta = this.cfgData.getMetadata();
    try (BatchWriter bw = this.conn.createBatchWriter(QueryTestTableHelper.METADATA_TABLE_NAME, bwConfig)) {
        for (Map.Entry<Multimap<String,String>,UID> entry : data) {
            Multimap<String,String> rawData = entry.getKey();
            String shardDate = extractShard(rawData);
            
            for (String column : rawData.keySet()) {
                if (meta.containsKey(column.toLowerCase())) {
                    Mutation mut = new Mutation(column);
                    mut.put(ColumnFamilyConstants.COLF_E, dtText, EMPTY_VALUE);
                    Value colVal = new Value(SummingCombiner.VAR_LEN_ENCODER.encode((long) rawData.get(column).size()));
                    mut.put(ColumnFamilyConstants.COLF_F, new Text(this.dataType + NULL_SEP + shardDate), colVal);
                    if (this.fieldConfig.getIndexFields().contains(column)) {
                        mut.put(ColumnFamilyConstants.COLF_I, dtText, EMPTY_VALUE);
                    }
                    if (this.fieldConfig.getReverseIndexFields().contains(column)) {
                        mut.put(ColumnFamilyConstants.COLF_RI, dtText, EMPTY_VALUE);
                    }
                    Normalizer<?> norm = meta.get(column.toLowerCase()).normalizer;
                    String type = getNormalizerTypeName(norm);
                    mut.put(ColumnFamilyConstants.COLF_T, new Text(this.dataType + NULL_SEP + type), EMPTY_VALUE);
                    
                    bw.addMutation(mut);
                } else {
                    log.debug("skipping col entry(" + column + ")");
                }
            }
        }
    }
}
 
Example 12
Source File: IndexedSourceAdapter.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Override
protected void indexQuery(List<StreamValue> out, Location location, ContextPlanner planner, List<IndexQuery> queries, List<OperatorNode<PhysicalExprOperator>> args) {
    // split IndexQuery by index and then invoke each index exactly once
    OperatorNode<PhysicalExprOperator> sourceAdapter = createSource(location, planner, args);
    Multimap<IndexKey, IndexQuery> split = ArrayListMultimap.create();
    for (IndexQuery query : queries) {
        split.put(query.index, query);
    }
    for (IndexKey idx : split.keySet()) {
        Collection<IndexQuery> todo = split.get(idx);
        selectMap.get(idx).index(out, location, sourceAdapter, planner, Lists.newArrayList(todo));
    }
}
 
Example 13
Source File: DPreaggregatedMetricsRW.java    From blueflood with Apache License 2.0 5 votes vote down vote up
private void insertMetricsInBatch(Multimap<Locator, IMetric> map, Granularity granularity) {
    BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);

    for (Locator locator : map.keySet()) {
        for (IMetric metric : map.get(locator)) {
            RollupType rollupType = metric.getRollupType();

            DAbstractMetricIO io = rollupTypeToIO.get(rollupType);
            BoundStatement boundStatement = io.getBoundStatementForMetric(metric, granularity);
            batch.add(boundStatement);

            if (granularity == Granularity.FULL) {
                Instrumentation.markFullResPreaggregatedMetricWritten();
            }

            if( !LocatorCache.getInstance().isLocatorCurrentInBatchLayer(locator) ) {
                LocatorCache.getInstance().setLocatorCurrentInBatchLayer(locator);
                batch.add(locatorIO.getBoundStatementForLocator( locator ));
            }

            // if we are recording delayed metrics, we may need to do an
            // extra insert
            if ( isRecordingDelayedMetrics ) {
                BoundStatement bs = getBoundStatementForMetricIfDelayed(metric);
                if ( bs != null ) {
                    batch.add(bs);
                }
            }
        }
    }
    LOG.trace(String.format("insert preaggregated batch statement size=%d", batch.size()));

    try {
        DatastaxIO.getSession().execute(batch);
    } catch ( Exception ex ) {
        Instrumentation.markWriteError();
        LOG.error(String.format("error writing batch of %d preaggregated metrics", batch.size()), ex );
    }
}
 
Example 14
Source File: OverriddenValueInspector.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void visitFragment(RuleCall object) {
	Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures;
	assignedFeatures = newMultimap();
	if (fragmentStack.add(object)) {
		try {
			doSwitch(object.getRule().getAlternatives());
		} finally {
			fragmentStack.remove(object);
		}
	}
	Multimap<String, AbstractElement> assignedByFragment = assignedFeatures;
	assignedFeatures = prevAssignedFeatures;
	for (String feature : assignedByFragment.keySet())
		checkAssignment(object, feature);
}
 
Example 15
Source File: ORUIManager.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
private void addGenericTokenLays(LayToken action) {
    PublicCompany company = action.getCompany();
    NetworkGraph graph = networkAdapter.getRouteGraph(company, true, false);
    Multimap<MapHex, Stop> hexStops = graph.getTokenableStops(company);
    for (MapHex hex:hexStops.keySet()) {
        GUIHex guiHex = map.getHex(hex);
        TokenHexUpgrade upgrade = TokenHexUpgrade.create(guiHex, hexStops.get(hex), action);
        TokenHexUpgrade.validates(upgrade);
        hexUpgrades.put(guiHex, upgrade);
    }
}
 
Example 16
Source File: GroupingAccumuloWriter.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void writeShardKeys(BatchWriterConfig bwConfig, final List<Map.Entry<Multimap<String,String>,UID>> data) throws MutationsRejectedException,
                TableNotFoundException {
    Map<String,RawMetaData> meta = this.cfgData.getMetadata();
    try (BatchWriter bw = this.conn.createBatchWriter(QueryTestTableHelper.SHARD_TABLE_NAME, bwConfig)) {
        for (Map.Entry<Multimap<String,String>,UID> entry : data) {
            UID uid = entry.getValue();
            Multimap<String,String> rawData = entry.getKey();
            String shardId = extractShard(rawData);
            long timestamp = shardDateToMillis(shardId);
            shardId = shardId + "_0";
            
            for (String column : rawData.keySet()) {
                if (meta.containsKey(column.toLowerCase())) {
                    Mutation mut = new Mutation(shardId);
                    int count = 0;
                    
                    int cardinality = rawData.get(column).size();
                    for (String val : rawData.get(column)) {
                        if (this.fieldConfig.getIndexFields().contains(column)) {
                            Normalizer<?> norm = meta.get(column.toLowerCase()).normalizer;
                            mut.put(FIELD_INDEX + column, norm.normalize(val) + NULL_SEP + this.dataType + NULL_SEP + uid,
                                            this.cfgData.getDefaultVisibility(), timestamp, EMPTY_VALUE);
                        }
                        mut.put(this.dataType + NULL_SEP + uid, column + "." + count + NULL_SEP + val, this.cfgData.getDefaultVisibility(), timestamp,
                                        EMPTY_VALUE);
                        count++;
                    }
                    bw.addMutation(mut);
                } else {
                    log.debug("skipping column entry(" + column + ")");
                }
            }
        }
    }
}
 
Example 17
Source File: ClusterFactory.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private ListMultimap<Chromosome, Cluster> cluster(@NotNull final Multimap<Chromosome, SVSegment> variantPositions,
        @NotNull final Multimap<Chromosome, PCFPosition> pcfPositions, @NotNull final ListMultimap<Chromosome, CobaltRatio> ratios) {
    ListMultimap<Chromosome, Cluster> clusters = ArrayListMultimap.create();
    for (Chromosome chromosome : pcfPositions.keySet()) {
        final Collection<PCFPosition> chromosomePcfPositions = pcfPositions.get(chromosome);
        final List<CobaltRatio> chromosomeRatios = ratios.containsKey(chromosome) ? ratios.get(chromosome) : Lists.newArrayList();
        final Collection<SVSegment> chromosomeVariants =
                variantPositions.containsKey(chromosome) ? variantPositions.get(chromosome) : Lists.newArrayList();
        clusters.putAll(chromosome, cluster(chromosomeVariants, chromosomePcfPositions, chromosomeRatios));
    }

    return clusters;
}
 
Example 18
Source File: AwsMetadataCollector.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private List<CloudVmMetaDataStatus> collectCloudVmMetaDataStatuses(AuthenticatedContext ac, List<CloudInstance> vms,
        List<String> knownInstanceIdList) {
    LOGGER.debug("Collect Cloud VM metadata statuses");

    List<CloudVmMetaDataStatus> collectedCloudVmMetaDataStatuses = new ArrayList<>();

    String region = ac.getCloudContext().getLocation().getRegion().value();
    AmazonCloudFormationRetryClient amazonCFClient = awsClient.createCloudFormationRetryClient(new AwsCredentialView(ac.getCloudCredential()), region);
    AmazonAutoScalingRetryClient amazonASClient = awsClient.createAutoScalingRetryClient(new AwsCredentialView(ac.getCloudCredential()), region);
    AmazonEC2Client amazonEC2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();

    Multimap<String, CloudInstance> instanceGroupMap = getInstanceGroupMap(vms);

    Multimap<String, Instance> instancesOnAWSForGroup = ArrayListMultimap.create();
    for (String group : instanceGroupMap.keySet()) {
        List<Instance> instancesForGroup = collectInstancesForGroup(ac, amazonASClient, amazonEC2Client, amazonCFClient, group);
        instancesOnAWSForGroup.putAll(group, instancesForGroup);
    }

    Multimap<String, Instance> unknownInstancesForGroup = getUnkownInstancesForGroup(knownInstanceIdList, instancesOnAWSForGroup);
    for (CloudInstance vm : vms) {
        if (vm.getInstanceId() == null) {
            addFromUnknownMap(vm, unknownInstancesForGroup, collectedCloudVmMetaDataStatuses);
        } else {
            addKnownInstance(vm, instancesOnAWSForGroup, collectedCloudVmMetaDataStatuses);
        }
    }
    return collectedCloudVmMetaDataStatuses;
}
 
Example 19
Source File: RR2Lev.java    From Clusion with GNU General Public License v3.0 4 votes vote down vote up
public static RR2Lev constructEMMParGMM(final byte[] key, final Multimap<String, String> lookup, final int bigBlock,
		final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException {

	final Multimap<String, byte[]> dictionary = ArrayListMultimap.create();
	
	random.setSeed(CryptoPrimitives.randomSeed(16));

	for (int i = 0; i < dataSize; i++) {
		// initialize all buckets with random values
		free.add(i);
	}

	List<String> listOfKeyword = new ArrayList<String>(lookup.keySet());
	int threads = 0;
	if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) {
		threads = listOfKeyword.size();
	} else {
		threads = Runtime.getRuntime().availableProcessors();
	}

	ExecutorService service = Executors.newFixedThreadPool(threads);
	ArrayList<String[]> inputs = new ArrayList<String[]>(threads);

	for (int i = 0; i < threads; i++) {
		String[] tmp;
		if (i == threads - 1) {
			tmp = new String[listOfKeyword.size() / threads + listOfKeyword.size() % threads];
			for (int j = 0; j < listOfKeyword.size() / threads + listOfKeyword.size() % threads; j++) {
				tmp[j] = listOfKeyword.get((listOfKeyword.size() / threads) * i + j);
			}
		} else {
			tmp = new String[listOfKeyword.size() / threads];
			for (int j = 0; j < listOfKeyword.size() / threads; j++) {

				tmp[j] = listOfKeyword.get((listOfKeyword.size() / threads) * i + j);
			}
		}
		inputs.add(i, tmp);
	}

	Printer.debugln("End of Partitionning  \n");

	List<Future<Multimap<String, byte[]>>> futures = new ArrayList<Future<Multimap<String, byte[]>>>();
	for (final String[] input : inputs) {
		Callable<Multimap<String, byte[]>> callable = new Callable<Multimap<String, byte[]>>() {
			public Multimap<String, byte[]> call() throws Exception {

				Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize);
				return output;
			}
		};
		futures.add(service.submit(callable));
	}

	service.shutdown();

	for (Future<Multimap<String, byte[]>> future : futures) {
		Set<String> keys = future.get().keySet();

		for (String k : keys) {
			dictionary.putAll(k, future.get().get(k));
		}

	}

	return new RR2Lev(dictionary, array);
}
 
Example 20
Source File: APKModuleGraph.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * For each seed target, find its reachable targets and mark them in a multimap as being reachable
 * by that module for later sorting into exclusive and shared targets
 *
 * @return the Multimap containing targets and the seed modules that contain them
 */
private Multimap<BuildTarget, String> mapTargetsToContainingModules() {
  Multimap<BuildTarget, String> targetToContainingApkModuleNameMap =
      MultimapBuilder.treeKeys().treeSetValues().build();
  for (Map.Entry<String, ImmutableList<BuildTarget>> seedConfig :
      getSeedConfigMap().get().entrySet()) {
    String seedModuleName = seedConfig.getKey();
    for (BuildTarget seedTarget : seedConfig.getValue()) {
      targetToContainingApkModuleNameMap.put(seedTarget, seedModuleName);
      new AbstractBreadthFirstTraversal<TargetNode<?>>(targetGraph.get(seedTarget)) {
        @Override
        public ImmutableSet<TargetNode<?>> visit(TargetNode<?> node) {

          ImmutableSet.Builder<TargetNode<?>> depsBuilder = ImmutableSet.builder();
          for (BuildTarget depTarget : node.getBuildDeps()) {
            if (!isInRootModule(depTarget) && !isSeedTarget(depTarget)) {
              depsBuilder.add(targetGraph.get(depTarget));
              targetToContainingApkModuleNameMap.put(depTarget, seedModuleName);
            }
          }
          return depsBuilder.build();
        }
      }.start();
    }
  }
  // Now to generate the minimal covers of APKModules for each set of APKModules that contain
  // a buildTarget
  DirectedAcyclicGraph<String> declaredDependencies = getDeclaredDependencyGraph();
  Multimap<BuildTarget, String> targetModuleEntriesToRemove =
      MultimapBuilder.treeKeys().treeSetValues().build();
  for (BuildTarget key : targetToContainingApkModuleNameMap.keySet()) {
    Collection<String> modulesForTarget = targetToContainingApkModuleNameMap.get(key);
    new AbstractBreadthFirstTraversal<String>(modulesForTarget) {
      @Override
      public Iterable<String> visit(String moduleName) throws RuntimeException {
        Collection<String> dependentModules =
            declaredDependencies.getIncomingNodesFor(moduleName);
        for (String dependent : dependentModules) {
          if (modulesForTarget.contains(dependent)) {
            targetModuleEntriesToRemove.put(key, dependent);
          }
        }
        return dependentModules;
      }
    }.start();
  }
  for (Map.Entry<BuildTarget, String> entryToRemove : targetModuleEntriesToRemove.entries()) {
    targetToContainingApkModuleNameMap.remove(entryToRemove.getKey(), entryToRemove.getValue());
  }
  return targetToContainingApkModuleNameMap;
}