-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/main/java/com/mageddo/dnsproxyserver/di/StartupEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,5 @@ | ||
package com.mageddo.dnsproxyserver.di; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
public interface StartupEvent { | ||
|
||
static boolean exists(Collection<StartupEvent> events, Class<?> clazz) { | ||
return lookup(events, clazz) != null; | ||
} | ||
|
||
static <T> T lookup(Collection<StartupEvent> events, Class<T> clazz) { | ||
return (T) events | ||
.stream() | ||
.filter(it -> Objects.equals(clazz, it.getClass())) | ||
.findFirst() | ||
.orElse(null) | ||
; | ||
} | ||
|
||
void onStart(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/mageddo/dnsproxyserver/di/StartupEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mageddo.dnsproxyserver.di; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
@Slf4j | ||
public class StartupEvents { | ||
public static boolean exists(Collection<StartupEvent> events, Class<?> classToFind) { | ||
return lookup(events, classToFind) != null; | ||
} | ||
|
||
public static <T> T lookup(Collection<StartupEvent> events, Class<T> classToFind) { | ||
final var found = events | ||
.stream() | ||
.filter(it -> Objects.equals(classToFind, it.getClass())) | ||
.findFirst() | ||
.orElse(null); | ||
log.trace("found={}, classToFind={}", found, classToFind); | ||
return (T) found; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters