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:dagger.internal.codegen.SubcomponentNames.java
private static ImmutableMap<ComponentDescriptor, String> namesByDescriptor(BindingGraph graph) { ImmutableListMultimap<String, ComponentDescriptor> componentDescriptorsBySimpleName = Multimaps.index( graph.componentDescriptors(), componentDescriptor -> componentDescriptor.typeElement().getSimpleName().toString()); ImmutableMap<ComponentDescriptor, Namer> componentNamers = qualifiedNames(graph.componentDescriptors()); Map<ComponentDescriptor, String> subcomponentImplSimpleNames = new LinkedHashMap<>(); componentDescriptorsBySimpleName.asMap().values().forEach(components -> subcomponentImplSimpleNames .putAll(disambiguateConflictingSimpleNames(components, componentNamers))); subcomponentImplSimpleNames.remove(graph.componentDescriptor()); return ImmutableMap.copyOf(subcomponentImplSimpleNames); }
From source file:edu.isi.karma.modeling.research.ComputeGED.java
private static void computeGEDApp1() throws Exception { File ff = new File(Params.JGRAPHT_DIR); File[] files = ff.listFiles(); DirectedWeightedMultigraph<Node, Link> gMain, gKarmaInitial, gKarmaFinal, gApp1Rank1, gApp1Rank2, gApp1Rank3;/*w w w . jav a 2 s.co m*/ HashSet<File> fileSet = new HashSet<File>(Arrays.asList(files)); Function<File, String> sameService = new Function<File, String>() { @Override 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; gApp1Rank1 = null; gApp1Rank2 = null; gApp1Rank3 = 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(".app1.rank1.jgraph")) { gApp1Rank1 = GraphUtil.deserialize(f.getPath()); } else if (f.getName().endsWith(".app1.rank2.jgraph")) { gApp1Rank2 = GraphUtil.deserialize(f.getPath()); } else if (f.getName().endsWith(".app1.rank3.jgraph")) { gApp1Rank3 = 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 (gApp1Rank1 != null) { distance = Util.getDistance(gMain, gApp1Rank1); label = "4-Rank1" + "-distance:" + distance; graphs.put(label, gApp1Rank1); } if (gApp1Rank2 != null) { distance = Util.getDistance(gMain, gApp1Rank2); label = "5-Rank2" + "-distance:" + distance; graphs.put(label, gApp1Rank2); } if (gApp1Rank3 != null) { distance = Util.getDistance(gMain, gApp1Rank3); label = "6-Rank3" + "-distance:" + distance; graphs.put(label, gApp1Rank3); } GraphVizUtil.exportJGraphToGraphvizFile(graphs, s, Params.OUTPUT_DIR + s + ".app1.out.dot"); } }
From source file:com.google.cloud.bigtable.dataflowimport.testing.SequenceFileIoUtils.java
/** * Creates a Sequence File and writes the content of {@code keyValues} to it. *///from ww w . ja v a 2s . c o m public static void createFileWithData(File sequenceFile, Collection<? extends Cell> keyValues) throws IOException { Configuration configuration = new Configuration(); // Configure serializers for Sequence File writer. configuration.set("io.serializations", WritableSerialization.class.getName() + "," + ResultSerialization.class.getName()); // Group cells by rowKey. ImmutableListMultimap<byte[], ? extends Cell> records = Multimaps.index(keyValues, new Function<Cell, byte[]>() { @Override public byte[] apply(Cell cell) { return CellUtil.cloneRow(cell); } }); try (Writer writer = SequenceFile.createWriter(configuration, Writer.keyClass(ImmutableBytesWritable.class), Writer.valueClass(Result.class), Writer.file(new Path(sequenceFile.toURI())))) { for (Collection<? extends Cell> cells : records.asMap().values()) { Result row = Result.create(cells.toArray(new Cell[cells.size()])); writer.append(new ImmutableBytesWritable(row.getRow()), row); } writer.close(); } }
From source file:org.jboss.metrics.agenda.impl.IntervalGrouping.java
@Override public Set<TaskGroup> apply(final List<Task> tasks) { ImmutableListMultimap<Interval, Task> tasksByInterval = Multimaps.index(tasks, new Function<Task, Interval>() { @Override/*from www. ja v a2 s .co m*/ public Interval apply(final Task definition) { return definition.getInterval(); } }); Set<TaskGroup> groups = new HashSet<>(); for (Interval interval : tasksByInterval.keys()) { TaskGroup group = new TaskGroup(interval); group.addTasks(tasksByInterval.get(interval)); groups.add(group); } return groups; }
From source file:com.facebook.presto.hive.PartitionUpdate.java
public static List<PartitionUpdate> mergePartitionUpdates(List<PartitionUpdate> unMergedUpdates) { ImmutableList.Builder<PartitionUpdate> partitionUpdates = ImmutableList.builder(); for (Collection<PartitionUpdate> partitionGroup : Multimaps.index(unMergedUpdates, PartitionUpdate::getName) .asMap().values()) {// w w w . j a va 2s . com PartitionUpdate firstPartition = partitionGroup.iterator().next(); ImmutableList.Builder<String> allFileNames = ImmutableList.builder(); for (PartitionUpdate partition : partitionGroup) { // verify partitions have the same new flag, write path and target path // this shouldn't happen but could if another user added a partition during the write if (partition.isNew() != firstPartition.isNew() || !partition.getWritePath().equals(firstPartition.getWritePath()) || !partition.getTargetPath().equals(firstPartition.getTargetPath())) { throw new PrestoException(HIVE_WRITER_ERROR, format("Partition %s was added or modified during INSERT", firstPartition.getName())); } allFileNames.addAll(partition.getFileNames()); } partitionUpdates.add(new PartitionUpdate(firstPartition.getName(), firstPartition.isNew(), firstPartition.getWritePath(), firstPartition.getTargetPath(), allFileNames.build())); } return partitionUpdates.build(); }
From source file:com.sun.tools.hat.internal.server.AllRootsQuery.java
@Override public void run() { startHtml("All Members of the Rootset"); // More interesting values are *higher* Multimap<Integer, Root> roots = Multimaps.index(snapshot.getRoots(), Root::getType); roots.asMap().entrySet().stream().sorted(Ordering.natural().reverse().onResultOf(entry -> entry.getKey())) .forEach(entry -> {/*from w ww .ja va2 s . c o m*/ out.print("<h2>"); print(Root.getTypeName(entry.getKey()) + " References"); out.println("</h2>"); entry.getValue().stream().sorted(Ordering.natural().onResultOf(Root::getDescription)) .forEach(root -> { printRoot(root); if (root.getReferer() != null) { out.print("<small> (from "); printThingAnchorTag(root.getReferer().getId()); print(root.getReferer().toString()); out.print(")</a></small>"); } out.print(" :<br>"); JavaThing t = snapshot.findThing(root.getId()); if (t != null) { // It should always be print("--> "); printThing(t); out.println("<br>"); } }); }); out.println("<h2>Other Queries</h2>"); out.println("<ul>"); out.println("<li>"); printAnchorStart(); out.print("\">"); print("Show All Classes"); out.println("</a>"); out.println("</ul>"); endHtml(); }
From source file:org.jclouds.vcloud.domain.internal.TasksListImpl.java
public TasksListImpl(URI location, SortedSet<Task> tasks) { this.location = location; this.tasks = tasks; this.tasksByResult = Multimaps.index(Iterables.filter(tasks, new Predicate<Task>() { public boolean apply(Task input) { return input.getResult() != null; }// w w w. j a v a 2 s .com }), new Function<Task, URI>() { public URI apply(Task input) { return input.getResult().getLocation(); } }); this.tasksByOwner = Multimaps.index(tasks, new Function<Task, URI>() { public URI apply(Task in) { return in.getOwner().getLocation(); } }); }
From source file:com.groupon.jenkins.dynamic.RecentBuilds.java
private List<RecentProject> groupByProject(Iterable<DynamicBuild> builds) { final ImmutableListMultimap<String, DynamicBuild> groupedByProject = Multimaps.index(builds, new Function<DynamicBuild, String>() { @Override//from w w w . jav a 2 s. co m public String apply(DynamicBuild build) { return build.getParent().getFullName(); } }); Iterable<RecentProject> groupedRecentProjects = Iterables.transform(groupedByProject.keySet(), new Function<String, RecentProject>() { @Override public RecentProject apply(String projectName) { return new RecentProject(projectName, groupedByProject.get(projectName)); } }); return Lists.newArrayList(groupedRecentProjects); }
From source file:cruise.umple.umpr.core.consistent.Consistents.java
/** * Builds an {@link ImportRepositorySet} from the runtime data produced by the {@link ConsoleMain} using * {@link ConsistentsBuilder}. //from ww w. j a v a2 s.c om * * @param outputFolder The location the repository lives. * @param allData {@link List} of {@link ImportRuntimeData} to map into new the consistent data structures. * @return Non-{@code null} instance */ public static ImportRepositorySet buildImportRepositorySet(final Path outputFolder, final Path srcFolder, final Iterable<? extends ImportFSM> allData) { final Multimap<Repository, ? extends ImportFSM> dataByRepo = Multimaps.index(allData, ImportFSM::getRepository); final ConsistentsBuilder cbld = CONSISTENTS_FACTORY.create(outputFolder, srcFolder); dataByRepo.asMap().entrySet().forEach(entry -> { final Repository key = entry.getKey(); final ConsistentRepositoryBuilder repoBld = cbld.withRepository(key); entry.getValue().forEach(data -> { final Path outpath = data.getOutputPath().getFileName(); if (data.isSuccessful()) { repoBld.addSuccessFile(outpath.toString(), data.getImportType(), data.getAttribLoc()); } else { repoBld.addFailedFile(outpath.toString(), data.getImportType(), data.getAttribLoc(), data.getState(), data.getFailure().get()); } }); repoBld.withCalculatedSuccessRate(); }); return cbld.getRepositorySet(); }
From source file:org.apache.aurora.scheduler.http.Maintenance.java
@GET @Produces(MediaType.APPLICATION_JSON)//w w w . java 2 s . c o m public Response getHosts() { return storage.read(storeProvider -> { Multimap<MaintenanceMode, String> hostsByMode = Multimaps.transformValues(Multimaps .index(storeProvider.getAttributeStore().getHostAttributes(), IHostAttributes::getMode), IHostAttributes::getHost); Map<MaintenanceMode, Object> hosts = ImmutableMap.of(DRAINED, ImmutableSet.copyOf(hostsByMode.get(DRAINED)), SCHEDULED, ImmutableSet.copyOf(hostsByMode.get(SCHEDULED)), DRAINING, getTasksByHosts(storeProvider, hostsByMode.get(DRAINING)).asMap()); return Response.ok(hosts).build(); }); }