@@ -58,9 +58,9 @@ public final class PPUtils {
58
58
59
59
private final String dateIsoFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS" ;
60
60
61
- protected static final String grepSeparator = ":" ;
61
+ private static final String grepSeparator = ":" ;
62
62
63
- protected static final boolean sortDirectoryLast = true ;
63
+ private static final boolean sortDirectoryLast = true ;
64
64
65
65
private final String sourceUrl = "https://raw.githubusercontent.com/pponec/DirectoryBookmarks/%s/utils/%s.java"
66
66
.formatted (!true ? "main" : "development" , appName );
@@ -84,18 +84,16 @@ void start(Array<String> args) throws Exception {
84
84
final var file = args .get (1 ).map (Path ::of ).get ();
85
85
final var printLine = args .get (2 ).orElse ("" ).equals ("--print" );
86
86
final var subArgs = args .subArray (2 + (printLine ? 1 : 0 ));
87
- final var bodyPattern = subArgs .get (-2 ).map (t -> Pattern . compile ( t ) ).orElse (null );
88
- final var filePattern = subArgs .get (-1 ).map (t -> Pattern . compile ( t ) ).orElse (null );
87
+ final var bodyPattern = subArgs .get (-2 ).map (Pattern :: compile ).orElse (null );
88
+ final var filePattern = subArgs .get (-1 ).map (Pattern :: compile ).orElse (null );
89
89
new FinderUtilitiy (bodyPattern , filePattern , enforcedLinux , out )
90
90
.findFiles (file , printLine && bodyPattern != null );
91
91
}
92
92
case "grep" -> {
93
93
if (args .size () > 3 ) {
94
- final var bodyPattern = args .get (2 ).map (t -> Pattern . compile ( t ) ).orElse (null ); // Pattern.CASE_INSENSITIVE);
94
+ final var bodyPattern = args .get (2 ).map (Pattern :: compile ).orElse (null ); // Pattern.CASE_INSENSITIVE);
95
95
final var pathFinder = new FinderUtilitiy (bodyPattern , null , enforcedLinux , out );
96
- args .stream ().skip (3 ).forEach (file -> {
97
- pathFinder .grep (Path .of (file ), true );
98
- });
96
+ args .stream ().skip (3 ).forEach (file -> pathFinder .grep (Path .of (file ), true ));
99
97
}
100
98
}
101
99
case "date" -> {
@@ -186,7 +184,7 @@ public void convertBase64(Path inpFile, boolean encode) throws IOException {
186
184
os .write (b2 );
187
185
}
188
186
}
189
- out .println ("Converted file has a name: '%s'" . formatted ( outFile ) );
187
+ out .printf ("Converted file has a name: '%s'%n" , outFile );
190
188
}
191
189
}
192
190
@@ -245,7 +243,7 @@ public boolean grep(Path file, boolean printLine) {
245
243
}
246
244
247
245
/** Method supports a GitBash shell. */
248
- protected PrintStream printFileName (Path path ) {
246
+ private PrintStream printFileName (Path path ) {
249
247
if (enforcedLinux ) {
250
248
out .print (path .toString ().replace ('\\' , '/' ));
251
249
} else {
@@ -264,7 +262,7 @@ public int compare(final Path p1, final Path p2) {
264
262
if (d1 != d2 ) {
265
263
return d1 ? 1 : -1 ;
266
264
} else {
267
- return p1 .getFileName ().toString ().compareTo (p1 .getFileName ().toString ());
265
+ return p1 .getFileName ().toString ().compareTo (p2 .getFileName ().toString ());
268
266
}
269
267
}
270
268
}
@@ -276,7 +274,7 @@ class Utilities {
276
274
/** Compile the script and build it to the executable JAR file */
277
275
private void compile () throws Exception {
278
276
if (isJar ()) {
279
- out .printf ("Use the statement rather: java %s.java c %s" . formatted ( appName ) );
277
+ out .printf ("Use the statement rather: java %s.java c %s" , appName );
280
278
System .exit (1 );
281
279
}
282
280
@@ -365,7 +363,7 @@ private String[] getAllClassFiles(Class<?> mainClass) {
365
363
result .add (mainClass .getSimpleName () + suffix );
366
364
Stream .of (mainClass .getDeclaredClasses ())
367
365
.map (c -> mainClass .getSimpleName () + '$' + c .getSimpleName () + suffix )
368
- .forEach (c -> result . add ( c ) );
366
+ .forEach (result :: add );
369
367
return result .toArray (String []::new );
370
368
}
371
369
@@ -393,89 +391,84 @@ private void removePackage(Path fullJavaClass) throws IOException {
393
391
394
392
395
393
/** The immutable Array wrapper with utilities (from the Ujorm framework) */
396
- static class Array <T > {
397
- protected final T [] array ;
398
-
399
- public Array (T [] array ) {
400
- this .array = array ;
401
- }
394
+ record Array <T >(T [] array ) {
402
395
403
396
/** Negative index is supported */
404
- public Optional <T > get (final int i ) {
405
- final var j = i >= 0 ? i : array .length + i ;
406
- return Optional .ofNullable (j >= 0 && j < array .length ? array [j ] : null );
407
- }
397
+ public Optional <T > get (final int i ) {
398
+ final var j = i >= 0 ? i : array .length + i ;
399
+ return Optional .ofNullable (j >= 0 && j < array .length ? array [j ] : null );
400
+ }
408
401
409
- /** Add new items to the new Array */
410
- @ SuppressWarnings ("unchecked" )
411
- public Array <T > add (final T ... toAdd ) {
412
- final var result = Arrays .copyOf (array , array .length + toAdd .length );
413
- System .arraycopy (toAdd , 0 , result , array .length , toAdd .length );
414
- return new Array <>(result );
415
- }
402
+ /** Add new items to the new Array */
403
+ @ SuppressWarnings ("unchecked" )
404
+ public Array <T > add (final T ... toAdd ) {
405
+ final var result = Arrays .copyOf (array , array .length + toAdd .length );
406
+ System .arraycopy (toAdd , 0 , result , array .length , toAdd .length );
407
+ return new Array <>(result );
408
+ }
416
409
417
- /** Negative index is supported */
418
- public T getItem (final int i ) {
419
- return array [i >= 0 ? i : array .length + i ];
420
- }
410
+ /** Negative index is supported */
411
+ public T getItem (final int i ) {
412
+ return array [i >= 0 ? i : array .length + i ];
413
+ }
421
414
422
- public Optional <T > getFirst () {
423
- return get (0 );
424
- }
415
+ public Optional <T > getFirst () {
416
+ return get (0 );
417
+ }
425
418
426
- public Optional <T > getLast () {
427
- return get (-1 );
428
- }
419
+ public Optional <T > getLast () {
420
+ return get (-1 );
421
+ }
429
422
430
- public Array <T > removeFirst () {
431
- final var result = array .length > 0 ? Arrays .copyOfRange (array , 1 , array .length ) : array ;
432
- return new Array <>(result );
433
- }
423
+ public Array <T > removeFirst () {
424
+ final var result = array .length > 0 ? Arrays .copyOfRange (array , 1 , array .length ) : array ;
425
+ return new Array <>(result );
426
+ }
434
427
435
- public Array <T > subArray (final int from ) {
436
- final var from2 = Math .min (from , array .length );
437
- final var result = Arrays .copyOfRange (array , from2 , array .length );
438
- return new Array <>(result );
439
- }
428
+ public Array <T > subArray (final int from ) {
429
+ final var from2 = Math .min (from , array .length );
430
+ final var result = Arrays .copyOfRange (array , from2 , array .length );
431
+ return new Array <>(result );
432
+ }
440
433
441
- public List <T > toList () {
442
- return List .of (array );
443
- }
434
+ public List <T > toList () {
435
+ return List .of (array );
436
+ }
444
437
445
- public Stream <T > stream () {
446
- return Stream .of (array );
447
- }
438
+ public Stream <T > stream () {
439
+ return Stream .of (array );
440
+ }
448
441
449
- @ SuppressWarnings ("unchecked" )
450
- public T [] toArray () {
451
- final var type = array .getClass ().getComponentType ();
452
- final var result = java .lang .reflect .Array .newInstance (type , array .length );
453
- System .arraycopy (array , 0 , result , 0 , array .length );
454
- return ( T []) result ;
455
- }
442
+ @ SuppressWarnings ("unchecked" )
443
+ public T [] toArray () {
444
+ final var type = array .getClass ().getComponentType ();
445
+ final var result = ( T []) java .lang .reflect .Array .newInstance (type , array .length );
446
+ System .arraycopy (array , 0 , result , 0 , array .length );
447
+ return result ;
448
+ }
456
449
457
- public boolean isEmpty () {
458
- return array .length == 0 ;
459
- }
450
+ public boolean isEmpty () {
451
+ return array .length == 0 ;
452
+ }
460
453
461
- public boolean hasLength () {
462
- return array .length > 0 ;
463
- }
454
+ public boolean hasLength () {
455
+ return array .length > 0 ;
456
+ }
464
457
465
- public int size () {
466
- return array .length ;
467
- }
458
+ public int size () {
459
+ return array .length ;
460
+ }
468
461
469
- @ Override
470
- public String toString () {
471
- return List .of (array ).toString ();
472
- }
462
+ @ Override
463
+ public String toString () {
464
+ return List .of (array ).toString ();
465
+ }
473
466
474
- @ SuppressWarnings ("unchecked" )
475
- public static <T > Array <T > of (T ... chars ) {
476
- return new Array <T >(chars );
467
+ @ SuppressWarnings ("unchecked" )
468
+ public static <T > Array <T > of (T ... chars ) {
469
+ return new Array <>(chars );
470
+ }
477
471
}
478
- }
479
472
480
473
/** JSON parser. The {@code array} type is not supported. */
481
474
public static class Json {
0 commit comments