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

de.team33.patterns.lazy.narvi.Mutual Maven / Gradle / Ivy

The newest version!
package de.team33.patterns.lazy.narvi;

import de.team33.patterns.exceptional.dione.XSupplier;

class Mutual {

    private volatile XSupplier backing;

    Mutual(final XSupplier initial) {
        this.backing = provident(initial);
    }

    private XSupplier definite(final T value) {
        return () -> value;
    }

    private XSupplier provident(final XSupplier initial) {
        return new XSupplier() {

            @Override
            public synchronized T get() throws X {
                if (backing == this) {
                    backing = definite(initial.get());
                }
                return backing.get();
            }
        };
    }

    T get() throws X {
        return backing.get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy