Skip to content

Commit 00c7c8b

Browse files
feffijknack
authored andcommitted
fixed minor code issues (jooby-project#1169)
(cherry picked from commit 8e70bd1)
1 parent fd4060a commit 00c7c8b

File tree

1 file changed

+26
-36
lines changed
  • modules/jooby-scanner/src/main/java/org/jooby/scanner

1 file changed

+26
-36
lines changed

modules/jooby-scanner/src/main/java/org/jooby/scanner/Scanner.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public class Scanner implements Jooby.Module {
372372
private List<String> packages;
373373

374374
@SuppressWarnings("rawtypes")
375-
private Set<Class> serviceTypes = new LinkedHashSet<>();
375+
private final Set<Class> serviceTypes = new LinkedHashSet<>();
376376

377377
/**
378378
* Creates a new {@link Scanner} and uses the provided scan spec or packages.
@@ -404,7 +404,7 @@ public void configure(final Env env, final Config conf, final Binder binder) {
404404
Router routes = env.router();
405405

406406
ClassLoader loader = getClass().getClassLoader();
407-
Throwing.Function<String, Class> loadClass = name -> loader.loadClass(name);
407+
Throwing.Function<String, Class> loadClass = loader::loadClass;
408408

409409
// bind once as singleton + post/pre callbacks
410410
Set<Object> bindings = new HashSet<>();
@@ -418,9 +418,7 @@ public void configure(final Env env, final Config conf, final Binder binder) {
418418
ScanResult result = scanner.scan(conf.getInt("runtime.processors") + 1);
419419

420420
Predicate<String> inPackage = name -> packages.stream()
421-
.filter(name::startsWith)
422-
.findFirst()
423-
.isPresent();
421+
.anyMatch(name::startsWith);
424422

425423
/** Controllers: */
426424
result.getNamesOfClassesWithAnnotation(Path.class)
@@ -443,41 +441,35 @@ public void configure(final Env env, final Config conf, final Binder binder) {
443441
/** Annotated with: */
444442
serviceTypes.stream()
445443
.filter(A)
446-
.forEach(a -> {
447-
result.getNamesOfClassesWithAnnotation(a)
448-
.stream()
449-
.filter(once)
450-
.map(loadClass)
451-
.filter(C)
452-
.forEach(bind);
453-
});
444+
.forEach(a -> result.getNamesOfClassesWithAnnotation(a)
445+
.stream()
446+
.filter(once)
447+
.map(loadClass)
448+
.filter(C)
449+
.forEach(bind));
454450

455451
/** Implements: */
456452
serviceTypes.stream()
457453
.filter(I)
458454
.filter(type -> type != Jooby.Module.class && type != Module.class && type != Service.class)
459-
.forEach(i -> {
460-
result.getNamesOfClassesImplementing(i)
461-
.stream()
462-
.filter(inPackage)
463-
.filter(once)
464-
.map(loadClass)
465-
.filter(C)
466-
.forEach(bind);
467-
});
455+
.forEach(i -> result.getNamesOfClassesImplementing(i)
456+
.stream()
457+
.filter(inPackage)
458+
.filter(once)
459+
.map(loadClass)
460+
.filter(C)
461+
.forEach(bind));
468462

469463
/** SubclassOf: */
470464
serviceTypes.stream()
471465
.filter(S)
472-
.forEach(k -> {
473-
result.getNamesOfSubclassesOf(k)
474-
.stream()
475-
.filter(inPackage)
476-
.filter(once)
477-
.map(loadClass)
478-
.filter(C)
479-
.forEach(bind);
480-
});
466+
.forEach(k -> result.getNamesOfSubclassesOf(k)
467+
.stream()
468+
.filter(inPackage)
469+
.filter(once)
470+
.map(loadClass)
471+
.filter(C)
472+
.forEach(bind));
481473

482474
/** Guice modules: */
483475
if (serviceTypes.contains(Module.class)) {
@@ -528,7 +520,7 @@ public Scanner scan(final Class<?> type) {
528520
}
529521

530522
private static <T> T newObject(final Class<T> klass) {
531-
return throwingSupplier(() -> klass.newInstance()).get();
523+
return throwingSupplier(klass::newInstance).get();
532524
}
533525

534526
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -542,7 +534,7 @@ private static void guavaServices(final Env env, final Binder binder,
542534
serviceTypes.forEach(guavaService);
543535
// lazy service manager
544536
AtomicReference<ServiceManager> sm = new AtomicReference<>();
545-
Provider<ServiceManager> smProvider = () -> sm.get();
537+
Provider<ServiceManager> smProvider = sm::get;
546538
binder.bind(ServiceManager.class).toProvider(smProvider);
547539
// ask Guice for services, create ServiceManager and start services
548540
env.onStart(r -> {
@@ -553,9 +545,7 @@ private static void guavaServices(final Env env, final Binder binder,
553545
sm.get().startAsync().awaitHealthy();
554546
});
555547
// stop services
556-
env.onStop(() -> {
557-
sm.get().stopAsync().awaitStopped();
558-
});
548+
env.onStop(() -> sm.get().stopAsync().awaitStopped());
559549
}
560550

561551
@SuppressWarnings({"unchecked", "rawtypes"})

0 commit comments

Comments
 (0)