// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.function.supplier;

import javax.annotation.Nullable;
import java.util.function.Supplier;

public class CachedSupplier<T> implements Supplier<T>
{
    private final Supplier<T> delegate;
    private transient volatile boolean initialized;
    @Nullable
    private transient T value;
    
    public CachedSupplier(final Supplier<T> delegate) {
        this.delegate = delegate;
    }
    
    @Nullable
    @Override
    public T get() {
        if (!this.initialized) {
            synchronized (this) {
                if (!this.initialized) {
                    final T t = this.delegate.get();
                    this.value = t;
                    this.initialized = true;
                    return t;
                }
            }
        }
        return this.value;
    }
    
    @Nullable
    public T getValue() {
        return this.value;
    }
    
    public void invalidate() {
        if (this.initialized) {
            synchronized (this) {
                if (this.initialized) {
                    this.value = null;
                    this.initialized = false;
                }
            }
        }
    }
}
