List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:com.evolveum.midpoint.util.ClassPathUtil.java
/** * This is not entirely reliable method. * Maybe it would be better to rely on Spring ClassPathScanningCandidateComponentProvider *///w ww .jav a 2 s .c om public static void searchClasses(String packageName, Consumer<Class> consumer) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setScanners(new SubTypesScanner(false)); builder.setUrls(ClasspathHelper.forPackage(packageName, LOGGER.getClass().getClassLoader())); builder.setInputsFilter(new FilterBuilder().includePackage(packageName)); Reflections reflections = new Reflections(builder); Multimap<String, String> map = reflections.getStore().get(SubTypesScanner.class.getSimpleName()); Set<String> types = new HashSet<>(); for (String key : map.keySet()) { Collection<String> col = map.get(key); if (col == null) { continue; } for (String c : col) { String simpleName = c.replaceFirst(packageName + "\\.", ""); if (simpleName.contains(".")) { continue; } types.add(c); } } for (String type : types) { try { Class clazz = Class.forName(type); consumer.accept(clazz); } catch (ClassNotFoundException e) { LOGGER.error("Error during loading class {}. ", type); } } }
From source file:org.deephacks.tools4j.config.internal.core.jpa.JpaBean.java
private static Set<BeanId> uniqueSet(Multimap<BeanId, JpaRef> refs) { Set<BeanId> ids = new HashSet<BeanId>(); for (BeanId id : refs.keySet()) { ids.add(id);/* www . ja v a2 s .c om*/ for (JpaRef ref : refs.get(id)) { ids.add(ref.getTarget()); } } return ids; }
From source file:com.google.errorprone.bugpatterns.ReplacementVariableFinder.java
private static ImmutableList<Fix> buildValidReplacements( Multimap<Integer, JCVariableDecl> potentialReplacements, Function<JCVariableDecl, Fix> replacementFunction) { if (potentialReplacements.isEmpty()) { return ImmutableList.of(); }/* w ww .j a v a 2s .c o m*/ // Take all of the potential edit-distance replacements with the same minimum distance, // then suggest them as individual fixes. return potentialReplacements.get(Collections.min(potentialReplacements.keySet())).stream() .map(replacementFunction).collect(toImmutableList()); }
From source file:org.corpus_tools.graphannis.SaltExport.java
public static SDocumentGraph map(API.NodeVector orig) { SDocumentGraph g = SaltFactory.createSDocumentGraph(); // convert the vector to a map Map<Long, API.Node> nodesByID = new LinkedHashMap<>(); for (long i = 0; i < orig.size(); i++) { nodesByID.put(orig.get(i).id(), orig.get(i)); }/* w w w . j a v a 2s. c o m*/ // create all new nodes Map<Long, SNode> newNodesByID = new LinkedHashMap<>(); for (Map.Entry<Long, API.Node> entry : nodesByID.entrySet()) { API.Node v = entry.getValue(); SNode n = mapNode(v); newNodesByID.put(entry.getKey(), n); } // add them to the graph newNodesByID.values().stream().forEach(n -> g.addNode(n)); // create and add all edges nodesByID.values().forEach((n) -> { for (long i = 0; i < n.outgoingEdges().size(); i++) { mapAndAddEdge(g, n, n.outgoingEdges().get(i), newNodesByID); } }); // find all chains of SOrderRelations and reconstruct the texts belonging to them Multimap<String, SNode> orderRoots = g.getRootsByRelationType(SALT_TYPE.SORDER_RELATION); orderRoots.keySet().forEach((name) -> { ArrayList<SNode> roots = new ArrayList<>(orderRoots.get(name)); if (SaltUtil.SALT_NULL_VALUE.equals(name)) { name = null; } recreateText(name, roots, g); }); addNodeLayers(g); return g; }
From source file:com.isotrol.impe3.core.impl.RequestParamsFactory.java
/** * Returns the collection of request parameters from a multimap object. * @param map Multimap.//from w w w .j a v a2 s . co m * @return The request query parameters. */ public static RequestParams of(Multimap<String, String> map) { if (map == null || map.isEmpty()) { return EMPTY; } final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder(); for (String key : map.keySet()) { final CaseIgnoringString cis = CaseIgnoringString.valueOf(key); builder.putAll(cis, map.get(key)); } return new Immutable(builder.build()); }
From source file:prm4jeval.dataanalysis.AnalysisResultsTableWriter.java
/** * @param mmap/*w w w . java 2 s . c o m*/ * key -> {measurements} * @return key -> (mean, ci/2) */ private final static Map<String, Tuple<Double, Double>> toConfidenceIntervalMap(Multimap<String, Double> mmap) { final Map<String, Tuple<Double, Double>> result = new HashMap<String, Tuple<Double, Double>>(); for (String key : mmap.keySet()) { final ConfidenceInterval confidenceInterval = new ConfidenceInterval(confidenceLevel); for (Double measurement : mmap.get(key)) { confidenceInterval.addMeasurement(measurement); } result.put(key, Tuple.tuple(confidenceInterval.getMean(), confidenceInterval.getWidth() / 2)); } return result; }
From source file:com.paolodragone.wsn.util.Senses.java
public static ListMultimap<String, Sense> buildWordSensesMap(Collection<Sense> senses) { Multimap<String, Sense> wordSensesMap = ArrayListMultimap.create(); ListMultimap<String, Sense> wordSensesSortedMap = ArrayListMultimap.create(); for (Sense sense : senses) { wordSensesMap.put(sense.getWord().toLowerCase(), sense); }/*from w ww . j av a 2 s. c o m*/ for (String word : wordSensesMap.keySet()) { List<Sense> senseList = new ArrayList<>(wordSensesMap.get(word)); sortSenseList(senseList); wordSensesSortedMap.putAll(word, senseList); } return wordSensesSortedMap; }
From source file:com.yahoo.yqlplus.engine.tools.TraceFormatter.java
public static void dump(OutputStream outputStream, TraceRequest trace) throws IOException { Multimap<Integer, TraceEntry> childmap = ArrayListMultimap.create(); for (TraceEntry entry : trace.getEntries()) { childmap.put(entry.getParentId(), entry); }//from w w w . j a va2s . c o m Multimap<Integer, TraceLogEntry> logmap = ArrayListMultimap.create(); for (TraceLogEntry entry : trace.getLog()) { logmap.put(entry.getTraceId(), entry); } CodeOutput out = new CodeOutput(); dumpTree(out, childmap, logmap, childmap.get(0)); outputStream.write(out.toString().getBytes(StandardCharsets.UTF_8)); }
From source file:org.sonar.java.filters.SuppressWarningFilter.java
private static boolean issueShouldNotBeReported(FilterableIssue issue, Multimap<String, Integer> excludedLineByRule) { RuleKey issueRuleKey = issue.ruleKey(); for (String excludedRule : excludedLineByRule.keySet()) { if (("all".equals(excludedRule) || isRuleKey(excludedRule, issueRuleKey)) && !isSuppressWarningRule(issueRuleKey)) { Collection<Integer> excludedLines = excludedLineByRule.get(excludedRule); if (excludedLines.contains(issue.line())) { return true; }/*from www. j a v a 2 s . c o m*/ } } return false; }
From source file:org.eclipse.ocl.examples.codegen.cse.HashedAnalyses.java
public static <V> void printIndented(@NonNull Appendable appendable, @NonNull Multimap<Integer, V> map, @NonNull String indentation, @NonNull String title) { try {//from www .ja v a 2 s . c o m List<Integer> keys = new ArrayList<Integer>(map.keySet()); Collections.sort(keys); for (Integer key : keys) { appendable.append(indentation + title + " " + key + "\n"); for (V analysis : map.get(key)) { appendable.append(indentation + "\t" + analysis.toString() + "\n"); } } } catch (IOException e) { e.printStackTrace(); } }