edu.stanford.nlp.util.Lazy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-parser Show documentation
Show all versions of stanford-parser Show documentation
Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.
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();
}
};
}
}