List of usage examples for com.google.common.collect Multimaps index
public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:edu.isi.karma.modeling.research.ComputeGED.java
private static void computeGEDApp2() throws Exception { File ff = new File(Params.JGRAPHT_DIR); File[] files = ff.listFiles(); DirectedWeightedMultigraph<Node, Link> gMain, gKarmaInitial, gKarmaFinal, gApp2; HashSet<File> fileSet = new HashSet<File>(Arrays.asList(files)); Function<File, String> sameService = new Function<File, String>() { @Override// ww w .j a v a 2 s. c om public String apply(final File s) { return s.getName().substring(0, s.getName().indexOf('.')); } }; Multimap<String, File> index = Multimaps.index(fileSet, sameService); for (String s : index.keySet()) { System.out.println(s); Collection<File> serviceFiles = index.get(s); gMain = null; gKarmaInitial = null; gKarmaFinal = null; gApp2 = null; for (File f : serviceFiles) { if (f.getName().endsWith(".main.jgraph")) { gMain = GraphUtil.deserialize(f.getPath()); } else if (f.getName().endsWith(".karma.initial.jgraph")) { gKarmaInitial = GraphUtil.deserialize(f.getPath()); } else if (f.getName().endsWith(".karma.final.jgraph")) { gKarmaFinal = GraphUtil.deserialize(f.getPath()); } else if (f.getName().endsWith(".app2.jgraph")) { gApp2 = GraphUtil.deserialize(f.getPath()); } } if (gMain == null) continue; String label; double distance; Map<String, DirectedWeightedMultigraph<Node, Link>> graphs = new TreeMap<String, DirectedWeightedMultigraph<Node, Link>>(); label = "0- Main"; graphs.put(label, gMain); if (gKarmaInitial != null) { distance = Util.getDistance(gMain, gKarmaInitial); label = "1-Karma Initial" + "-distance:" + distance; graphs.put(label, gKarmaInitial); } if (gKarmaFinal != null) { distance = Util.getDistance(gMain, gKarmaFinal); label = "3-Karma Final" + "-distance:" + distance; graphs.put(label, gKarmaFinal); } if (gApp2 != null) { distance = Util.getDistance(gMain, gApp2); label = "2-Output" + "-distance:" + distance; graphs.put(label, gApp2); } GraphVizUtil.exportJGraphToGraphvizFile(graphs, s, Params.OUTPUT_DIR + s + ".app2.out.dot"); } }
From source file:org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures.java
protected ListMultimap<String, IResolvedOperation> computeIndex(List<IResolvedOperation> operations) { // produces an immutable index which is what we want to have return Multimaps.index(operations, new Function<IResolvedOperation, String>() { @Override//from w w w. j av a 2s .co m public String apply(IResolvedOperation input) { return input.getResolvedErasureSignature(); } }); }
From source file:org.polarsys.reqcycle.repository.connector.update.pages.DialogUpdatePage.java
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); composite.setLayout(new GridLayout(1, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2)); Composite top = new Composite(composite, SWT.None); top.setLayout(new GridLayout(2, false)); top.setLayoutData(new GridData(GridData.FILL_BOTH)); ScrolledComposite scrolledComposite = new ScrolledComposite(top, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); Composite composite_1 = new Composite(scrolledComposite, SWT.NONE); composite_1.setLayout(new GridLayout(1, false)); Multimap<String, RequirementSource> allSourcesByConnector = Multimaps .index(Iterables.filter(reqSources, new Predicate<RequirementSource>() { @Override/*from w w w . j ava 2 s .co m*/ public boolean apply(RequirementSource arg0) { return arg0.getRepositoryURI() != null && arg0.getRepositoryURI().trim().length() > 0; } }), new Function<RequirementSource, String>() { @Override public String apply(RequirementSource arg0) { return connManager.get(arg0.getConnectorId()).getName(); } }); for (String connectorId : allSourcesByConnector.keySet()) { //a Local requirement source is not available to update Group group = new Group(composite_1, SWT.NONE); group.setLayout(new GridLayout(3, false)); group.setText(connectorId); group.setLayoutData(new GridData(SWT.FILL, SWT.UP, true, false, 3, 1)); for (RequirementSource rs : allSourcesByConnector.get(connectorId)) { createGroupWidgets(group, rs); } } scrolledComposite.setContent(composite_1); scrolledComposite.setMinSize(composite_1.computeSize(SWT.DEFAULT, SWT.DEFAULT)); return composite; }
From source file:com.android.build.gradle.internal.incremental.StringSwitch.java
/** * Emit code for a string switch for the given string classifier. * * switch(s.hashCode()) {/* ww w . j ava 2s .c o m*/ * case 192: visitCase(s); * case 312: visitCase(s); * case 1024: * if (s.equals("collided_method1")) { * visit(s); * } else if (s.equals("collided_method2")) { * visit(s); * } * visitDefault(); * default: * visitDefault(); * } * **/ private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitString(); visitHashMethod(mv); // Group strings by hash code. Multimap<Integer, String> buckets = Multimaps.index(strings, HASH_METHOD); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:edu.cmu.cs.lti.ark.fn.evaluation.PrepareFullAnnotationJson.java
/** * Reads predicted frame elements from testFEPredictionsFile and groups them by sentence index * * @param lines the predicted frame elements * @return a map from sentence num to a set of predicted frame elements for that sentence * @throws IOException if there is a problem reading from the file *//* w w w.j av a 2s.co m*/ public static Multimap<Integer, RankedScoredRoleAssignment> parseRoleAssignments(List<String> lines) { final List<RankedScoredRoleAssignment> roleAssignments = copyOf(transform(lines, processPredictionLine)); // group by sentence index return Multimaps.index(roleAssignments, getSentenceIndex); }
From source file:com.google.api.server.spi.discovery.DiscoveryGenerator.java
public Result writeDiscovery(Iterable<ApiConfig> configs, DiscoveryContext context, SchemaRepository schemaRepository) { ImmutableListMultimap<ApiKey, ApiConfig> configsByKey = Multimaps.index(configs, new Function<ApiConfig, ApiKey>() { @Override/* w w w .j av a 2 s . c o m*/ public ApiKey apply(ApiConfig config) { return config.getApiKey(); } }); ImmutableMap.Builder<ApiKey, RestDescription> builder = ImmutableMap.builder(); for (ApiKey apiKey : configsByKey.keySet()) { builder.put(apiKey, writeApi(apiKey, configsByKey.get(apiKey), context, schemaRepository)); } ImmutableMap<ApiKey, RestDescription> discoveryDocs = builder.build(); return Result.builder().setDiscoveryDocs(discoveryDocs) .setDirectory(generateDirectory(discoveryDocs, context)).build(); }
From source file:uk.ac.ebi.spot.rdf.model.baseline.ExperimentalFactors.java
public Multimap<FactorGroup, String> groupAssayGroupIdsByNonDefaultFilterFactor( Iterable<String> assayGroupIds) { Function<String, FactorGroup> groupByFunction = new Function<String, FactorGroup>() { public FactorGroup apply(String assayGroupId) { return getNonDefaultFilterFactors(assayGroupId); }//from w w w . j a v a2 s .co m }; return Multimaps.index(assayGroupIds, groupByFunction); }
From source file:dodola.anole.lib.StringSwitch.java
/** * Emit code for a string switch for the given string classifier. * * switch(s.hashCode()) {//from w w w . ja v a 2s . c o m * case 192: visitCase(s); * case 312: visitCase(s); * case 1024: * if (s.equals("collided_method1")) { * visit(s); * } else if (s.equals("collided_method2")) { * visit(s); * } * visitDefault(); * default: * visitDefault(); * } * **/ private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitString(); visitHashMethod(mv); // Group strings by hash code. Multimap<Integer, String> buckets = Multimaps.index(strings, hashMethod); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:models.documentStore.AspectOpinionMinedCorpusModel.java
private Map<Object, Collection<AspectOpinionMinedDocumentModel>> groupDocuments( Iterable<AspectOpinionMinedDocumentModel> documents, DocumentGrouping grouping) { Multimap<Object, AspectOpinionMinedDocumentModel> indexedDocuments = null; switch (grouping) { case orientation: indexedDocuments = Multimaps.index(documents, new Function<AspectOpinionMinedDocumentModel, Object>() { @Override/*w ww . j a v a 2 s .co m*/ @Nullable public Object apply(@Nullable AspectOpinionMinedDocumentModel document) { double polarity = ObjectUtils.defaultIfNull(document.polarity, 0.0); if (polarity < 0) { return NEGATIVE; } else if (polarity == 0) { return NEUTRAL; } return POSITIVE; } }); break; case aspect: indexedDocuments = ArrayListMultimap.create(); for (AspectOpinionMinedDocumentModel document : documents) { if (document.aspectPolarities == null || document.aspectPolarities.size() == 0) { indexedDocuments.put(null, document); } else { for (AspectLexiconModel aspect : document.aspectPolarities.keySet()) { indexedDocuments.put(aspect, document); } } } break; } return indexedDocuments.asMap(); }
From source file:org.obm.push.calendar.ConsistencyEventChangesLogger.java
private ImmutableListMultimap<EventObmId, Event> buildUpdatesMultimap(EventChanges changes) { return Multimaps.index(changes.getUpdated(), new Function<Event, EventObmId>() { @Override/*from ww w. j a v a 2s . c o m*/ public EventObmId apply(Event input) { return input.getObmId(); } }); }