1414import java .util .stream .Stream ;
1515
1616public class Main {
17-
17+
1818 public static void main (String [] args ) throws IOException {
19- File rootDir = new File ("./target/generated/" );
20- System .out .println ("Writing to " + rootDir .getAbsolutePath ());
21- Path root = rootDir .toPath ();
22-
23-
19+ String pathname = "./target/generated/" ;
20+
21+ int roots = 10 ;
2422 int depth = 10 ;
25- int roots = 10 ;
2623 int classes = 100 ;
24+ if (args .length == 0 ) {
25+ System .out .println ("No arguments given, using defaults" );
26+ } else {
27+ try {
28+ roots = Integer .parseUnsignedInt (args [0 ]);
29+ depth = Integer .parseUnsignedInt (args [1 ]);
30+ classes = Integer .parseUnsignedInt (args [2 ]);
31+ pathname = args [3 ];
32+ } catch (Exception e ) {
33+ //
34+ }
35+ }
36+ File rootDir = new File (pathname );
37+ Path root = rootDir .toPath ();
38+ System .out .println ("Writing to " + rootDir .getAbsolutePath ());
39+ System .out .println ("Roots: " + roots + ", depth: " + depth + ", classes & interfaces per package: " + (classes *2 ));
40+ System .out .println ("Will generate " + roots + "x" + depth + "x" + classes + "x2 + 2 = " + (depth * roots * classes * 2 + 2 ) + " files" );
2741
2842 new JavaBuilder (depth , roots , classes , root ).build ();
2943 }
3044}
3145
3246class JavaBuilder {
33-
47+
3448 static List <String > namesList = IntStream .rangeClosed ('a' , 'z' ).mapToObj (x -> String .valueOf ((char )x ))
3549 .collect (Collectors .toList ());
36-
50+
3751 int depth ;
3852 int roots ;
3953 private Ring <String > pnames ;
@@ -44,7 +58,7 @@ class JavaBuilder {
4458 private List <Interface > interfaces ;
4559
4660 private int countClasses ;
47-
61+
4862 public JavaBuilder (int depth , int roots , int countClasses , Path root ) {
4963 this .depth = depth ;
5064 this .roots = roots ;
@@ -54,7 +68,7 @@ public JavaBuilder(int depth, int roots, int countClasses, Path root) {
5468 classes = new ArrayList <>();
5569 interfaces = new ArrayList <>();
5670 }
57-
71+
5872 void build () throws IOException {
5973 Files .walkFileTree (root , new SimpleFileVisitor <Path >() {
6074 @ Override
@@ -70,13 +84,13 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
7084 }
7185 });
7286 Files .createDirectories (root );
73-
87+
7488 List <Package > rootPackages = new ArrayList <>();
7589 for (int i = 0 ; i < roots ; i ++) {
7690 Package p = createPackage (pnames .next (), null );
7791 rootPackages .add (p );
7892 }
79-
93+
8094 for (Package r : rootPackages ) {
8195 Stream <Package > stream = Stream .iterate (r , x -> new Package (pnames .next (), x )).limit (depth );
8296 stream .forEach (p -> {
@@ -97,30 +111,30 @@ private void generateFile(JavaElement e) {
97111 e1 .printStackTrace ();
98112 }
99113 }
100-
114+
101115 void createInterfaces (Package p ) {
102116 Ring <Interface > toImplement = new Ring <>(interfaces , countClasses );
103117 if (interfaces .isEmpty ()) {
104118 interfaces .add (new Interface ("IFoo0" , p .getFqn (), "java.util.concurrent.Callable" ));
105119 }
106- toImplement .stream ().forEach (i -> {
120+ toImplement .stream ().forEach (i -> {
107121 interfaces .add (new Interface ("IFoo" + interfaces .size (), p .getFqn (), toImplement .next ().fqn ()));
108122 });
109123 }
110-
124+
111125 void createClasses (Package p ) {
112126 Ring <Interface > implement = new Ring <>(interfaces , countClasses );
113127 Ring <Clazz > toExtend = new Ring <>(classes , countClasses );
114128 if (classes .isEmpty ()) {
115- classes .add (new Clazz ("Element0 " , p .getFqn (), implement .next ().fqn (), "java.lang.Object" ));
129+ classes .add (new Clazz ("Foo0 " , p .getFqn (), implement .next ().fqn (), "java.lang.Object" ));
116130 }
117131 toExtend .stream ().forEach (x -> {
118- classes .add (new Clazz ("Element " + classes .size (), p .getFqn (), implement .next ().fqn (), toExtend .next ().fqn ()));
132+ classes .add (new Clazz ("Foo " + classes .size (), p .getFqn (), implement .next ().fqn (), toExtend .next ().fqn ()));
119133 });
120134 }
121-
135+
122136 Package createPackage (String name , Package parent ) {
123137 return new Package (name , parent );
124138 }
125-
139+
126140}
0 commit comments