Java Code Examples for com.google.common.collect.Maps#transformValues()

The following examples show how to use com.google.common.collect.Maps#transformValues() . 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: ExampleMarketDataBuilder.java    From Strata with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: AtlasJanusGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ItemStateModel.java    From OpenModsLib with MIT License 6 votes vote down vote up
@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);
}
 
Example 4
Source File: ArrayField.java    From drift with Apache License 2.0 5 votes vote down vote up
public Map<Short, List<Boolean>> getMapBooleanList()
{
    if (mapBooleanArray == null) {
        return null;
    }
    return Maps.transformValues(mapBooleanArray, Booleans::asList);
}
 
Example 5
Source File: ArrayField.java    From drift with Apache License 2.0 5 votes vote down vote up
public Map<Short, List<Long>> getMapLongList()
{
    if (mapLongArray == null) {
        return null;
    }
    return Maps.transformValues(this.mapLongArray, Longs::asList);
}
 
Example 6
Source File: JsonValues.java    From DCMonitor with MIT License 5 votes vote down vote up
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;
        }
      }
    )
  );
}
 
Example 7
Source File: JsonToWebElementConverter.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: PhoenixRuntime.java    From phoenix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: AbstractJavaNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: Producers.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
public static <K, T> Map<K, T> produce(Map<K, Producer<T>> map) {
    return Maps.transformValues(map, Producer::get);
}
 
Example 11
Source File: RedshiftConnectionConfigTest.java    From digdag with Apache License 2.0 4 votes vote down vote up
@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 12
Source File: ValueWrappingMap.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void putAll(Map<? extends K, ? extends V> map) {
	super.putAll(Maps.transformValues(map, (v) -> wrapper.apply(v)));
}
 
Example 13
Source File: MysqlUpdateMutation.java    From SpinalTap with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static Map<String, Serializable> asColumnValues(@NonNull final Row row) {
  return Maps.transformValues(row.getColumns(), Column::getValue);
}
 
Example 14
Source File: FulgoraVertexMemory.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public Map<Long,EntryList> retrievePartitionAggregates() {
    for (PartitionVertexAggregate agg : partitionVertices.values()) agg.completeIteration();
    return Maps.transformValues(partitionVertices, s -> s.getLoadedProperties());
}
 
Example 15
Source File: PgConnectionConfigTest.java    From digdag with Apache License 2.0 4 votes vote down vote up
@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)
    );
}
 
Example 16
Source File: ModuleNamespaceContext.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
Map<String, String> prefixesAndNamespaces() {
    return Maps.transformValues(prefixToModule, module -> module.localQNameModule().getNamespace().toString());
}
 
Example 17
Source File: JavaTypeTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public SortedMap<Integer, String> tokenListWithPos(final char[] code) {
	return Maps.transformValues(fullTokenListWithPos(code),
			FullToken.TOKEN_NAME_CONVERTER);
}
 
Example 18
Source File: BrooklynComponentTemplateResolver.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected Map<?, ?> transformSpecialFlags(Map<?, ?> flag) {
    return Maps.transformValues(flag, this);
}
 
Example 19
Source File: KeyValueAggregator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Map<K, Value<V>> asTransformedMap(Function<Vector<V>, Value<V>> function){
	return Maps.transformValues(this.map, function);
}
 
Example 20
Source File: NodeDiscovery.java    From curator-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}