This commit is contained in:
Alexey Kudravtsev
2016-12-26 17:03:07 +03:00
parent 8212ba127d
commit 4c8f483860
3 changed files with 15 additions and 6 deletions
@@ -255,17 +255,20 @@ public class DFSTBuilder<Node> {
if (componentSizes.isEmpty()) return Collections.emptyList();
return new MyCollection<Collection<Node>>(componentSizes.size()) {
@NotNull
@Override
public Iterator<Collection<Node>> iterator() {
return new MyIterator<Collection<Node>>(componentSizes.size()) {
private int offset = 0;
private int offset;
@Override
protected Collection<Node> get(int i) {
final int cSize = componentSizes.get(i), cOffset = offset;
final int cSize = componentSizes.get(i);
final int cOffset = offset;
if (cSize == 0) return Collections.emptyList();
offset += cSize;
return new MyCollection<Node>(cSize) {
@NotNull
@Override
public Iterator<Node> iterator() {
return new MyIterator<Node>(cSize) {
@@ -282,7 +285,7 @@ public class DFSTBuilder<Node> {
};
}
private static abstract class MyCollection<T> extends AbstractCollection<T> {
private abstract static class MyCollection<T> extends AbstractCollection<T> {
private final int size;
protected MyCollection(int size) {
@@ -295,9 +298,9 @@ public class DFSTBuilder<Node> {
}
}
private static abstract class MyIterator<T> implements Iterator<T> {
private abstract static class MyIterator<T> implements Iterator<T> {
private final int size;
private int i = 0;
private int i;
protected MyIterator(int size) {
this.size = size;
@@ -22,9 +22,12 @@ import java.util.Iterator;
* @author dsl
*/
public interface Graph<Node> extends InboundSemiGraph<Node>, OutboundSemiGraph<Node> {
@Override
Collection<Node> getNodes();
@Override
Iterator<Node> getIn(Node n);
@Override
Iterator<Node> getOut(Node n);
}
@@ -15,12 +15,15 @@
*/
package com.intellij.util.graph;
import org.jetbrains.annotations.NotNull;
import java.util.*;
/**
* @author dsl
*/
public class GraphGenerator<Node> implements Graph<Node> {
@NotNull
public static <T> Graph<T> generate(InboundSemiGraph<T> graph) {
return new GraphGenerator<T>(graph);
}
@@ -28,7 +31,7 @@ public class GraphGenerator<Node> implements Graph<Node> {
private final InboundSemiGraph<Node> myGraph;
private final Map<Node, Set<Node>> myOuts;
private GraphGenerator(InboundSemiGraph<Node> graph) {
private GraphGenerator(@NotNull InboundSemiGraph<Node> graph) {
myGraph = graph;
myOuts = new LinkedHashMap<Node, Set<Node>>();
buildOuts();