package io.socket.util; import java.util.NoSuchElementException; public class Optional { static final Optional EMPTY = Optional.ofNullable(null); private T value; public static Optional of(T value) { if (value == null) { throw new NullPointerException(); } return new Optional(value); } public static Optional ofNullable(T value) { return new Optional(value); } public static Optional empty() { return EMPTY; } private Optional(T value) { this.value = value; } public boolean isPresent() { return this.value != null; } public T get() { if (this.value == null) { throw new NoSuchElementException(); } return this.value; } public T orElse(T other) { return this.value != null ? this.value : other; } }