List of usage examples for com.google.common.collect Maps transformEntries
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap, EntryTransformer<? super K, ? super V1, V2> transformer)
From source file:org.onosproject.store.primitives.impl.DatabaseManager.java
@Activate public void activate() { localNodeId = clusterService.getLocalNode().id(); Map<PartitionId, Set<NodeId>> partitionMap = Maps.newHashMap(); clusterMetadataService.getClusterMetadata().getPartitions().forEach(p -> { partitionMap.put(p.getId(), Sets.newHashSet(p.getMembers())); });//from w w w .java 2s. co m String[] activeNodeUris = partitionMap.values().stream().reduce((s1, s2) -> Sets.union(s1, s2)).get() .stream().map(this::nodeIdToUri).toArray(String[]::new); String localNodeUri = nodeIdToUri(clusterMetadataService.getLocalNode().id()); Protocol protocol = new CopycatCommunicationProtocol(clusterService, clusterCommunicator); ClusterConfig clusterConfig = new ClusterConfig().withProtocol(protocol) .withElectionTimeout(electionTimeoutMillis(activeNodeUris)) .withHeartbeatInterval(heartbeatTimeoutMillis(activeNodeUris)).withMembers(activeNodeUris) .withLocalMember(localNodeUri); CopycatConfig copycatConfig = new CopycatConfig().withName("onos").withClusterConfig(clusterConfig) .withDefaultSerializer(new DatabaseSerializer()).withDefaultExecutor( Executors.newSingleThreadExecutor(new NamedThreadFactory("copycat-coordinator-%d"))); coordinator = new DefaultClusterCoordinator(copycatConfig.resolve()); Function<PartitionId, Log> logFunction = id -> id.asInt() == 0 ? newInMemoryLog() : newPersistentLog(); Map<PartitionId, Database> databases = Maps.transformEntries(partitionMap, (k, v) -> { String[] replicas = v.stream().map(this::nodeIdToUri).toArray(String[]::new); DatabaseConfig config = newDatabaseConfig(String.format("p%s", k), logFunction.apply(k), replicas); return coordinator.<Database>getResource(config.getName(), config.resolve(clusterConfig).withSerializer(copycatConfig.getDefaultSerializer()) .withDefaultExecutor(copycatConfig.getDefaultExecutor())); }); inMemoryDatabase = databases.remove(PartitionId.from(0)); partitionedDatabase = new PartitionedDatabase("onos-store", databases.values()); CompletableFuture<Void> status = coordinator.open().thenCompose(v -> CompletableFuture .allOf(inMemoryDatabase.open(), partitionedDatabase.open()).whenComplete((db, error) -> { if (error != null) { log.error("Failed to initialize database.", error); } else { log.info("Successfully initialized database."); } })); Futures.getUnchecked(status); AsyncConsistentMap<TransactionId, Transaction> transactions = this .<TransactionId, Transaction>consistentMapBuilder().withName("onos-transactions") .withSerializer(Serializer.using(KryoNamespaces.API, MapUpdate.class, MapUpdate.Type.class, Transaction.class, Transaction.State.class)) .buildAsyncMap(); transactionManager = new TransactionManager(partitionedDatabase, transactions); partitionedDatabase.setTransactionManager(transactionManager); log.info("Started"); }
From source file:org.obm.imap.archive.treatment.TreatmentStepdefs.java
private ArrayList<SharedMailbox> usersMapToScopeSharedMailboxList(Map<String, Integer> sharedMailboxes) { return Lists.newArrayList( Maps.transformEntries(sharedMailboxes, new Maps.EntryTransformer<String, Integer, SharedMailbox>() { @Override/*from www. ja v a 2 s . c o m*/ public SharedMailbox transformEntry(String sharedMailbox, Integer id) { return SharedMailbox.builder().name(sharedMailbox).id(id).build(); } }).values()); }
From source file:com.google.devtools.build.lib.profiler.statistics.SkylarkStatistics.java
/** * Build a Map of {@link TasksStatistics} from the given duration maps. *//*from w w w. j av a 2 s.c o m*/ private static Map<String, TasksStatistics> buildTasksStatistics( final Map<String, LongArrayList> durationsMap) { return Maps.transformEntries(durationsMap, new EntryTransformer<String, LongArrayList, TasksStatistics>() { @Override public TasksStatistics transformEntry(String function, LongArrayList durations) { return TasksStatistics.create(function, durations); } }); }
From source file:org.kie.workbench.common.screens.projecteditor.client.build.BuildExecutor.java
private void buildDeployWithMultipleServerTemplatesAvailable(Collection<ServerTemplate> serverTemplates, String defaultContainerId, String defaultContainerAlias, boolean defaultStartContainer) { final Map<String, ServerTemplate> serverTemplatesIds = Maps.uniqueIndex(serverTemplates, s -> s.getId()); final Map<String, Set<String>> containerNames = Maps.transformEntries(serverTemplatesIds, (id, server) -> FluentIterable.from(server.getContainersSpec()).transform(c -> c.getContainerName()) .toSet());/*from w ww . ja v a 2 s . c o m*/ deploymentScreenPopupView.addServerTemplates( FluentIterable.from(serverTemplatesIds.keySet()).toSortedSet(String.CASE_INSENSITIVE_ORDER)); deploymentScreenPopupView.setValidateExistingContainerCallback(containerName -> FluentIterable .from(containerNames.get(deploymentScreenPopupView.getServerTemplate())).contains(containerName)); deploymentScreenPopupView.setContainerId(defaultContainerId); deploymentScreenPopupView.setContainerAlias(defaultContainerAlias); deploymentScreenPopupView.setStartContainer(defaultStartContainer); deploymentScreenPopupView.configure(() -> { final String containerId = deploymentScreenPopupView.getContainerId(); final String containerAlias = deploymentScreenPopupView.getContainerAlias(); final String serverTemplate = deploymentScreenPopupView.getServerTemplate(); final boolean startContainer = deploymentScreenPopupView.getStartContainer(); getSafeExecutedCommand(getBuildDeployProvisionCommand(DeploymentMode.VALIDATED, containerId, containerAlias, serverTemplate, startContainer)).execute(); deploymentScreenPopupView.hide(); }); deploymentScreenPopupView.show(); }
From source file:google.registry.tools.server.ListObjectsAction.java
/** * Computes the column widths of the given table of strings column-keyed by strings and returns * them as a map from column key name to integer width. The column width is defined as the max * length of any string in that column, including the name of the column. *///from w ww . j a v a 2 s . com private static ImmutableMap<String, Integer> computeColumnWidths(ImmutableTable<?, String, String> data, final boolean includingHeader) { return ImmutableMap.copyOf(Maps.transformEntries(data.columnMap(), new Maps.EntryTransformer<String, Map<?, String>, Integer>() { @Override public Integer transformEntry(String columnName, Map<?, String> columnValues) { // Return the length of the longest string in this column (including the column name). return Ordering.natural() .max(Iterables.transform( Iterables.concat(ImmutableList.of(includingHeader ? columnName : ""), columnValues.values()), new Function<String, Integer>() { @Override public Integer apply(String value) { return value.length(); } })); } })); }
From source file:io.atomix.core.election.impl.DefaultLeaderElectorService.java
@Override public Map<String, Leadership<byte[]>> getLeaderships() { Map<String, Leadership<byte[]>> result = new HashMap<>(); try {/*from w ww .j ava 2s .c om*/ result.putAll(Maps.transformEntries(elections, (k, v) -> leadership(k))); return result; } catch (Exception e) { getLogger().error("State machine operation failed", e); throw Throwables.propagate(e); } }
From source file:org.obm.imap.archive.treatment.TreatmentStepdefs.java
private ArrayList<ScopeUser> usersMapToScopeUserList(Map<String, String> users) { return Lists//from w w w.j av a 2 s . com .newArrayList(Maps.transformEntries(users, new Maps.EntryTransformer<String, String, ScopeUser>() { @Override public ScopeUser transformEntry(String user, String extId) { return ScopeUser.builder().login(user).id(UserExtId.valueOf(extId)).build(); } }).values()); }
From source file:com.nesscomputing.migratory.metadata.MetadataManager.java
public Map<String, Integer> retrieveCurrentVersions(final MigratoryOption... options) { return Maps.transformEntries(getStatus(null, options), new EntryTransformer<String, MetadataInfo, Integer>() { @Override/*from w ww . ja v a 2s . c o m*/ public Integer transformEntry(final String name, final MetadataInfo info) { return info.getEndVersion(); } }); }
From source file:com.netflix.astyanax.thrift.AbstractThriftMutationBatchImpl.java
@Override public Map<ByteBuffer, Set<String>> getRowKeys() { return Maps.transformEntries(mutationMap, new EntryTransformer<ByteBuffer, Map<String, List<Mutation>>, Set<String>>() { @Override/*from w w w. j av a 2 s . c om*/ public Set<String> transformEntry(ByteBuffer key, Map<String, List<Mutation>> value) { return value.keySet(); } }); }
From source file:com.opower.rest.client.generator.hystrix.HystrixClient.java
private Map<Method, HystrixCommand.Setter> assembleHystrixCommandSetters() { return Maps.transformEntries(this.commandKeyMap, new Maps.EntryTransformer<Method, HystrixCommandKey, HystrixCommand.Setter>() { @Override//from ww w. j ava 2 s . c o m public HystrixCommand.Setter transformEntry(Method method, HystrixCommandKey value) { HystrixClient<T, B> builder = HystrixClient.this; HystrixCommand.Setter setter = HystrixCommand.Setter.withGroupKey(builder.groupKey) .andCommandKey(value) .andCommandPropertiesDefaults(builder.commandPropertiesMap.get(method)) .andThreadPoolPropertiesDefaults(builder.threadPoolPropertiesMap.get(method)); if (builder.threadPoolKeysMap.containsKey(method)) { setter.andThreadPoolKey(builder.threadPoolKeysMap.get(method)); } return setter; } }); }