Skip to content

Instantly share code, notes, and snippets.

View babjo's full-sized avatar
🎯
Focusing

Chanhyeong Lee babjo

🎯
Focusing
View GitHub Profile
public class ClassA {
private Collaborator collaborator1;
private Collaborator collaborator2;
public void methodA() { // changed
...
}
public void methodB() { // affected as well
...
public class SendKakaoCommand implements Command { // new
...
public void execute() {
...
}
}
public class Handler {
...
public void handle(Command command) {
command.execute();
}
}
interface Command {
public void execute();
}
public class SendEmailCommand implements Command {
public class Handler {
...
public void handle(Command command) {
switch (command.getType()) {
case SEND_EMAIL:
String subject = command.getSubject();
String body = renderBody(command.getType(), command.getBodyParams());
emailSender.send(new Email(subject, body));
break;
case SEND_KAKAO: // new
public class Handler {
...
public void handle(Command command) {
switch (command.getType()) {
case SEND_EMAIL:
String subject = command.getSubject();
String body = renderBody(command.getType(), command.getBodyParams());
emailSender.send(new Email(subject, body));
break;
default:
@babjo
babjo / install_openjdk11.sh
Created October 6, 2018 06:02
A script to install openjdk11 with curl
curl https://download.java.net/java/ga/jdk11/openjdk-11_osx-x64_bin.tar.gz \
| tar -xz \
&& sudo mv jdk-11.jdk /Library/Java/JavaVirtualMachines
// use a lambda expression to create the initial listener
// which does nothing
HyperlinkListener listener = event -> {};
// these decorators first do their own thing and then call the
// decorated listener (the one handed over during construction);
// in the end, the last added decorator will act first
listener = new ExternalApplicationOpeningHyperlinkListenerDecorator(listener);
listener = new BrowserOpeningHyperlinkListenerDecorator(listener);
listener = new ServiceRequestHandlingHyperlinkListenerDecorator(listener);
CompletableFuture<String> completableFuture
= CompletableFuture.supplyAsync(() -> "Hello");
CompletableFuture<String> future = completableFuture
.thenApplyAsync(s -> s + " World");
assertEquals("Hello World", future.get());
CompletableFuture<String> completableFuture = new CompletableFuture<>();
// ...
completableFuture.completeExceptionally(
new RuntimeException("Calculation failed!"));
// ...
completableFuture.get(); // ExecutionException
String name = null;
// ...
CompletableFuture<String> completableFuture
= CompletableFuture.supplyAsync(() -> {
if (name == null) {
throw new RuntimeException("Computation error!");
}
return "Hello, " + name;