All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.util.Lazy Maven / Gradle / Ivy

Go to download

Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.

There is a newer version: 3.9.2
Show newest version
package edu.stanford.nlp.util;

import java.util.function.Supplier;

/**
 * An instantiation of a lazy object.
 *
 * @author Gabor Angeli
 */
public abstract class Lazy {
  private E implOrNull = null;

  public synchronized E get() {
    if (implOrNull == null) {
      implOrNull = compute();
    }
    return implOrNull;
  }

  protected abstract E compute();

  public E getIfDefined() {
    return implOrNull;
  }

  public static  Lazy from(final E definedElement) {
    return new Lazy() {
      @Override
      protected E compute() {
        return definedElement;
      }
    };
  }

  public static  Lazy of(Supplier fn) {
    return new Lazy() {
      @Override
      protected E compute() {
        return fn.get();
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy