
com.twitter.scrooge.Option Maven / Gradle / Ivy
The newest version!
package com.twitter.scrooge;
import java.util.*;
public abstract class Option {
public abstract A get();
public abstract boolean isDefined();
public static Option make(boolean b, A a) {
if (b) {
return new Some(a);
} else {
return none();
}
}
public static Option none() {
return (Option) NONE;
}
public static Option NONE = new Option() {
public Void get() {
throw new IllegalArgumentException();
}
public boolean isDefined() {
return false;
}
};
public static class Some extends Option {
final A a;
public Some(A a) {
this.a = a;
}
public A get() {
return a;
}
public boolean isDefined() {
return true;
}
public boolean equals(Object other) {
if (!(other instanceof Some)) return false;
Some that = (Some) other;
return this.a.equals(that.a);
}
public String toString() {
return "Some(" + this.a.toString() + ")";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy