Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public interface Option<T> {
  2.   T get();
  3.   boolean isDefined();
  4. }
  5.  
  6. public class Some<T> implements Option<T> {
  7.   private final T value;
  8.  
  9.   public Some(T value) {
  10.     this.value = value;
  11.   }
  12.  
  13.   public boolean isDefined() {  return true;  }
  14.  
  15.   public T get() {  return value;  }
  16. }
  17.  
  18. public final class None<T> implements Option<T> {
  19.   public None() {
  20.   }
  21.  
  22.   public boolean isDefined() { return false;  }
  23.  
  24.   public T get() {
  25.     throw new UnsupportedOperationException("Cannot resolve value on None");
  26.   }
  27. }