package speiger.src.coreengine.utils.collections.collection;

import java.util.function.Supplier;

public class Lazy<T> implements Supplier<T>
{
	Supplier<T> provider;
	T value;
	
	public Lazy(Supplier<T> provider) {
		this.provider = provider;
	}
	
	public T get() {
		if(value == null) {
			value = provider.get();
		}
		return value;
	}
	
	public void clearValue() {
		value = null;
	}
	
	public boolean hasValue() {
		return value != null;
	}
	
	public T reload() {
		T oldValue = value;
		value = provider.get();
		return oldValue;
	}
}
