List of usage examples for com.google.common.base Functions forMap
public static <K, V> Function<K, V> forMap(Map<K, ? extends V> map, @Nullable V defaultValue)
From source file:org.grouplens.grapht.solver.DependencySolver.java
/** * Rewrite a dependency graph using the rules in this solver. The accumulated global graph and * back edges are ignored and not modified. * <p>Graph rewrite walks the graph, looking for nodes to rewrite. If the desire that leads * to a node is matched by a trigger binding function, then it is resolved using the binding * functions and replaced with the resulting (merged) node. Rewriting proceeds from the root * down, but does not consider the children of nodes generated by the rewriting process.</p> * * @param graph The graph to rewrite./*w w w. java 2 s . c om*/ * @return A rewritten version of the graph. */ public DAGNode<Component, Dependency> rewrite(DAGNode<Component, Dependency> graph) throws ResolutionException { if (!graph.getLabel().getSatisfaction().getErasedType().equals(Void.TYPE)) { throw new IllegalArgumentException("only full dependency graphs can be rewritten"); } logger.debug("rewriting graph with {} nodes", graph.getReachableNodes().size()); // We proceed in three stages. Map<DAGEdge<Component, Dependency>, DAGEdge<Component, Dependency>> replacementSubtrees = Maps.newHashMap(); walkGraphForReplacements(graph, InjectionContext.singleton(graph.getLabel().getSatisfaction()), replacementSubtrees); DAGNode<Component, Dependency> stage2 = graph.transformEdges(Functions.forMap(replacementSubtrees, null)); logger.debug("merging rewritten graph"); // Now we have a graph (stage2) with rewritten subtrees based on trigger rules // We merge this graph with the original to deduplicate. MergePool<Component, Dependency> pool = MergePool.create(); pool.merge(graph); return pool.merge(stage2); }
From source file:com.eucalyptus.ws.util.HmacUtils.java
private static Function<String, List<String>> forMap(final Map<String, List<String>> values, Function<String, String> keyConversion) { return Functions.compose(Functions.forMap(values, Collections.<String>emptyList()), keyConversion); }
From source file:google.registry.rdap.RdapJsonFormatter.java
/** * Creates a string array of status values; the spec indicates that OK should be listed as * "active"./*from w w w . j a v a 2 s .c o m*/ */ private static ImmutableList<String> makeStatusValueList(ImmutableSet<StatusValue> statusValues) { return FluentIterable.from(statusValues) .transform(Functions.forMap(statusToRdapStatusMap, RdapStatus.OBSCURED)) .transform(new Function<RdapStatus, String>() { @Override public String apply(RdapStatus status) { return status.getDisplayName(); } }).toSortedSet(Ordering.natural()).asList(); }