/** Returns an immutable copy of {@code graph}. */ public static <N> ImmutableGraph<N> copyOf(Graph<N> graph) { return (graph instanceof ImmutableGraph) ? (ImmutableGraph<N>) graph : new ImmutableGraph<N>( new ConfigurableValueGraph<N, Presence>( GraphBuilder.from(graph), getNodeConnections(graph), graph.edges().size())); }
private static <N> ImmutableMap<N, GraphConnections<N, Presence>> getNodeConnections( Graph<N> graph) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the graph's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, GraphConnections<N, Presence>> nodeConnections = ImmutableMap.builder(); for (N node : graph.nodes()) { nodeConnections.put(node, connectionsOf(graph, node)); } return nodeConnections.build(); }
InferredNullability(Graph<InferenceVariable> constraints) { this.constraintGraph = ImmutableGraph.copyOf(constraints); }
@Override public ImmutableGraph<N> asGraph() { return new ImmutableGraph<N>(this); // safe because the view is effectively immutable }
/** Get inferred nullness qualifier for an expression, if possible. */ public Optional<Nullness> getExprNullness(ExpressionTree exprTree) { InferenceVariable iv = TypeArgInferenceVar.create(ImmutableList.of(), exprTree); return constraintGraph.nodes().contains(iv) ? getNullness(iv) : Optional.empty(); }
@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { ImmutableNetwork<Node, DependencyEdge> dependencyGraph = nonCycleBreakingDependencyGraph(bindingGraph); // Check each endpoint pair only once, no matter how many parallel edges connect them. Set<EndpointPair<Node>> dependencyEndpointPairs = dependencyGraph.asGraph().edges(); Set<EndpointPair<Node>> visited = newHashSetWithExpectedSize(dependencyEndpointPairs.size()); for (EndpointPair<Node> endpointPair : dependencyEndpointPairs) { cycleContainingEndpointPair(endpointPair, dependencyGraph, visited) .ifPresent(cycle -> reportCycle(cycle, bindingGraph, diagnosticReporter)); } }
@Override public ImmutableGraph<N> asGraph() { return new ImmutableGraph<N>(this); // safe because the view is effectively immutable }
/** * Get inferred nullness qualifiers for method-generic type variables at a callsite. When * inference is not possible for a given type variable, that type variable is not included in the * resulting map. */ public ImmutableMap<TypeVariableSymbol, Nullness> getNullnessGenerics( MethodInvocationTree callsite) { ImmutableMap.Builder<TypeVariableSymbol, Nullness> result = ImmutableMap.builder(); for (TypeVariableSymbol tvs : TreeInfo.symbol((JCTree) callsite.getMethodSelect()).getTypeParameters()) { InferenceVariable iv = TypeVariableInferenceVar.create(tvs, callsite); if (constraintGraph.nodes().contains(iv)) { getNullness(iv).ifPresent(nullness -> result.put(tvs, nullness)); } } return result.build(); }
/** * Returns an empty graph (immutable) initialized with all properties queryable from {@code graph}. * * @param graph The graph to use as template for the created graph * @param <N> The class of the nodes * @return an empty graph * @see GraphBuilder#from(Graph) */ public static <N> ImmutableGraph<N> emptyGraph(Graph<N> graph) { return ImmutableGraph.copyOf(GraphBuilder.from(graph).build()); }
/** Returns an immutable copy of {@code graph}. */ public static <N> ImmutableGraph<N> copyOf(Graph<N> graph) { return (graph instanceof ImmutableGraph) ? (ImmutableGraph<N>) graph : new ImmutableGraph<N>( new ConfigurableValueGraph<N, Presence>( GraphBuilder.from(graph), getNodeConnections(graph), graph.edges().size())); }
@Override public ImmutableGraph<N> asGraph() { return new ImmutableGraph<N>(this); // safe because the view is effectively immutable }
private static <N> ImmutableMap<N, GraphConnections<N, Presence>> getNodeConnections( Graph<N> graph) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the graph's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, GraphConnections<N, Presence>> nodeConnections = ImmutableMap.builder(); for (N node : graph.nodes()) { nodeConnections.put(node, connectionsOf(graph, node)); } return nodeConnections.build(); }
/** Get inferred nullness qualifier for an expression, if possible. */ public Optional<Nullness> getExprNullness(ExpressionTree exprTree) { InferenceVariable iv = TypeArgInferenceVar.create(ImmutableList.of(), exprTree); return constraintGraph.nodes().contains(iv) ? getUpperBound(iv) : Optional.empty(); }
/** Returns an immutable copy of {@code graph}. */ public static <N> ImmutableGraph<N> copyOf(Graph<N> graph) { return (graph instanceof ImmutableGraph) ? (ImmutableGraph<N>) graph : new ImmutableGraph<N>( new ConfigurableValueGraph<N, Presence>( GraphBuilder.from(graph), getNodeConnections(graph), graph.edges().size())); }
@Override public ImmutableGraph<N> asGraph() { return new ImmutableGraph<N>(super.asGraph()); // safe because the view is effectively immutable }
private static <N> ImmutableMap<N, GraphConnections<N, Presence>> getNodeConnections( Graph<N> graph) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the graph's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, GraphConnections<N, Presence>> nodeConnections = ImmutableMap.builder(); for (N node : graph.nodes()) { nodeConnections.put(node, connectionsOf(graph, node)); } return nodeConnections.build(); }
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) { final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entity); final StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class); streamEntity.outputs().stream() .map(valueReference -> valueReference.asString(parameters)) .map(ModelId::of) .map(modelId -> EntityDescriptor.create(modelId, ModelTypes.OUTPUT_V1)) .map(entities::get) .filter(Objects::nonNull) .forEach(outputEntity -> mutableGraph.putEdge(entity, outputEntity)); return ImmutableGraph.copyOf(mutableGraph); } }
/** Returns an immutable copy of {@code graph}. */ public static <N> ImmutableGraph<N> copyOf(Graph<N> graph) { return (graph instanceof ImmutableGraph) ? (ImmutableGraph<N>) graph : new ImmutableGraph<N>( new ConfigurableValueGraph<N, Presence>( GraphBuilder.from(graph), getNodeConnections(graph), graph.edges().size())); }
@Override public ImmutableGraph<N> asGraph() { return new ImmutableGraph<N>(super.asGraph()); // safe because the view is effectively immutable }