List of usage examples for com.google.common.collect SetMultimap get
@Override Set<V> get(@Nullable K key);
Because a SetMultimap has unique values for a given key, this method returns a Set , instead of the java.util.Collection specified in the Multimap interface.
From source file:com.google.caliper.core.BenchmarkClassModel.java
/** * Validates the given user-provided parameters against the parameter fields on the benchmark * class.// w ww . j a v a 2 s .c o m */ public static void validateUserParameters(Class<?> clazz, SetMultimap<String, String> userParameters) { for (String paramName : userParameters.keySet()) { try { Field field = clazz.getDeclaredField(paramName); Parameters.validate(field, userParameters.get(paramName)); } catch (NoSuchFieldException e) { throw new InvalidCommandException("unrecognized parameter: " + paramName); } catch (InvalidBenchmarkException e) { // TODO(kevinb): this is weird. throw new InvalidCommandException(e.getMessage()); } } }
From source file:org.apache.gobblin.data.management.copy.hive.WhitelistBlacklist.java
private static boolean multimapContains(SetMultimap<Pattern, Pattern> multimap, String database, Optional<String> table, boolean blacklist) { for (Pattern dbPattern : multimap.keySet()) { if (dbPattern.matcher(database).matches()) { if (!table.isPresent()) { // if we are only matching database return !blacklist || multimap.get(dbPattern).contains(ALL_TABLES); }//w w w . java 2 s . c om for (Pattern tablePattern : multimap.get(dbPattern)) { if (tablePattern.matcher(table.get()).matches()) { return true; } } } } return false; }
From source file:com.google.gerrit.server.index.change.StalenessChecker.java
private static boolean refsAreStale(GitRepositoryManager repoManager, Change.Id id, Project.NameKey project, SetMultimap<Project.NameKey, RefState> allStates, ListMultimap<Project.NameKey, RefStatePattern> allPatterns) { try (Repository repo = repoManager.openRepository(project)) { Set<RefState> states = allStates.get(project); for (RefState state : states) { if (!state.match(repo)) { return true; }//from ww w .ja v a 2 s . c o m } for (RefStatePattern pattern : allPatterns.get(project)) { if (!pattern.match(repo, states)) { return true; } } return false; } catch (IOException e) { log.warn(String.format("error checking staleness of %s in %s", id, project), e); return true; } }
From source file:com.wrmsr.wava.basic.BasicLoopInfo.java
public static Map<Name, Name> getLoopParents(SetMultimap<Name, Name> loopContents) { Map<Name, Name> loopParents = new HashMap<>(); Map<Name, Set<Name>> map = loopContents.keySet().stream() .collect(toHashMap(identity(), loop -> new HashSet<>())); for (Name cur : loopContents.keySet()) { map.get(cur).add(ENTRY_NAME);//from w w w . j av a 2 s. com Set<Name> children = loopContents.get(cur); for (Name child : children) { if (!cur.equals(child) && loopContents.containsKey(child)) { map.get(child).add(cur); } } } Map<Name, Integer> loopDepths = map.entrySet().stream() .collect(toHashMap(entry -> entry.getKey(), entry -> entry.getValue().size())); loopDepths.put(ENTRY_NAME, 0); int maxDepth = loopDepths.values().stream().mapToInt(Integer::intValue).max().orElse(0); List<List<Name>> depthLoopsLists = IntStream.range(0, maxDepth + 1).boxed() .<List<Name>>map(i -> new ArrayList<>()).collect(toArrayList()); loopDepths.forEach((loop, depth) -> depthLoopsLists.get(depth).add(loop)); Set<Name> seen = new HashSet<>(); for (int depth = 1; depth < depthLoopsLists.size(); ++depth) { for (Name loop : depthLoopsLists.get(depth)) { Name parent = getOnlyElement(Sets.difference(map.get(loop), seen)); checkState(loopDepths.get(parent) == depth - 1); loopParents.put(loop, parent); } seen.addAll(depthLoopsLists.get(depth - 1)); } checkState(loopContents.keySet().equals(loopParents.keySet())); return loopParents; }
From source file:omero.cmd.graphs.GraphUtil.java
/** * Rearrange the deletion targets such that original files are listed before their containing directories. * @param session the Hibernate session/*from w ww .jav a 2 s . c o m*/ * @param targetObjects the objects that are to be deleted * @return the given target objects with any original files suitably ordered for deletion */ static SetMultimap<String, Long> arrangeDeletionTargets(Session session, SetMultimap<String, Long> targetObjects) { if (targetObjects.get(OriginalFile.class.getName()).size() < 2) { /* no need to rearrange anything, as there are not multiple original files */ return targetObjects; } final SetMultimap<String, Long> orderedIds = LinkedHashMultimap.create(); for (final Map.Entry<String, Collection<Long>> targetObjectsByClass : targetObjects.asMap().entrySet()) { final String className = targetObjectsByClass.getKey(); Collection<Long> ids = targetObjectsByClass.getValue(); if (OriginalFile.class.getName().equals(className)) { final Collection<Collection<Long>> sortedIds = ModelObjectSequencer.sortOriginalFileIds(session, ids); ids = new ArrayList<Long>(ids.size()); for (final Collection<Long> idBatch : sortedIds) { ids.addAll(idBatch); } } orderedIds.putAll(className, ids); } return orderedIds; }
From source file:org.inferred.freebuilder.processor.MethodFinder.java
/** * Returns all methods, declared and inherited, on {@code type}, except those specified by * {@link Object}./*from www . j ava 2 s.c om*/ * * <p>If method B overrides method A, only method B will be included in the return set. * Additionally, if methods A and B have the same signature, but are on unrelated interfaces, * one will be arbitrarily picked to be returned. */ public static ImmutableSet<ExecutableElement> methodsOn(TypeElement type, Elements elements) throws CannotGenerateCodeException { TypeElement objectType = elements.getTypeElement(Object.class.getCanonicalName()); SetMultimap<Signature, ExecutableElement> methods = LinkedHashMultimap.create(); for (TypeElement supertype : getSupertypes(type)) { for (ExecutableElement method : methodsIn(supertype.getEnclosedElements())) { if (method.getEnclosingElement().equals(objectType)) { continue; // Skip methods specified by Object. } Signature signature = new Signature(method); Iterator<ExecutableElement> iterator = methods.get(signature).iterator(); while (iterator.hasNext()) { ExecutableElement otherMethod = iterator.next(); if (elements.overrides(method, otherMethod, type) || method.getParameters().equals(otherMethod.getParameters())) { iterator.remove(); } } methods.put(signature, method); } } return ImmutableSet.copyOf(methods.values()); }
From source file:com.puppycrawl.tools.checkstyle.checks.TranslationCheck.java
/** * Arranges a set of property files by their prefix. * The method returns a Map object. The filename prefixes * work as keys each mapped to a set of files. * @param propFiles the set of property files * @param basenameSeparator the basename separator * @return a Map object which holds the arranged property file sets *//* w w w . jav a 2 s.c o m*/ private static SetMultimap<String, File> arrangePropertyFiles(List<File> propFiles, String basenameSeparator) { final SetMultimap<String, File> propFileMap = HashMultimap.create(); for (final File file : propFiles) { final String identifier = extractPropertyIdentifier(file, basenameSeparator); final Set<File> fileSet = propFileMap.get(identifier); fileSet.add(file); } return propFileMap; }
From source file:de.bund.bfr.knime.gis.views.regiontoregionvisualizer.RegionToRegionUtils.java
public static Set<String> getSelectedGisEdgeIds(Set<Edge<RegionNode>> gisEdges, Set<Edge<GraphNode>> graphSelectedEdges, boolean joinEdges) { if (!joinEdges) { return CanvasUtils.getElementIds(graphSelectedEdges); }/*from w w w .j a v a2 s . c o m*/ SetMultimap<Pair<String, String>, String> gisEdgesByRegion = LinkedHashMultimap.create(); for (Edge<RegionNode> gisEdge : gisEdges) { String fromRegion = gisEdge.getFrom().getId(); String toRegion = gisEdge.getTo().getId(); gisEdgesByRegion.put(new Pair<>(fromRegion, toRegion), gisEdge.getId()); } Set<String> selectedGisEdgeIds = new LinkedHashSet<>(); for (Edge<GraphNode> graphEdge : graphSelectedEdges) { String fromRegion = graphEdge.getFrom().getRegion(); String toRegion = graphEdge.getTo().getRegion(); selectedGisEdgeIds.addAll(gisEdgesByRegion.get(new Pair<>(fromRegion, toRegion))); } return selectedGisEdgeIds; }
From source file:eu.esdihumboldt.hale.common.align.tgraph.impl.internal.TGraphFactory.java
/** * Create a transformation graph from a transformation tree. * //from w w w .ja v a 2 s .co m * @param ttree the transformation tree * @param functionService the function service * @return an in-memory graph created from the transformation tree */ public static Graph create(TransformationTree ttree, FunctionService functionService) { TreeToGraphVisitor graphVisitor = new TreeToGraphVisitor(functionService); ttree.accept(graphVisitor); SetMultimap<String, String> connections = graphVisitor.getAllConnections(); Set<String> ids = graphVisitor.getAllIds(); Graph graph = new TinkerGraph(); // add nodes to the graph for (String key : ids) { // create a vertex for each transformation node TransformationNode node = graphVisitor.getNode(key); Vertex vertex = graph.addVertex(key); setVertexProperties(vertex, node); } for (String key : connections.keySet()) { for (String value : connections.get(key)) { Vertex targetSide = graph.getVertex(key); Vertex sourceSide = graph.getVertex(value); TransformationNode targetSideNode = graphVisitor.getNode(key); TransformationNode sourceSideNode = graphVisitor.getNode(value); String edgeLabel; if (sourceSideNode instanceof SourceNode && targetSideNode instanceof SourceNode) { edgeLabel = EDGE_CHILD; } else if (sourceSideNode instanceof SourceNode && targetSideNode instanceof CellNode) { edgeLabel = EDGE_VARIABLE; } else if (sourceSideNode instanceof CellNode && targetSideNode instanceof GroupNode) { edgeLabel = EDGE_RESULT; } else if (sourceSideNode instanceof GroupNode && targetSideNode instanceof GroupNode) { edgeLabel = EDGE_PARENT; } else { throw new IllegalStateException("Invalid relation in transformation tree"); } Edge edge = graph.addEdge(null, sourceSide, targetSide, edgeLabel); setEdgeProperties(edge, sourceSideNode, targetSideNode); } } return graph; }
From source file:de.bund.bfr.knime.gis.views.regiontoregionvisualizer.RegionToRegionUtils.java
public static Set<String> getSelectedGraphEdgeIds(Set<Edge<GraphNode>> graphEdges, Set<Edge<RegionNode>> gisSelectedEdges, boolean joinEdges) { if (!joinEdges) { return CanvasUtils.getElementIds(gisSelectedEdges); }/*from w ww . j a va 2 s .co m*/ SetMultimap<Pair<String, String>, String> graphEdgesByRegion = LinkedHashMultimap.create(); for (Edge<GraphNode> graphEdge : graphEdges) { String fromRegion = graphEdge.getFrom().getRegion(); String toRegion = graphEdge.getTo().getRegion(); graphEdgesByRegion.put(new Pair<>(fromRegion, toRegion), graphEdge.getId()); } Set<String> selectedGraphEdgeIds = new LinkedHashSet<>(); for (Edge<RegionNode> gisEdge : gisSelectedEdges) { String fromRegion = gisEdge.getFrom().getId(); String toRegion = gisEdge.getTo().getId(); selectedGraphEdgeIds.addAll(graphEdgesByRegion.get(new Pair<>(fromRegion, toRegion))); } return selectedGraphEdgeIds; }