Last active
December 18, 2015 15:39
-
-
Save qnoid/5805659 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
public class ApplicationScope | |
{ | |
private volatile String value; | |
private final Supplier<String> supplier; | |
public ApplicationScope() | |
{ | |
this.supplier = null; | |
} | |
public ApplicationScope(Supplier<String> supplier) | |
{ | |
this.supplier = supplier; | |
} | |
public void didCreate(String value){ | |
this.value = value; | |
} | |
public void acceptValue(Consumer<String> consumer) | |
{ | |
if(this.value == null){ | |
throw new RuntimeException("Program execution is wrong!"); | |
} | |
consumer.accept(this.value); | |
} | |
public void acceptSuppliedValue(Consumer<String> consumer) | |
{ | |
String value = this.supplier.get(); | |
if(value == null){ | |
throw new RuntimeException("Program execution is wrong!"); | |
} | |
consumer.accept(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment