下面列出了com.google.common.collect.Maps#transformValues ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets all rates curves.
*
* @return the map of all rates curves
*/
public SortedMap<LocalDate, RatesCurveGroup> loadAllRatesCurves() {
if (!subdirectoryExists(CURVES_DIR)) {
throw new IllegalArgumentException("No rates curves directory found");
}
ResourceLocator curveGroupsResource = getResource(CURVES_DIR, CURVES_GROUPS_FILE);
if (curveGroupsResource == null) {
throw new IllegalArgumentException(Messages.format(
"Unable to load rates curves: curve groups file not found at {}/{}", CURVES_DIR, CURVES_GROUPS_FILE));
}
ResourceLocator curveSettingsResource = getResource(CURVES_DIR, CURVES_SETTINGS_FILE);
if (curveSettingsResource == null) {
throw new IllegalArgumentException(Messages.format(
"Unable to load rates curves: curve settings file not found at {}/{}", CURVES_DIR, CURVES_SETTINGS_FILE));
}
ListMultimap<LocalDate, RatesCurveGroup> curveGroups =
RatesCurvesCsvLoader.loadAllDates(curveGroupsResource, curveSettingsResource, getRatesCurvesResources());
// There is only one curve group in the market data file so this will always succeed
Map<LocalDate, RatesCurveGroup> curveGroupMap = Maps.transformValues(curveGroups.asMap(), groups -> groups.iterator().next());
return new TreeMap<>(curveGroupMap);
}
@Override
public IBakedModel bake(IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
final IModel defaultModel;
if (this.defaultModel.isPresent()) {
defaultModel = getModel(this.defaultModel.get());
} else if (!this.stateModels.isEmpty()) {
final ResourceLocation first = this.stateModels.values().iterator().next();
defaultModel = getModel(first);
} else {
defaultModel = ModelLoaderRegistry.getMissingModel();
}
final IBakedModel bakedDefaultModel = defaultModel.bake(defaultModel.getDefaultState(), format, bakedTextureGetter);
final Map<State, IBakedModel> bakedStateModels = Maps.transformValues(stateModels, input -> {
final IModel model = getModel(input);
return model.bake(model.getDefaultState(), format, bakedTextureGetter);
});
return new ItemStateOverrideList(bakedStateModels).wrapModel(bakedDefaultModel);
}
private Object convertGremlinValue(Object rawValue) {
if (rawValue instanceof Vertex) {
return GraphDbObjectFactory.createVertex(this, (Vertex) rawValue);
} else if (rawValue instanceof Edge) {
return GraphDbObjectFactory.createEdge(this, (Edge) rawValue);
} else if (rawValue instanceof Map) {
Map<String, Object> rowValue = (Map<String, Object>) rawValue;
return Maps.transformValues(rowValue, GREMLIN_VALUE_CONVERSION_FUNCTION);
} else if (rawValue instanceof ImmutablePath) {
ImmutablePath path = (ImmutablePath) rawValue;
return convertGremlinValue(path.objects());
} else if (rawValue instanceof List) {
return Lists.transform((List) rawValue, GREMLIN_VALUE_CONVERSION_FUNCTION);
} else if (rawValue instanceof Collection) {
throw new UnsupportedOperationException("Unhandled collection type: " + rawValue.getClass());
}
return rawValue;
}
private static Map<String, Map<String, Long>> transformMetrics(Map<String, Map<MetricType, Long>> metricMap) {
Function<Map<MetricType, Long>, Map<String, Long>> func = new Function<Map<MetricType, Long>, Map<String, Long>>() {
@Override
public Map<String, Long> apply(Map<MetricType, Long> map) {
return createMetricMap(map);
}
};
return Maps.transformValues(metricMap, func);
}
public Map<Short, List<Long>> getMapLongList()
{
if (mapLongArray == null) {
return null;
}
return Maps.transformValues(this.mapLongArray, Longs::asList);
}
@Override
public Object apply(Object result) {
if (result instanceof Collection<?>) {
Collection<?> results = (Collection<?>) result;
return Lists.newArrayList(Iterables.transform(results, this));
}
if (result instanceof Map<?, ?>) {
Map<?, ?> resultAsMap = (Map<?, ?>) result;
String elementKey = getElementKey(resultAsMap);
if (null != elementKey) {
RemoteWebElement element = newRemoteWebElement();
element.setId(String.valueOf(resultAsMap.get(elementKey)));
return element;
} else {
return Maps.transformValues(resultAsMap, this);
}
}
if (result instanceof RemoteWebElement) {
return setOwner((RemoteWebElement) result);
}
if (result instanceof Number) {
if (result instanceof Float || result instanceof Double) {
return ((Number) result).doubleValue();
}
return ((Number) result).longValue();
}
return result;
}
public final List<TokenNameBinding> getNameBindings(final ASTNode node,
final File file) throws IOException {
final Set<Set<ASTNode>> nodeBindings = getNameBindings(node);
final SortedMap<Integer, String> tokenPositions = Maps.transformValues(
tokenizer.tokenListWithPos(file),
FullToken.TOKEN_NAME_CONVERTER);
return getTokenBindings(tokenPositions, nodeBindings);
}
public static <T> JsonValues of(Map<String, T> rawValues) {
return new JsonValues(
Maps.transformValues(
rawValues, new Function<T, Object>() {
@Override
public Object apply(T input) {
return (Object) input;
}
}
)
);
}
public Map<Short, List<Boolean>> getMapBooleanList()
{
if (mapBooleanArray == null) {
return null;
}
return Maps.transformValues(mapBooleanArray, Booleans::asList);
}
@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)
);
}
}
@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 = PgConnectionConfig.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 = PgConnectionConfig.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 = PgConnectionConfig.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
Map<String, String> ignoredCustomConfigValues = Maps.transformValues(customConfigValues, key -> "ignore");
this.connConfigWithCustomValueFromSecrets = PgConnectionConfig.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 = PgConnectionConfig.configure(
key -> Optional.fromNullable(configValuesWithOverriddenPassword.get(key)),
jdbcOpTestHelper.createConfig(configValuesUsingOverriddenPassword)
);
}
protected Map<K, Value<V>> asTransformedMap(Function<Vector<V>, Value<V>> function){
return Maps.transformValues(this.map, function);
}
protected Map<?, ?> transformSpecialFlags(Map<?, ?> flag) {
return Maps.transformValues(flag, this);
}
@Override
public SortedMap<Integer, String> tokenListWithPos(final char[] code) {
return Maps.transformValues(fullTokenListWithPos(code),
FullToken.TOKEN_NAME_CONVERTER);
}
Map<String, String> prefixesAndNamespaces() {
return Maps.transformValues(prefixToModule, module -> module.localQNameModule().getNamespace().toString());
}
public static <K, T> Map<K, T> produce(Map<K, Producer<T>> map) {
return Maps.transformValues(map, Producer::get);
}
public Map<Long,EntryList> retrievePartitionAggregates() {
for (PartitionVertexAggregate agg : partitionVertices.values()) agg.completeIteration();
return Maps.transformValues(partitionVertices, s -> s.getLoadedProperties());
}
@VisibleForTesting
static Map<String, Serializable> asColumnValues(@NonNull final Row row) {
return Maps.transformValues(row.getColumns(), Column::getValue);
}
@Override
public void putAll(Map<? extends K, ? extends V> map) {
super.putAll(Maps.transformValues(map, (v) -> wrapper.apply(v)));
}
/**
* Retrieve the available nodes.
*
* @return The available nodes.
*/
public Map<String, T> getNodes() {
return Maps.transformValues(Collections.unmodifiableMap(_nodes), input -> (input != null) ? input.orElse(null) : null);
}