List of usage examples for com.google.common.collect Multimaps transformValues
public static <K, V1, V2> ListMultimap<K, V2> transformValues(ListMultimap<K, V1> fromMultimap, final Function<? super V1, V2> function)
From source file:com.facebook.buck.cli.CommandHelper.java
public static void printJSON(CommandRunnerParams params, Multimap<String, QueryTarget> targetsAndResults) throws IOException { Multimap<String, String> targetsAndResultsNames = Multimaps.transformValues(targetsAndResults, input -> Preconditions.checkNotNull(input.toString())); params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetsAndResultsNames.asMap()); }
From source file:org.eclipse.viatra.addon.validation.runtime.ValidationManager.java
/** * Returns the map of all the registered constraint specifications for the particular editor Ids. * //from w ww . ja v a2 s .c o m * @return A Multimap containing all the registered constraint specifications for each editor Id. * @deprecated Use {@link ConstraintExtensionRegistry#getEditorConstraintSpecificationMap()} instead */ public static synchronized Multimap<String, IConstraintSpecification> getEditorConstraintSpecificationMap() { Multimap<String, IProvider<IConstraintSpecification>> constraintSpecificationMap = ConstraintExtensionRegistry .getEditorConstraintSpecificationMap(); Multimap<String, IConstraintSpecification> unwrappedMap = Multimaps.transformValues( constraintSpecificationMap, new Function<IProvider<IConstraintSpecification>, IConstraintSpecification>() { @Override public IConstraintSpecification apply(IProvider<IConstraintSpecification> provider) { return provider.get(); } }); return unwrappedMap; }
From source file:org.apache.aurora.scheduler.http.Maintenance.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from w w w. j a va 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(); }); }
From source file:com.twitter.aurora.scheduler.http.Maintenance.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from w ww .j a v a 2 s . c o m*/ public Response getHosts() { return storage.weaklyConsistentRead(new Work.Quiet<Response>() { @Override public Response apply(StoreProvider storeProvider) { Multimap<MaintenanceMode, String> hostsByMode = Multimaps.transformValues( Multimaps.index(storeProvider.getAttributeStore().getHostAttributes(), GET_MODE), HOST_NAME); Map<MaintenanceMode, Object> hosts = Maps.newHashMap(); hosts.put(DRAINED, ImmutableSet.copyOf(hostsByMode.get(DRAINED))); hosts.put(SCHEDULED, ImmutableSet.copyOf(hostsByMode.get(SCHEDULED))); hosts.put(DRAINING, getTasksByHosts(storeProvider, hostsByMode.get(DRAINING)).asMap()); return Response.ok(hosts).build(); } }); }
From source file:com.github.lukaszkusek.xml.comparator.document.XMLDocument.java
private Multimap<String, Node> createNodeMultiMap(Collection<XPathLine> xPathLines) { return Multimaps.transformValues(FluentIterable.from(xPathLines).index(XPathLine::getXPath), xPathLine -> { Node node = new Node(xPathLine.getIndex(), xPathLine.getXPath()); node.setValue(xPathLine.getValue()); node.putAttribute(xPathLine.getAttributeName(), xPathLine.getAttributeValue()); return node; });//from w ww. j a va 2 s . c om }
From source file:com.qcadoo.mes.basic.shift.ShiftTimetableExceptions.java
private ImmutableMultimap<TimetableExceptionType, DateRange> getExceptions(final Entity shift) { List<Entity> timetableExceptionEntities = shift.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS); return ImmutableMultimap.copyOf(Multimaps .transformValues(Multimaps.index(timetableExceptionEntities, EXTRACT_TYPE), EXTRACT_DATE_RANGE)); }
From source file:org.jclouds.joyent.sdc.v6_5.compute.functions.OrphanedGroupsByDatacenterId.java
public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) { Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup()); Set<DatacenterAndName> datacenterAndGroupNames = ImmutableSet .copyOf(filter(transform(nodesWithGroup, new Function<NodeMetadata, DatacenterAndName>() { @Override/* ww w . jav a 2s. co m*/ public DatacenterAndName apply(NodeMetadata input) { String datacenterId = input.getLocation().getId(); return DatacenterAndName.fromDatacenterAndName(datacenterId, input.getGroup()); } }), allNodesInGroupTerminated)); Multimap<String, String> datacenterToDatacenterAndGroupNames = Multimaps.transformValues( Multimaps.index(datacenterAndGroupNames, DatacenterAndName.DATACENTER_FUNCTION), DatacenterAndName.NAME_FUNCTION); return datacenterToDatacenterAndGroupNames; }
From source file:org.apache.aurora.scheduler.http.Maintenance.java
private Multimap<String, String> getTasksByHosts(StoreProvider provider, Iterable<String> hosts) { if (Iterables.isEmpty(hosts)) { return ImmutableMultimap.of(); }/* w w w .j a v a2s . co m*/ ImmutableSet.Builder<IScheduledTask> drainingTasks = ImmutableSet.builder(); drainingTasks.addAll( provider.getTaskStore().fetchTasks(Query.slaveScoped(hosts).byStatus(Tasks.SLAVE_ASSIGNED_STATES))); return Multimaps.transformValues(Multimaps.index(drainingTasks.build(), Tasks::scheduledToSlaveHost), Tasks::id); }
From source file:org.jclouds.cloudstack.compute.functions.OrphanedGroupsByZoneId.java
public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) { Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup()); Set<ZoneAndName> zoneAndGroupNames = ImmutableSet .copyOf(filter(transform(nodesWithGroup, new Function<NodeMetadata, ZoneAndName>() { @Override//from w ww . jav a 2s . com public ZoneAndName apply(NodeMetadata input) { String zoneId = input.getLocation().getScope() == LocationScope.HOST ? input.getLocation().getParent().getId() : input.getLocation().getId(); return ZoneAndName.fromZoneAndName(zoneId, input.getGroup()); } }), allNodesInGroupTerminated)); Multimap<String, String> zoneToZoneAndGroupNames = Multimaps.transformValues( Multimaps.index(zoneAndGroupNames, ZoneAndName.ZONE_FUNCTION), ZoneAndName.NAME_FUNCTION); return zoneToZoneAndGroupNames; }
From source file:com.twitter.aurora.scheduler.http.Maintenance.java
private Multimap<String, String> getTasksByHosts(StoreProvider provider, Iterable<String> hosts) { ImmutableSet.Builder<IScheduledTask> drainingTasks = ImmutableSet.builder(); for (String host : hosts) { drainingTasks.addAll(provider.getTaskStore().fetchTasks(Query.slaveScoped(host).active())); }//ww w . j a va 2 s .co m return Multimaps.transformValues(Multimaps.index(drainingTasks.build(), TASK_TO_HOST), Tasks.SCHEDULED_TO_ID); }