import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

public class Promise<T> {

  private final CountDownLatch latch = new CountDownLatch(1);
  private final AtomicReference<T> value = new AtomicReference<>();

  public void deliver(T value) {
    this.value.set(value);
    latch.countDown();
  }

  public T get() throws InterruptedException {
    this.latch.await();
    return this.value.get();
  }

  public T get(long timeout, TimeUnit unit, T defaultValue) throws InterruptedException {
    final boolean delivered = this.latch.await(timeout, unit);
    if (!delivered) {
      return defaultValue;
    }

    return this.value.get();
  }

  public static void main(String[] args) throws InterruptedException {
    System.out.println("Hello world");
    Promise<Integer> p = new Promise<Integer>();
    Integer x = p.get(3, TimeUnit.SECONDS, 5);
    System.out.printf("Waited and got %s%n", x);
  }
}

@@ -126,16 +126,43 @@
 ference;
+%0Aimport java.util.Optional;
 %0A%0Apublic
@@ -342,24 +342,128 @@
 (T value) %7B%0A
+    if (value == null) %7B%0A          throw new IllegalArgumentException(%22%60value%60 cannot be null.%22);%0A    %7D%0A
     this.val
@@ -481,16 +481,21 @@
 e);%0A    
+this.
 latch.co
@@ -620,25 +620,35 @@
 %7D%0A%0A  public 
-T
+Optional%3CT%3E
  get(long ti
@@ -671,24 +671,8 @@
 unit
-, T defaultValue
 ) th
@@ -801,28 +801,32 @@
 urn 
-defaultValue
+Optional.empty()
 ;%0A    %7D%0A
 %0A   
@@ -821,17 +821,16 @@
 ;%0A    %7D%0A
-%0A
     retu
@@ -824,37 +824,44 @@
    %7D%0A    return 
-this.
+Optional.of(
 value.get();%0A  %7D
@@ -847,32 +847,33 @@
 l.of(value.get()
+)
 ;%0A  %7D%0A%0A  public 
@@ -1026,23 +1026,33 @@
 ();%0A    
+Optional%3C
 Integer
+%3E
  x = p.g
@@ -1077,11 +1077,8 @@
 ONDS
-, 5
 );%0A 

Use optional