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

de.team33.patterns.lazy.e1.Lazy Maven / Gradle / Ivy

There is a newer version: 1.13.0
Show newest version
package de.team33.patterns.lazy.e1;

import java.util.function.Supplier;

/**
 * Implements a {@link Supplier} that provides a virtually fixed value.
 * This value is only actually determined when it is accessed for the first time.
 * 

* This implementation ensures that the {@linkplain #Lazy(Supplier) originally defined initialization code} * is called at most once, even if there is concurrent access from multiple threads, unless the * initialization attempt causes a {@link RuntimeException}. *

* Once the value is established, unnecessary effort to synchronize competing accesses is avoided. * * @deprecated Further development is discontinued and this package/module may be removed in a future release. * Successor edition is the module lazy-narvi. */ @Deprecated public class Lazy extends Mutual implements Supplier { /** * Initializes a new instance giving a supplier that defines the intended initialization of the * represented value. */ public Lazy(final Supplier initial) { super(initial::get); } /** * Executes the {@linkplain #Lazy(Supplier) originally defined initialization code} on the first call and * returns its result on that and every subsequent call without calling the supplier again. */ @Override public final T get() { return backing.get(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy