package nl.korthout.baubillious.neuralnet;

import nl.korthout.baubillious.neuralnet.graph.Edge;
import nl.korthout.baubillious.neuralnet.graph.Graph;
import nl.korthout.baubillious.neuralnet.graph.Node;

import java.util.List;

public class GraphGenerator {

    private int nodes;
    private int minNeighbours;

    public GraphGenerator() {
        nodes = 0;
        minNeighbours = 0;
    }

    public GraphGenerator nodes(int number) {
        this.nodes = number;
        return this;
    }

    public GraphGenerator minNeighbours(int number) {
        this.minNeighbours = number;
        return this;
    }

    public Graph generate() {
        Graph graph = new Graph();

        for (int i=0; i<nodes; i++) {
            Node node = new Node();

            List<Node> randomNodes = graph.getRandomNodes(Math.min(minNeighbours, i));
            for (Node randomNode: randomNodes) {
                Edge edge = new Edge(randomNode, node);
                randomNode.addNeighbour(edge);
                node.addNeighbour(edge);
            }

            graph.addNode(node);
        }

        return graph;
    }

}

@@ -37,16 +37,40 @@
 alnet;%0A%0A
+import java.util.List;%0A%0A
 import n
@@ -226,32 +226,8 @@
 e;%0A%0A
-import java.util.List;%0A%0A
 publ
@@ -253,16 +253,130 @@
 ator %7B%0A%0A
+    public static final int DEFAULT_NUMBER_OF_NODES = 1;%0A    public static final int DEFAULT_MIN_NEIGHBOURS = 1;%0A%0A
     priv
@@ -384,16 +384,24 @@
 te int n
+umberOfN
 odes;%0A  
@@ -473,16 +473,46 @@
    n
-odes = 0
+umberOfNodes = DEFAULT_NUMBER_OF_NODES
 ;%0A  
@@ -533,17 +533,38 @@
 bours = 
-0
+DEFAULT_MIN_NEIGHBOURS
 ;%0A    %7D%0A
@@ -624,16 +624,24 @@
   this.n
+umberOfN
 odes = n
@@ -855,24 +855,124 @@
 ew Graph();%0A
+        createNodes(graph);%0A        return graph;%0A    %7D%0A%0A    private void createNodes(Graph graph) %7B
 %0A        for
@@ -982,15 +982,27 @@
 nt i
-=
+ = 
 0; i
-%3Cn
+ %3C numberOfN
 odes
@@ -1046,17 +1046,16 @@
 Node();%0A
-%0A
         
@@ -1062,54 +1062,222 @@
     
-List%3CNode%3E randomNodes = graph.getRandomNodes(
+createEdgesToRandomExistingNodes(graph, node);%0A            graph.addNode(node);%0A        %7D%0A    %7D%0A%0A    private void createEdgesToRandomExistingNodes(Graph graph, Node node) %7B%0A        int numberOfPossibleNeighbours = 
 Math
@@ -1300,17 +1300,27 @@
 rs, 
-i
+graph.size(
 ));%0A    
     
@@ -1311,24 +1311,111 @@
 ize());%0A    
+    List%3CNode%3E randomExistingNodes = graph.getRandomNodes(numberOfPossibleNeighbours);%0A
         for 
@@ -1434,24 +1434,32 @@
 Node: random
+Existing
 Nodes) %7B%0A   
@@ -1471,28 +1471,14 @@
     
-    Edge edge = new 
+create
 Edge
@@ -1509,167 +1509,178 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-randomNode.addNeighbour(edge);%0A                node.addNeighbour(edge);%0A            %7D%0A%0A            graph.addNode(node);%0A        %7D%0A%0A        return graph
+private void createEdge(Node node, Node other) %7B%0A        Edge edge = new Edge(node, other);%0A        other.addNeighbour(edge);%0A        node.addNeighbour(edge)
 ;%0A  

Use short methods style from CleanCode