List of usage examples for com.google.common.collect Maps transformValues
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap, Function<? super V1, V2> function)
From source file:com.blurengine.blur.modules.goal.ScoreComponent.java
/** * Returns an immutable map of objects with a score represented by a {@code double} value. * * @return immutable map of object -> score *//*from ww w .jav a 2 s. c om*/ @Nonnull public Map<Object, Double> getScores() { return Collections.unmodifiableMap(Maps.transformValues(scores, Score::getScore)); }
From source file:com.nesscomputing.service.discovery.testing.client.MemoryDiscoveryClient.java
private void updateStateOfTheWorld() { Map<String, ConsistentRingGroup> newWorldOrder = Maps .transformValues(Multimaps.index(announcements, GET_SERVICE_NAME).asMap(), BUILD_RING_GROUP); getStateOfTheWorldHolder().setState(newWorldOrder); LOG.trace("Pushed out discovery update, new world order = %s", newWorldOrder); }
From source file:org.sonar.server.computation.component.VisitorsCrawler.java
public Map<ComponentVisitor, Long> getCumulativeDurations() { return ImmutableMap .copyOf(Maps.transformValues(this.visitorCumulativeDurations, VisitorDurationToDuration.INSTANCE)); }
From source file:org.openqa.selenium.remote.internal.JsonToWebElementConverter.java
public Object apply(Object result) { if (result instanceof Collection<?>) { Collection<?> results = (Collection<?>) result; return Lists.newArrayList(Iterables.transform(results, this)); }//from w ww . j ava 2 s . co m if (result instanceof Map<?, ?>) { Map<?, ?> resultAsMap = (Map<?, ?>) result; if (resultAsMap.containsKey("ELEMENT")) { RemoteWebElement element = newRemoteWebElement(); element.setId(String.valueOf(resultAsMap.get("ELEMENT"))); element.setFileDetector(driver.getFileDetector()); return element; } else if (resultAsMap.containsKey("element-6066-11e4-a52e-4f735466cecf")) { RemoteWebElement element = newRemoteWebElement(); element.setId(String.valueOf(resultAsMap.get("element-6066-11e4-a52e-4f735466cecf"))); element.setFileDetector(driver.getFileDetector()); return element; } else { return Maps.transformValues(resultAsMap, this); } } if (result instanceof Number) { if (result instanceof Float || result instanceof Double) { return ((Number) result).doubleValue(); } return ((Number) result).longValue(); } return result; }
From source file:org.locationtech.geogig.model.internal.RocksdbDAGStorageProvider.java
@Override public Map<NodeId, Node> getNodes(final Set<NodeId> nodeIds) { Map<NodeId, DAGNode> dagNodes = nodeStore.getAll(nodeIds); return Maps.transformValues(dagNodes, (dn) -> dn.resolve(treeCache)); }
From source file:org.onosproject.store.primitives.impl.FederatedDistributedPrimitiveCreator.java
@Override public <K, V> AsyncConsistentMap<K, V> newAsyncConsistentMap(String name, Serializer serializer) { checkNotNull(name);/*from w w w. j a v a2s . co m*/ checkNotNull(serializer); Map<PartitionId, AsyncConsistentMap<K, V>> maps = Maps.transformValues(members, partition -> partition.newAsyncConsistentMap(name, serializer)); Hasher<K> hasher = key -> { int hashCode = Hashing.sha256().hashBytes(serializer.encode(key)).asInt(); return sortedMemberPartitionIds.get(Math.abs(hashCode) % members.size()); }; return new PartitionedAsyncConsistentMap<>(name, maps, hasher); }
From source file:co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable.java
@Override public void put(NavigableMap<byte[], NavigableMap<byte[], Long>> updates) { NavigableMap<byte[], NavigableMap<byte[], Update>> convertedUpdates = Maps .newTreeMap(Bytes.BYTES_COMPARATOR); for (NavigableMap.Entry<byte[], NavigableMap<byte[], Long>> entry : updates.entrySet()) { convertedUpdates.put(entry.getKey(), Maps.transformValues(entry.getValue(), Updates.LONG_TO_PUTS)); }/*from w w w . jav a2 s . com*/ InMemoryTableService.merge(tableName, convertedUpdates, System.currentTimeMillis()); }
From source file:org.apache.aurora.scheduler.app.LocalServiceRegistryWithOverrides.java
private Map<String, InetSocketAddress> applyDnsOverrides(Map<String, InetSocketAddress> services) { final InetAddress inetAddress; try {//ww w .j a va2s .c o m inetAddress = InetAddress.getByName(this.zkLocalDnsNameOverride.get()); } catch (UnknownHostException e) { throw new RuntimeException("Failed to resolve address.", e); } return ImmutableMap .copyOf(Maps.transformValues(services, new Function<InetSocketAddress, InetSocketAddress>() { @Override public InetSocketAddress apply(InetSocketAddress input) { return new InetSocketAddress(inetAddress, input.getPort()); } })); }
From source file:io.crate.operation.reference.sys.SysObjectArrayReference.java
@Override public Object[] value() { List<NestedObjectExpression> childImplementations = getChildImplementations(); Object[] values = new Object[childImplementations.size()]; int i = 0;/*from w w w. j ava2 s.c om*/ for (NestedObjectExpression expression : childImplementations) { Map<String, Object> map = Maps.transformValues(expression.getChildImplementations(), new Function<ReferenceImplementation, Object>() { @Nullable @Override public Object apply(@Nullable ReferenceImplementation input) { Object value = input.value(); if (value != null && value instanceof BytesRef) { return ((BytesRef) value).utf8ToString(); } else { return value; } } }); values[i++] = map; } return values; }
From source file:com.twitter.common.stats.NumericStatExporter.java
/** * Creates a new numeric stat exporter that will export to the specified sink. * * @param exportSink Consumes stats.//from w ww .j ava 2s. c o m * @param executor Executor to handle export thread. * @param exportInterval Export period. */ public NumericStatExporter(final Closure<Map<String, ? extends Number>> exportSink, ScheduledExecutorService executor, Amount<Long, Time> exportInterval) { checkNotNull(exportSink); this.executor = checkNotNull(executor); this.exportInterval = checkNotNull(exportInterval); this.exportSink = exportSink; exporter = new Runnable() { @Override public void run() { exportSink.execute( Maps.transformValues(Maps.uniqueIndex(Stats.getNumericVariables(), GET_NAME), READ_STAT)); } }; }