code: private static <T> Supplier<T> memoize(Supplier<T> original) {
      return new Supplier<T>() {
        Supplier<T> mDelegate = this::firstTime;
        boolean mInitialized;
        public T get() {
          return mDelegate.get();
        }
  
        private synchronized T firstTime() {
          if (!mInitialized) {
            T value = original.get();
            mDelegate = () -> value;
            mInitialized = true;
          }
          return mDelegate.get();
        }
      };
    }
docs: Memoize implementation for java.util.function.supplier.