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

net.fornwall.jelf.MemoizedObject Maven / Gradle / Ivy

package net.fornwall.jelf;

/**
 * A memoized object. Override {@link #computeValue} in subclasses; call {@link #getValue} in using code.
 */
abstract class MemoizedObject {
	private boolean computed;
	private T value;

	/**
	 * Should compute the value of this memoized object. This will only be called once, upon the first call to
	 * {@link #getValue}.
	 */
	protected abstract T computeValue() throws ElfException;

	/** Public accessor for the memoized value. */
	public final T getValue() throws ElfException {
		if (!computed) {
			value = computeValue();
			computed = true;
		}
		return value;
	}
	
	@SuppressWarnings("unchecked")
	public static  MemoizedObject[] uncheckedArray(int size) {
		return new MemoizedObject[size];
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy