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

net.sf.javagimmicks.util8.AbstractLazySupplier Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
package net.sf.javagimmicks.util8;

import java.util.function.Supplier;

abstract class AbstractLazySupplier implements Supplier
{
   private final Supplier _baseSupplier;

   protected AbstractLazySupplier(final Supplier baseSupplier)
   {
      _baseSupplier = baseSupplier;
   }

   @Override
   public final E get()
   {
      E instance = getInstance();
      if (instance != null)
      {
         return instance;
      }

      synchronized (this)
      {
         instance = getInstance();
         if (instance == null)
         {
            instance = _baseSupplier.get();
            setInstance(instance);
         }
      }

      return instance;
   }

   abstract protected E getInstance();

   abstract protected void setInstance(E instance);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy