/** * Creates a new instance of the factory * * @param errorTypesEnum an {@link ErrorTypeDefinition} implementation indicating all the errors from an extension * @param extensionNamespace the namespace for the {@link ErrorModel} to be generated */ public ErrorsModelFactory(ErrorTypeDefinition<?>[] errorTypesEnum, String extensionNamespace) throws IllegalModelDefinitionException { this.extensionNamespace = extensionNamespace.toUpperCase(); final DirectedGraph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph = toGraph(errorTypesEnum); errorModelMap = new HashMap<>(); initErrorModelMap(errorModelMap); new TopologicalOrderIterator<>(graph).forEachRemaining(errorType -> { ErrorModel errorModel = toErrorModel(errorType, errorModelMap); errorModelMap.put(errorModel.toString(), errorModel); }); addConnectivityErrors(errorModelMap); }
/** * Creates a new instance of the factory * * @param errorTypesEnum an {@link ErrorTypeDefinition} implementation indicating all the errors from an extension * @param extensionNamespace the namespace for the {@link ErrorModel} to be generated */ public ErrorsModelFactory(ErrorTypeDefinition<?>[] errorTypesEnum, String extensionNamespace) throws IllegalModelDefinitionException { this.extensionNamespace = extensionNamespace.toUpperCase(); final DirectedGraph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph = toGraph(errorTypesEnum); errorModelMap = new HashMap<>(); initErrorModelMap(errorModelMap); new TopologicalOrderIterator<>(graph).forEachRemaining(errorType -> { ErrorModel errorModel = toErrorModel(errorType, errorModelMap); errorModelMap.put(errorModel.toString(), errorModel); }); addConnectivityErrors(errorModelMap); }
/** * Computes the transitive closure of a directed acyclic graph in $O(nm)$ * * @param graph - Graph to compute transitive closure for. * @param <V> the graph vertex type * @param <E> the graph edge type */ public <V, E> void closeDirectedAcyclicGraph(DirectedAcyclicGraph<V, E> graph) { Deque<V> orderedVertices = new ArrayDeque<>(graph.vertexSet().size()); new TopologicalOrderIterator<>(graph).forEachRemaining(orderedVertices::addFirst); for (V vertex : orderedVertices) { for (V successor : Graphs.successorListOf(graph, vertex)) { for (V closureVertex : Graphs.successorListOf(graph, successor)) { graph.addEdge(vertex, closureVertex); } } } }