List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:com.facebook.buck.cxx.CxxHeaders.java
/** * @return the arguments to add to the preprocessor command line to include the given header packs * in preprocessor search path./* w w w .java2 s .c om*/ */ public static Iterable<String> getArgs(Iterable<CxxHeaders> cxxHeaderses, SourcePathResolver resolver, Optional<PathShortener> pathMinimizer, Preprocessor preprocessor) { ImmutableList.Builder<String> args = ImmutableList.builder(); // Collect the header maps and roots into buckets organized by include type, so that we can: // 1) Apply the header maps first (so that they work properly). // 2) De-duplicate redundant include paths. Multimap<CxxPreprocessables.IncludeType, String> headerMaps = LinkedHashMultimap.create(); Multimap<CxxPreprocessables.IncludeType, String> roots = LinkedHashMultimap.create(); for (CxxHeaders cxxHeaders : cxxHeaderses) { Optional<SourcePath> headerMap = cxxHeaders.getHeaderMap(); if (headerMap.isPresent()) { headerMaps.put(cxxHeaders.getIncludeType(), resolveSourcePathAndShorten(resolver, headerMap.get(), pathMinimizer).toString()); } roots.put(cxxHeaders.getIncludeType(), resolveSourcePathAndShorten(resolver, cxxHeaders.getIncludeRoot(), pathMinimizer).toString()); } // Define the include type ordering. We always add local ("-I") include paths first so that // headers match there before system ("-isystem") ones. ImmutableSet<CxxPreprocessables.IncludeType> includeTypes = ImmutableSet .of(CxxPreprocessables.IncludeType.LOCAL, CxxPreprocessables.IncludeType.SYSTEM); // Apply the header maps first, so that headers that matching there avoid falling back to // stat'ing files in the normal include roots. Preconditions.checkState(includeTypes.containsAll(headerMaps.keySet())); for (CxxPreprocessables.IncludeType includeType : includeTypes) { args.addAll(includeType.includeArgs(preprocessor, headerMaps.get(includeType))); } // Apply the regular includes last. Preconditions.checkState(includeTypes.containsAll(roots.keySet())); for (CxxPreprocessables.IncludeType includeType : includeTypes) { args.addAll(includeType.includeArgs(preprocessor, roots.get(includeType))); } return args.build(); }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
/** given a matching of nodes, extends the matching to pair up all edges which * have isomorphically matched incident nodes. In the case of a multigraph, * edges are matched arbitrarily./*from w ww . java 2 s. c o m*/ * * @param nodeMatching * @param fscc * @return */ public static GraphMatching induceEdgeMatchingUndirected(GraphMatching nodeMatching, FeatureSetCompatibilityChecker fscc) { final Graph g1 = nodeMatching.getGraph1(); final Graph g2 = nodeMatching.getGraph2(); BiMap<Integer, Integer> edgeMatch = HashBiMap.create(); Multimap<Set<Integer>, Integer> g2Edges = HashMultimap.create(); g2.getEdgeIDs().forEach( g2e -> g2Edges.put(Sets.newHashSet(g2.getEdgeSourceNodeID(g2e), g2.getEdgeTargetNodeID(g2e)), g2e)); g1.getEdgeIDs().forEach(eid -> { int g1n1 = g1.getEdgeSourceNodeID(eid); int g1n2 = g1.getEdgeTargetNodeID(eid); int g2n1 = nodeMatching.getMatchedNodeInGraph2(g1n1); int g2n2 = nodeMatching.getMatchedNodeInGraph2(g1n2); if (g2n1 == -1 || g2n2 == -1) return; //skip edges with unmapped nodes in graph 2 if (g2Edges.get(Sets.newHashSet(g2n1, g2n2)).size() == 0) return; //skip if it can't be matched to a graph 2 edge int g2MatchedEdge = -1; // make sure the edges are compatible for (int g2e : g2Edges.get(Sets.newHashSet(g2n1, g2n2))) if (fscc.apply(g1.getEdgeFeatures(eid).collect(toSet()), g2.getEdgeFeatures(g2e).collect(toSet()))) g2MatchedEdge = g2e; if (g2MatchedEdge != -1) //if we found a match, record it edgeMatch.put(eid, g2MatchedEdge); }); return includeEdgeMatching(nodeMatching, edgeMatch); }
From source file:com.taobao.android.builder.tools.solib.NativeSoUtils.java
/** * abiso// ww w . ja va2 s . co m * * @param supportAbis * @param removeSoFiles * @param dirs * @return */ public static Map<String, Multimap<String, File>> getAbiSoFiles(Set<String> supportAbis, Set<String> removeSoFiles, List<File> dirs) { Map<String, Multimap<String, File>> result = new HashMap<String, Multimap<String, File>>(); IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles); for (File dir : dirs) { Collection<File> files = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE); for (File file : files) { File parentFolder = file.getParentFile(); String parentName = parentFolder.getName(); String shortName = getSoShortName(file); Multimap<String, File> maps = result.get(parentName); if (null == maps) { maps = HashMultimap.create(10, 3); } maps.put(shortName, file); result.put(parentName, maps); } } return result; }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
/** given a matching of nodes, extends the matching to pair up all edges which * have isomorphically matched incident nodes. In the case of a multigraph, * edges are matched arbitrarily.//www . j ava 2 s . c om * * @param nodeMatching * @param fscc * @return */ public static GraphMatching induceEdgeMatching(GraphMatching nodeMatching, FeatureSetCompatibilityChecker fscc) { // if they're not directed, we need to treat edge compatibility differently: if (nodeMatching.getGraph1().getFeatures().anyMatch(f -> f.equals(DIRECTED)) && nodeMatching.getGraph2().getFeatures().anyMatch(f -> f.equals(DIRECTED))) return induceEdgeMatchingUndirected(nodeMatching, fscc); final Graph g1 = nodeMatching.getGraph1(); final Graph g2 = nodeMatching.getGraph2(); BiMap<Integer, Integer> edgeMatch = HashBiMap.create(); Multimap<Pair<Integer>, Integer> g2Edges = HashMultimap.create(); g2.getEdgeIDs().forEach( g2e -> g2Edges.put(Pair.makePair(g2.getEdgeSourceNodeID(g2e), g2.getEdgeTargetNodeID(g2e)), g2e)); g1.getEdgeIDs().forEach(eid -> { int g1n1 = g1.getEdgeSourceNodeID(eid); int g1n2 = g1.getEdgeTargetNodeID(eid); int g2n1 = nodeMatching.getMatchedNodeInGraph2(g1n1); int g2n2 = nodeMatching.getMatchedNodeInGraph2(g1n2); if (g2n1 == -1 || g2n2 == -1) return; //skip edges with unmapped nodes in graph 2 if (g2Edges.get(Pair.makePair(g2n1, g2n2)).size() == 0) return; //skip if it can't be matched to a graph 2 edge int g2MatchedEdge = -1; // make sure the edges are compatible for (int g2e : g2Edges.get(Pair.makePair(g2n1, g2n2))) if (fscc.apply(g1.getEdgeFeatures(eid).collect(toSet()), g2.getEdgeFeatures(g2e).collect(toSet()))) g2MatchedEdge = g2e; if (g2MatchedEdge != -1) //if we found a match, record it edgeMatch.put(eid, g2MatchedEdge); }); return includeEdgeMatching(nodeMatching, edgeMatch); }
From source file:org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler.java
@NotNull private static Set<CallableMemberDescriptor> collectSuperMethods(@NotNull ClassDescriptor classDescriptor) { Set<CallableMemberDescriptor> inheritedFunctions = new LinkedHashSet<CallableMemberDescriptor>(); for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) { for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) { if (descriptor instanceof CallableMemberDescriptor) { inheritedFunctions.add((CallableMemberDescriptor) descriptor); }/*from w w w. ja v a 2 s . c o m*/ } } // Only those actually inherited Set<CallableMemberDescriptor> filteredMembers = OverridingUtil.filterOutOverridden(inheritedFunctions); // Group members with "the same" signature Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = LinkedHashMultimap.create(); for (CallableMemberDescriptor one : filteredMembers) { if (factoredMembers.values().contains(one)) continue; for (CallableMemberDescriptor another : filteredMembers) { // if (one == another) continue; factoredMembers.put(one, one); if (OverridingUtil.isOverridableBy(one, another).getResult() == OVERRIDABLE || OverridingUtil.isOverridableBy(another, one).getResult() == OVERRIDABLE) { factoredMembers.put(one, another); } } } return factoredMembers.keySet(); }
From source file:org.jclouds.http.utils.Queries.java
private static void parseKeyValueFromStringToDecodedMap(String stringToParse, Multimap<String, String> map) { // note that '=' can be a valid part of the value int indexOfFirstEquals = stringToParse.indexOf('='); String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0, indexOfFirstEquals); String value = indexOfFirstEquals == -1 ? null : stringToParse.substring(indexOfFirstEquals + 1); map.put(urlDecode(key), urlDecode(value)); }
From source file:io.fd.maintainer.plugin.util.CommonTasks.java
static String formatReviewerInfo(final Set<ComponentReviewInfo> reviewInfoSet) { final Multimap<String, String> componentToAffectedFileIndex = LinkedListMultimap.create(); final Set<ComponentReviewInfo> componentBoundReviewInfoSet = reviewInfoSet.stream() .filter(reviewInfo -> reviewInfo.getState() == COMPONENT_FOUND).collect(Collectors.toSet()); componentBoundReviewInfoSet.forEach(reviewInfo -> componentToAffectedFileIndex .put(reviewInfo.getComponentName(), reviewInfo.getAffectedFile())); final Map<String, Set<Maintainer>> componentToMaintainers = new HashMap<>(); componentBoundReviewInfoSet.forEach(reviewInfo -> { if (!componentToMaintainers.containsKey(reviewInfo.getComponentName())) { componentToMaintainers.put(reviewInfo.getComponentName(), reviewInfo.getComponentMaintainers()); }//w w w. j a v a 2 s . co m }); final List<ComponentReviewInfo> componentNotFoundReviewInfos = reviewInfoSet.stream() .filter(reviewInfo -> reviewInfo.getState() == COMPONENT_NOT_FOUND).collect(Collectors.toList()); final String messageComponentsFound = componentToAffectedFileIndex.keySet().stream() .map(key -> format("Component %s%s%s" + "Maintainers :%s%s%s" + "Affected files :%s%s%s", key, LINE_SEPARATOR, LINE_SEPARATOR, LINE_SEPARATOR, formatMaintainers(componentToMaintainers.get(key)), LINE_SEPARATOR, LINE_SEPARATOR, formatFiles(componentToAffectedFileIndex.get(key)), LINE_SEPARATOR)) .collect(Collectors.joining(LINE_SEPARATOR)); final String messageComponentsNotFound = format("No component found for following files%s%s", LINE_SEPARATOR, formatFilesWithNoComponent(componentNotFoundReviewInfos)); if (nonNull(messageComponentsNotFound)) { return messageComponentsFound.concat(LINE_SEPARATOR).concat(messageComponentsNotFound); } else { return messageComponentsFound; } }
From source file:uk.ac.ebi.intact.dataexchange.cvutils.CvUtils.java
/** * Returns the id of the parent which is common to the children provided. If none is found, it returns null. * * @param children A CvTerms with a common parent * @return the common parent for the children */// w w w. ja v a 2s. co m public static CvDagObject findLowestCommonAncestor(CvDagObject... children) { if (children.length < 2) { throw new IllegalArgumentException("At least two children have to be provided to find a common parent"); } Multimap<String, String> cvMap = LinkedHashMultimap.create(); // get all the parents for each child for (CvDagObject child : children) { cvMap.put(child.getIdentifier(), child.getIdentifier()); cvMap.putAll(child.getIdentifier(), findAllParentsForTerm(child)); } // calculate the common parents by interesecting all the collections of parents for each child List<String> commonParents = null; for (Collection<String> parents : cvMap.asMap().values()) { List<String> parentsList = new LinkedList<String>(parents); if (commonParents == null) { commonParents = parentsList; } else { commonParents = ListUtils.intersection(commonParents, parentsList); } } // the first child of the commonParents collection is the lowest common ancestor if (!commonParents.isEmpty()) { String parentId = commonParents.iterator().next(); return findParentById(children[0], parentId); } return null; }
From source file:org.jetbrains.kotlin.idea.codeInsight.OverrideMethodsHandler.java
@NotNull private static Set<CallableMemberDescriptor> collectSuperMethods(@NotNull ClassDescriptor classDescriptor) { Set<CallableMemberDescriptor> inheritedFunctions = new LinkedHashSet<CallableMemberDescriptor>(); for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) { for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) { if (descriptor instanceof CallableMemberDescriptor) { inheritedFunctions.add((CallableMemberDescriptor) descriptor); }/*from w w w. ja va 2 s. c om*/ } } // Only those actually inherited Set<CallableMemberDescriptor> filteredMembers = OverrideResolver.filterOutOverridden(inheritedFunctions); // Group members with "the same" signature Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = LinkedHashMultimap.create(); for (CallableMemberDescriptor one : filteredMembers) { if (factoredMembers.values().contains(one)) continue; for (CallableMemberDescriptor another : filteredMembers) { // if (one == another) continue; factoredMembers.put(one, one); if (OverridingUtil.DEFAULT.isOverridableBy(one, another).getResult() == OVERRIDABLE || OverridingUtil.DEFAULT.isOverridableBy(another, one).getResult() == OVERRIDABLE) { factoredMembers.put(one, another); } } } return factoredMembers.keySet(); }
From source file:org.ambraproject.wombat.config.site.SiteRequestCondition.java
/** * Construct a map from each pattern to the sites that use that pattern. *//*from w w w. j a v a 2s .c om*/ private static Multimap<RequestMappingContext, Site> buildPatternMap(SiteSet siteSet, RequestMappingContext baseMapping) { Preconditions.checkArgument(!baseMapping.isSiteless()); Multimap<RequestMappingContext, Site> patterns = LinkedListMultimap.create(); for (Site site : siteSet.getSites()) { RequestMappingContext mapping = getMappingForSite(baseMapping, site); if (mapping != null) { patterns.put(mapping, site); } } return patterns; }