Package org.jano.util

Source Code of org.jano.util.Optional

package org.jano.util;

import sun.plugin.dom.exception.InvalidStateException;

public class Optional<T> {
  private final T ref;

  private Optional(T ref) {
    this.ref = ref;
  }

  public T get() {
    if (null == ref) throw new InvalidStateException("Optional is empty");
    return ref;
  }

  public T getOrNull() {
    return ref;
  }

  public T getOrElse(T other) {
    return null != ref ? ref : other;
  }

  public boolean isPresent() {
    return null != ref;
  }

  public boolean isEmpty() {
    return null == ref;
  }

  public static <A> Optional<A> any(A ref) {
    return new Optional(ref);
  }

  public static <A> Optional<A> of(A ref) {
    if (null == ref) throw new NullPointerException("ref");
    return any(ref);
  }

  public static <A> Optional<A> empty() {
    return any(null);
  }
}
TOP

Related Classes of org.jano.util.Optional

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.