Skip to content

Instantly share code, notes, and snippets.

@qnoid
Last active December 18, 2015 15:39
Show Gist options
  • Save qnoid/5805659 to your computer and use it in GitHub Desktop.
Save qnoid/5805659 to your computer and use it in GitHub Desktop.
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