Java Code Examples for com.google.common.collect.Maps#transformEntries()
The following examples show how to use
com.google.common.collect.Maps#transformEntries() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryConfigs.java From docker-client with Apache License 2.0 | 6 votes |
@JsonCreator public static RegistryConfigs create(final Map<String, RegistryAuth> configs) { if (configs == null) { return empty(); } // need to add serverAddress to each RegistryAuth instance; it is not available when // Jackson is deserializing the RegistryAuth field final Map<String, RegistryAuth> transformedMap = Maps.transformEntries(configs, new Maps.EntryTransformer<String, RegistryAuth, RegistryAuth>() { @Override public RegistryAuth transformEntry(final String key, final RegistryAuth value) { if (value == null) { return null; } if (value.serverAddress() == null) { return value.toBuilder() .serverAddress(key) .build(); } return value; } }); return builder().configs(transformedMap).build(); }
Example 2
Source File: AbstractTwillController.java From twill with Apache License 2.0 | 6 votes |
@Override public final ListenableFuture<Set<String>> restartInstances( Map<String, ? extends Set<Integer>> runnableToInstanceIds) { Map<String, String> runnableToStringInstanceIds = Maps.transformEntries(runnableToInstanceIds, new Maps.EntryTransformer<String, Set<Integer>, String>() { @Override public String transformEntry(String runnableName, Set<Integer> instanceIds) { validateInstanceIds(runnableName, instanceIds); return GSON.toJson(instanceIds, new TypeToken<Set<Integer>>() {}.getType()); } }); Command updateStateCommand = Command.Builder.of(Constants.RESTART_RUNNABLES_INSTANCES) .addOptions(runnableToStringInstanceIds) .build(); Message message = SystemMessages.updateRunnablesInstances(updateStateCommand); return sendMessage(message, runnableToInstanceIds.keySet()); }
Example 3
Source File: TimedTransitionProperty.java From nomulus with Apache License 2.0 | 6 votes |
/** * Converts the provided value map into the equivalent transition map, using transition objects * of the given TimedTransition subclass. The value map must be sorted according to the natural * ordering of its DateTime keys, and keys cannot be earlier than START_OF_TIME. */ // NB: The Class<T> parameter could be eliminated by getting the class via reflection, but then // the callsite cannot infer T, so unless you explicitly call this as .<V, T>fromValueMap() it // will default to using just TimedTransition<V>, which fails at runtime. private static <V, T extends TimedTransition<V>> NavigableMap<DateTime, T> makeTransitionMap( ImmutableSortedMap<DateTime, V> valueMap, final Class<T> timedTransitionSubclass) { checkArgument( Ordering.natural().equals(valueMap.comparator()), "Timed transition value map must have transition time keys in chronological order"); return Maps.transformEntries( valueMap, (DateTime transitionTime, V value) -> { checkArgument( !transitionTime.isBefore(START_OF_TIME), "Timed transition times cannot be earlier than START_OF_TIME / Unix Epoch"); T subclass = TypeUtils.instantiate(timedTransitionSubclass); ((TimedTransition<V>) subclass).transitionTime = transitionTime; subclass.setValue(value); return subclass; }); }
Example 4
Source File: HintsPollerResult.java From emodb with Apache License 2.0 | 5 votes |
private Map<InetAddress, Long> getHostsWithHints(Map<InetAddress, Optional<Long>> hintsInfo) { return Maps.transformEntries( Maps.filterEntries(hintsInfo, new Predicate<Map.Entry<InetAddress, Optional<Long>>>() { @Override public boolean apply(Map.Entry<InetAddress, Optional<Long>> input) { return input.getValue().isPresent(); } }), new Maps.EntryTransformer<InetAddress, Optional<Long>, Long>() { @Override public Long transformEntry(InetAddress key, Optional<Long> value) { return value.get(); } }); }
Example 5
Source File: NotifyingHelper.java From bazel with Apache License 2.0 | 5 votes |
@Override public Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch( @Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) throws InterruptedException { for (SkyKey key : keys) { notifyingHelper.graphListener.accept(key, EventType.CREATE_IF_ABSENT, Order.BEFORE, null); } return Maps.transformEntries( delegate.createIfAbsentBatch(requestor, reason, keys), notifyingHelper.wrapEntry); }
Example 6
Source File: NotifyingHelper.java From bazel with Apache License 2.0 | 5 votes |
@Override public Map<SkyKey, ? extends NodeEntry> getBatch( @Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys) throws InterruptedException { for (SkyKey key : keys) { notifyingHelper.graphListener.accept(key, EventType.GET_BATCH, Order.BEFORE, reason); } return Maps.transformEntries( delegate.getBatch(requestor, reason, keys), notifyingHelper.wrapEntry); }
Example 7
Source File: ObjectStorageBlobConfigurationTest.java From james-project with Apache License 2.0 | 5 votes |
@ParameterizedTest @ArgumentsSource(RequiredParameters.class) void shouldThrowWhenRequiredParameterEmpty(String toEmpty) { Map<String, Object> configurationWithFilteredKey = Maps.transformEntries(VALID_CONFIGURATION, (key, value) -> { if (toEmpty.equals(key)) { return ""; } else { return value; } }); assertThat(configurationWithFilteredKey).containsEntry(toEmpty, ""); assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(new MapConfiguration(configurationWithFilteredKey))) .isInstanceOf(ConfigurationException.class); }
Example 8
Source File: KafkaMetadataUtil.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * @param brokers in multiple clusters, keyed by cluster id * @param topic * @return Get the partition metadata list for the specific topic via the brokers * null if topic is not found */ public static Map<String, List<PartitionMetadata>> getPartitionsForTopic(SetMultimap<String, String> brokers, final String topic) { return Maps.transformEntries(brokers.asMap(), new EntryTransformer<String, Collection<String>, List<PartitionMetadata>>() { @Override public List<PartitionMetadata> transformEntry(String key, Collection<String> bs) { return getPartitionsForTopic(new HashSet<String>(bs), topic); } }); }
Example 9
Source File: DasRemoteDelegate.java From das with Apache License 2.0 | 5 votes |
public static EntityMeta extract(Class clz) { if(clz == Map.class) { return new EntityMeta().setMapType(true); } else if(isSimpleType(clz)) { return null; } com.ppdai.das.client.delegate.EntityMeta meta = EntityMetaManager.extract(clz); Map<String, String> fieldMap = Maps.transformEntries(meta.getFieldMap(), (key, value) -> value.getName()); Map<String, ColumnMeta> metaMap = Maps.transformEntries(meta.getMetaMap(), (key, value) -> { return new ColumnMeta() .setName(value.getName()) .setType(value.getType() == null ? null : value.getType().getName()) .setAutoIncremental(value.isAutoIncremental()) .setPrimaryKey(value.isPrimaryKey()) .setInsertable(value.isInsertable()) .setUpdatable(value.isUpdatable()) .setVersion(value.isVersion()); }); List<String> columnTypes = Arrays.stream(meta.getColumnTypes()).map( t -> t == null ? null : t.getName() ).collect(Collectors.toList()); return new EntityMeta() .setAutoIncremental(meta.isAutoIncremental()) .setColumnNames(newArrayList(meta.getColumnNames())) .setIdentityField(meta.getIdentityField() == null ? null : meta.getIdentityField().getName()) .setInsertableColumnNames(newArrayList(meta.getInsertableColumnNames())) .setPrimaryKeyNames(newArrayList(meta.getPrimaryKeyNames())) .setTableName(meta.getTableName()) .setVersionColumn(meta.getVersionColumn()) .setUpdatableColumnNames(newArrayList(meta.getUpdatableColumnNames())) .setColumnTypes(columnTypes) .setFieldMap(fieldMap) .setMetaMap(new HashMap<>(metaMap)); }
Example 10
Source File: SystemMessages.java From twill with Apache License 2.0 | 5 votes |
private static Map<String, String> convertLogEntryToString(Map<String, LogEntry.Level> logLevels) { return Maps.transformEntries(logLevels, new Maps.EntryTransformer<String, LogEntry.Level, String>() { @Override public String transformEntry(String loggerName, LogEntry.Level level) { return level == null ? null : level.name(); } }); }
Example 11
Source File: YarnTwillPreparer.java From twill with Apache License 2.0 | 5 votes |
private TwillRuntimeSpecification saveSpecification(TwillSpecification spec, Path targetFile) throws IOException { final Multimap<String, LocalFile> runnableLocalFiles = populateRunnableLocalFiles(spec); // Rewrite LocalFiles inside twillSpec Map<String, RuntimeSpecification> runtimeSpec = Maps.transformEntries( spec.getRunnables(), new Maps.EntryTransformer<String, RuntimeSpecification, RuntimeSpecification>() { @Override public RuntimeSpecification transformEntry(String key, RuntimeSpecification value) { return new DefaultRuntimeSpecification(value.getName(), value.getRunnableSpecification(), value.getResourceSpecification(), runnableLocalFiles.get(key)); } }); // Serialize into a local temp file. LOG.debug("Creating {}", targetFile); try (Writer writer = Files.newBufferedWriter(targetFile, StandardCharsets.UTF_8)) { EventHandlerSpecification eventHandler = spec.getEventHandler(); if (eventHandler == null) { eventHandler = new LogOnlyEventHandler().configure(); } TwillSpecification newTwillSpec = new DefaultTwillSpecification(spec.getName(), runtimeSpec, spec.getOrders(), spec.getPlacementPolicies(), eventHandler); Map<String, String> configMap = Maps.newHashMap(); for (Map.Entry<String, String> entry : config) { if (entry.getKey().startsWith("twill.")) { configMap.put(entry.getKey(), entry.getValue()); } } TwillRuntimeSpecification twillRuntimeSpec = new TwillRuntimeSpecification( newTwillSpec, appLocation.getLocationFactory().getHomeLocation().getName(), appLocation.toURI(), zkConnectString, runId, twillSpec.getName(), config.get(YarnConfiguration.RM_SCHEDULER_ADDRESS), logLevels, maxRetries, configMap, runnableConfigs); TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec, writer); LOG.debug("Done {}", targetFile); return twillRuntimeSpec; } }
Example 12
Source File: AnnotationProxy.java From ArchUnit with Apache License 2.0 | 5 votes |
private Map<String, Object> unwrapProxiedProperties() { return Maps.transformEntries(toProxy.getProperties(), new Maps.EntryTransformer<String, Object, Object>() { @Override public Object transformEntry(String key, Object value) { Class<?> returnType = getDeclaredMethod(key).getReturnType(); return conversions.convertIfNecessary(value, returnType); } }); }
Example 13
Source File: TestRestfulApi.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
/** * Test restful api is working. * @param map request parameters * @return map result */ @POST @Path("/call") @Consumes(MediaType.APPLICATION_JSON) public Map<String, String> call(final Map<String, String> map) { caller.call(map.get("string")); caller.call(Integer.valueOf(map.get("integer"))); return Maps.transformEntries(map, new Maps.EntryTransformer<String, String, String>() { @Override public String transformEntry(final String key, final String value) { return value + "_processed"; } }); }
Example 14
Source File: KafkaPosition.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public Map<Integer, IPartitionPosition> getPartitionPositions() { return Maps.transformEntries(partitionOffsetMap, new EntryTransformer<Integer, Long, IPartitionPosition>() { @Override public IPartitionPosition transformEntry(@Nullable Integer key, @Nullable Long value) { return new KafkaPartitionPosition(key, value); } }); }
Example 15
Source File: DasServer.java From das with Apache License 2.0 | 5 votes |
DasDiagInfo diagInfo2Hints(DasDiagnose dasDiagnose) { if (dasDiagnose == null) { return null; } Map<String, String> diagnoseInfoMap = Maps.transformEntries(dasDiagnose.getDiagnoseInfoMap(), (key, value) -> Objects.toString(value, "")); List<DasDiagInfo> subs = dasDiagnose.getChildDiagnoses().stream().map(d -> diagInfo2Hints(d)).collect(Collectors.toList()); return new DasDiagInfo() .setName(dasDiagnose.getName()) .setDiagnoseInfoMap(diagnoseInfoMap) .setSpaceLevel(dasDiagnose.getSpaceLevel()) .setEntries(subs); }
Example 16
Source File: RedshiftConnectionConfigTest.java From digdag with Apache License 2.0 | 4 votes |
@Before public void setUp() throws IOException { { // This map contains only minimum custom values to test default values Map<String, String> defaultConfigValues = ImmutableMap.of( "host", "foobar0.org", "user", "user0", "database", "database0" ); this.connConfigWithDefaultValue = RedshiftConnectionConfig.configure( key -> Optional.absent(), jdbcOpTestHelper.createConfig(defaultConfigValues) ); // This map contains values that are all "ignore" so that we can detect if this value is used unexpectedly Map<String, String> ignoredDefaultConfigValues = Maps.transformValues(defaultConfigValues, key -> "ignore"); this.connConfigWithDefaultValueFromSecrets = RedshiftConnectionConfig.configure( key -> Optional.fromNullable(defaultConfigValues.get(key)), jdbcOpTestHelper.createConfig(ignoredDefaultConfigValues) ); } // This map contains whole custom values to test if custom values are used expectedly Map<String, String> customConfigValues = ImmutableMap.<String, String>builder(). put("host", "foobar1.org"). put("port", "6543"). put("user", "user1"). put("password", "password1"). put("database", "database1"). put("ssl", "true"). put("connect_timeout", "15s"). put("socket_timeout", "12 m"). put("schema", "myschema").build(); { this.connConfigWithCustomValue = RedshiftConnectionConfig.configure( key -> key.equals("password") ? Optional.of("password1") : Optional.absent(), jdbcOpTestHelper.createConfig(customConfigValues) ); // This map contains values that are all "ignore" so that we can detect if this value is used unexpectedly ImmutableList<String> itemsFromOnlyConfig = ImmutableList.of("connect_timeout", "socket_timeout"); Map<String, String> ignoredCustomConfigValues = Maps.transformEntries(customConfigValues, (key, value) -> itemsFromOnlyConfig.contains(key) ? value : "ignore"); this.connConfigWithCustomValueFromSecrets = RedshiftConnectionConfig.configure( key -> Optional.fromNullable(customConfigValues.get(key)), jdbcOpTestHelper.createConfig(ignoredCustomConfigValues) ); } { Map<String, String> configValuesWithOverriddenPassword = ImmutableMap.<String, String>builder() .putAll(customConfigValues) .put("another_db_password", "password2") .build(); Map<String, String> configValuesUsingOverriddenPassword = ImmutableMap.<String, String>builder() .putAll(customConfigValues) .put("password_override", "another_db_password") .build(); this.connConfigWithOverriddenPassword = RedshiftConnectionConfig.configure( key -> Optional.fromNullable(configValuesWithOverriddenPassword.get(key)), jdbcOpTestHelper.createConfig(configValuesUsingOverriddenPassword) ); } }
Example 17
Source File: MemoryExperimentsCache.java From alchemy with MIT License | 4 votes |
@Override public Map<String, Experiment> getActiveExperiments() { final Map<String, Experiment> filtered = Maps.filterEntries(db, ACTIVE_FILTER); return Maps.transformEntries(filtered, EXPERIMENT_COPY_TRANSFORMER); }