@@ -410,22 +410,23 @@ private static String shortName(String filename) {
410
410
return filename .substring (index + 1 );
411
411
}
412
412
413
- private interface Generator <T > {
414
- void generate (List <String > lines , T attachment ) throws IOException ;
413
+ @ FunctionalInterface
414
+ private interface Action <T > {
415
+ void execute (List <String > lines , T attachment ) throws IOException ;
415
416
416
- default Generator <T > and (Generator < T > generator ) {
417
+ default Action <T > and (Action <? super T > action ) {
417
418
return (lines , attachment ) -> {
418
- generate (lines , attachment );
419
- generator . generate (lines , attachment );
419
+ execute (lines , attachment );
420
+ action . execute (lines , attachment );
420
421
};
421
422
}
422
423
423
- static Generator <String > write ( Generator <Path > writeMethod , Path folder , String extension ) {
424
- return (lines , rawFilename ) -> writeMethod . generate (lines , folder .resolve (rawFilename + extension ));
424
+ static Action <String > create ( Action <Path > action , Path folder , String extension ) {
425
+ return (lines , rawFilename ) -> action . execute (lines , folder .resolve (rawFilename + extension ));
425
426
}
426
427
}
427
428
428
- private static void generate (List <Path > paths , Generator <String > generator ) throws IOException {
429
+ private static void generate (List <Path > paths , Action <String > action ) throws IOException {
429
430
for (var path : paths ) {
430
431
var rawFilename = removeExtension (path .getFileName ().toString ());
431
432
@@ -435,7 +436,7 @@ private static void generate(List<Path> paths, Generator<String> generator) thro
435
436
lines = stream .dropWhile (LineKind .is (LineKind .TEXT )).dropWhile (LineKind .is (LineKind .BLANK )).collect (Collectors .toList ());
436
437
}
437
438
438
- generator . generate (lines , rawFilename );
439
+ action . execute (lines , rawFilename );
439
440
}
440
441
}
441
442
@@ -454,7 +455,7 @@ private static List<Path> gatherFiles(Path directory, Predicate<String> filter)
454
455
}
455
456
}
456
457
457
- private static /* record*/ class Config {
458
+ private static record Config ( Optional < Kind > index , Set < Kind > kinds , Map < Kind , Path > folderMap ) {
458
459
private enum Kind {
459
460
MARKDOWN (".md" , build ::writeMarkDown ),
460
461
NOTEBOOK (".ipynb" , build ::writeJupyter ),
@@ -469,12 +470,12 @@ static Optional<Kind> of(String name) {
469
470
470
471
private final String propertyName ;
471
472
private final String extension ;
472
- private final Generator <Path > generator ;
473
+ private final Action <Path > action ;
473
474
474
- private Kind (String extension , Generator <Path > generator ) {
475
+ private Kind (String extension , Action <Path > action ) {
475
476
this .propertyName = name ().toLowerCase ();
476
477
this .extension = extension ;
477
- this .generator = generator ;
478
+ this .action = action ;
478
479
}
479
480
480
481
Path folder (Properties properties ) {
@@ -486,16 +487,6 @@ private static Optional<String> getProperty(Properties properties, String proper
486
487
return Optional .ofNullable (properties .getProperty (propertyName ));
487
488
}
488
489
489
- private final Optional <Kind > index ;
490
- private final Set <Kind > kinds ;
491
- private final Map <Kind , Path > folderMap ;
492
-
493
- private Config (Optional <Kind > index , Set <Kind > kinds , Map <Kind , Path > folderMap ) {
494
- this .index = index ;
495
- this .kinds = kinds ;
496
- this .folderMap = folderMap ;
497
- }
498
-
499
490
Path folder (Kind kind ) {
500
491
return folderMap .get (kind );
501
492
}
@@ -523,8 +514,8 @@ public static void main(String[] args) throws IOException {
523
514
createDirectories (config .folder (kind ));
524
515
}
525
516
526
- // create generator
527
- var generator = config .kinds .stream ().map (k -> Generator . write (k .generator , config .folder (k ), k .extension )).reduce (Generator ::and ).orElseThrow ();
517
+ // create action
518
+ var generator = config .kinds .stream ().map (k -> Action . create (k .action , config .folder (k ), k .extension )).reduce (Action ::and ).orElseThrow ();
528
519
529
520
// gather files and generate
530
521
var files = gatherFiles (Path .of ("." ), name -> name .endsWith (".jsh" ));
0 commit comments