List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:com.google.devtools.j2objc.translate.OcniExtractor.java
/** * Finds all block comments and associates them with their containing type. * This is trickier than you might expect because of inner types. *//*from www. java 2 s .co m*/ private static ListMultimap<TreeNode, Comment> findBlockComments(CompilationUnit unit) { ListMultimap<TreeNode, Comment> blockComments = ArrayListMultimap.create(); for (Comment comment : unit.getCommentList()) { if (!comment.isBlockComment()) { continue; } int commentPos = comment.getStartPosition(); AbstractTypeDeclaration containingType = null; int containingTypePos = -1; for (AbstractTypeDeclaration type : unit.getTypes()) { int typePos = type.getStartPosition(); if (typePos < 0) { continue; } int typeEnd = typePos + type.getLength(); if (commentPos > typePos && commentPos < typeEnd && typePos > containingTypePos) { containingType = type; containingTypePos = typePos; } } blockComments.put(containingType != null ? containingType : unit, comment); } return blockComments; }
From source file:org.codeqinvest.investment.QualityInvestmentPlanService.java
public QualityInvestmentPlan computeInvestmentPlan(QualityAnalysis analysis, String basePackage, int investmentInMinutes) { Multimap<Double, QualityViolation> violationsByProfit = ArrayListMultimap.create(); for (QualityViolation violation : filterViolationsByArtefactNameStartingWith(basePackage, analysis.getViolations())) { double profit = profitCalculator.calculateProfit(violation); if (Math.round(profit) > 0) { violationsByProfit.put(profit, violation); }//from w w w. j av a 2 s . c o m } List<Double> allProfits = new ArrayList<Double>(); for (Double profit : violationsByProfit.keySet()) { int numberOfViolations = violationsByProfit.get(profit).size(); for (int i = 0; i < numberOfViolations; i++) { allProfits.add(profit); } } Collections.sort(allProfits, new DescendingComparator<Double>()); Set<QualityInvestmentPlanEntry> investmentPlanEntries = Sets.newTreeSet(); int toInvest = investmentInMinutes; int invested = 0; for (double profit : allProfits) { List<QualityViolation> violations = new ArrayList<QualityViolation>(violationsByProfit.get(profit)); Collections.sort(violations, new ViolationByRemediationCostsComparator()); for (QualityViolation violation : violations) { int remediationCost = violation.getRemediationCosts(); if (remediationCost <= toInvest) { invested += remediationCost; toInvest -= remediationCost; QualityRequirement requirement = violation.getRequirement(); investmentPlanEntries.add(new QualityInvestmentPlanEntry(requirement.getMetricIdentifier(), requirement.getOperator() + " " + requirement.getThreshold(), violation.getArtefact().getName(), violation.getArtefact().getShortClassName(), (int) Math.round(profit), remediationCost)); } } } final int overallProfit = calculateOverallProfit(investmentPlanEntries); return new QualityInvestmentPlan(basePackage, invested, overallProfit, calculateRoi(investmentPlanEntries, overallProfit), investmentPlanEntries); }
From source file:de.ii.xtraplatform.feature.provider.pgis.SqlFeatureCreator.java
public SqlFeatureCreator(SlickSession session, ActorMaterializer materializer, SqlFeatureInserts inserts) { this.session = session; this.materializer = materializer; this.inserts = inserts; this.multiplicities = ArrayListMultimap.create(); this.valueContainer = inserts.getValueContainer(ImmutableMap.of()); }
From source file:t9.T9algo.java
private static String nums_to_text(String num_string) throws FileNotFoundException, IOException { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. String li[] = num_string.split("\\*"); TreeMap<String, String[]> z = new TreeMap<>(); for (String num_word : li) { String tmp[] = textonyms(num_word); z.put(num_word, tmp);/*from w w w . ja va 2s . c o m*/ } String bnc_str; StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader( new FileReader("/home/rb/NetBeansProjects/Test/src/test/all.num.o5.txt")); try { String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } bnc_str = sb.toString();//.split("\\n"); // System.out.println(everything[1]); } finally { br.close(); } Multimap<String, String> d3 = ArrayListMultimap.create(); StringBuilder s_words = new StringBuilder(); StringBuilder all_words = new StringBuilder(); // TreeMap<String,String> d3= new TreeMap<>(); for (Map.Entry<String, String[]> entry : z.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); for (String item : value) { String pattern = "(\\S*)" + item; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(bnc_str); int i; for (i = m.start() - 2; i >= 0; --i) if (bnc_str.charAt(i) == 32) break; d3.put(item, bnc_str.substring(i + 1, m.start() - 1)); } // all_words.append(bnc_str.substring(i+1,m.start()-1)+" "); all_words.append(d3.get(key) + " "); } return all_words.toString(); }
From source file:org.zalando.logbook.spring.Request.java
@Override public Multimap<String, String> getHeaders() { final ListMultimap<String, String> map = ArrayListMultimap.create(); request.getHeaders().forEach(map::putAll); return map;//w w w .j ava 2 s . c om }
From source file:org.jboss.tools.windup.ui.internal.explorer.Group.java
private List<IssueGroupNode<?>> createGroupNodesHelper(IssueGroupNode<?> parent, List<IMarker> markers) { List<IssueGroupNode<?>> nodes = Lists.newArrayList(); Multimap<T, IMarker> groups = ArrayListMultimap.create(); markers.forEach(marker -> {/*from www . ja v a 2s . c om*/ T identifier = findIdentifier(marker); if (identifier != null) { groups.put(identifier, marker); } }); for (T id : groups.keySet()) { List<IMarker> groupMarkers = Lists.newArrayList(groups.get(id)); E node = createGroupNode(parent, id, groupMarkers); if (!children.isEmpty()) { List<IssueGroupNode<?>> nodeChildren = Lists.newArrayList(); for (Group<?, ?> child : children) { List<IssueGroupNode<?>> tempChildren = child.createGroupNodesHelper(node, groupMarkers); if (!tempChildren.isEmpty()) { nodeChildren.addAll(tempChildren); } } node.setChildren(nodeChildren); } nodes.add(node); } return nodes; }
From source file:org.nmdp.ngs.variant.vcf.StreamingVcfParser.java
/** * Stream the specified readable./*from w w w.j a v a2 s. co m*/ * * @param readable readable, must not be null * @param listener event based reader callback, must not be null * @throws IOException if an I/O error occurs */ public static void stream(final Readable readable, final VcfStreamListener listener) throws IOException { checkNotNull(readable); checkNotNull(listener); VcfParser.parse(readable, new VcfParseAdapter() { /** VCF record builder. */ private final VcfRecord.Builder builder = VcfRecord.builder(); /** File format, e.g. <code>VCFv4.2</code>, the only required header field. */ private String fileFormat; /** List of meta-information header lines. */ private List<String> meta = new ArrayList<String>(); /** VCF samples keyed by name. */ private Map<String, VcfSample> samples = new HashMap<String, VcfSample>(); @Override public void lineNumber(final long lineNumber) throws IOException { builder.withLineNumber(lineNumber); } @Override public void meta(final String meta) throws IOException { this.meta.add(meta.trim()); if (meta.startsWith("##fileformat=")) { fileFormat = meta.substring(13).trim(); } else if (meta.startsWith("##SAMPLE=")) { ListMultimap<String, String> values = ArrayListMultimap.create(); String[] tokens = meta.substring(10).split(","); for (String token : tokens) { String[] metaTokens = token.split("="); String key = metaTokens[0]; String[] valueTokens = metaTokens[1].split(";"); for (String valueToken : valueTokens) { values.put(key, valueToken.replace("\"", "").replace(">", "")); } } String id = values.get("ID").get(0); List<String> genomeIds = values.get("Genomes"); List<String> mixtures = values.get("Mixture"); List<String> descriptions = values.get("Description"); List<VcfGenome> genomes = new ArrayList<VcfGenome>(genomeIds.size()); for (int i = 0, size = genomeIds.size(); i < size; i++) { genomes.add(new VcfGenome(genomeIds.get(i), Double.parseDouble(mixtures.get(i)), descriptions.get(i))); } samples.put(id, new VcfSample(id, genomes.toArray(new VcfGenome[0]))); } } @Override public void samples(final String... samples) throws IOException { for (String sample : samples) { // add if missing in meta lines if (!this.samples.containsKey(sample)) { this.samples.put(sample, new VcfSample(sample, new VcfGenome[0])); } } // at end of header lines, notify listener of header listener.header(new VcfHeader(fileFormat, meta)); // ...and samples for (VcfSample sample : this.samples.values()) { listener.sample(sample); } } @Override public void chrom(final String chrom) throws IOException { builder.withChrom(chrom); } @Override public void pos(final long pos) throws IOException { builder.withPos(pos); } @Override public void id(final String... id) throws IOException { builder.withId(id); } @Override public void ref(final String ref) throws IOException { builder.withRef(ref); } @Override public void alt(final String... alt) throws IOException { builder.withAlt(alt); } @Override public void qual(final double qual) throws IOException { builder.withQual(qual); } @Override public void filter(final String... filter) throws IOException { builder.withFilter(filter); } @Override public void info(final String infoId, final String... values) throws IOException { builder.withInfo(infoId, values); } @Override public void format(final String... format) throws IOException { builder.withFormat(format); } @Override public void genotype(final String sampleId, final String formatId, final String... values) throws IOException { builder.withGenotype(sampleId, formatId, values); } @Override public boolean complete() throws IOException { listener.record(builder.build()); builder.reset(); fileFormat = null; meta = null; samples = null; return true; } }); }
From source file:gg.uhc.uhc.messages.BaseMessageTemplates.java
public BaseMessageTemplates(Config config) { this.config = config; this.templating = new DefaultMustacheFactory(); this.templates = ArrayListMultimap.create(); }
From source file:com.google.gerrit.server.notedb.DraftCommentNotesParser.java
DraftCommentNotesParser(Change.Id changeId, RevWalk walk, ObjectId tip, GitRepositoryManager repoManager, AllUsersName draftsProject, Account.Id author) throws RepositoryNotFoundException, IOException { this.changeId = changeId; this.walk = walk; this.tip = tip; this.repo = repoManager.openMetadataRepository(draftsProject); this.author = author; comments = ArrayListMultimap.create(); }
From source file:org.eclipse.viatra.query.patternlanguage.emf.util.AdvancedPatternParsingResults.java
protected AdvancedPatternParsingResults() { this.addedSpecifications = new HashSet<IQuerySpecification>(); this.updatedSpecifications = new HashSet<IQuerySpecification>(); this.removedSpecifications = new HashSet<IQuerySpecification>(); this.impactedSpecifications = new HashSet<IQuerySpecification>(); this.uriMap = ArrayListMultimap.create(); }