package com.hubspot.jinjava.interpret;

import com.fasterxml.jackson.annotation.JsonValue;
import java.util.function.Supplier;

public class LazyExpression implements Supplier {
  private final Supplier supplier;
  private final String image;
  private final boolean memoize;
  private Object jsonValue = null;

  private LazyExpression(Supplier supplier, String image, boolean memoize) {
    this.supplier = supplier;
    this.image = image;
    this.memoize = memoize;
  }

  public static LazyExpression of(Supplier supplier, String image) {
    return new LazyExpression(supplier, image, true);
  }

  public static LazyExpression of(Supplier supplier, String image, boolean memoize) {
    return new LazyExpression(supplier, image, memoize);
  }

  @Override
  public Object get() {
    if (jsonValue == null || !memoize) {
      jsonValue = supplier.get();
    }
    return jsonValue;
  }

  @Override
  public String toString() {
    return image;
  }

  @JsonValue
  public Object getJsonValue() {
    return jsonValue == null ? "" : jsonValue;
  }
}

@@ -252,31 +252,39 @@
 e final 
-boolean
+MEMOIZATION
  memoiz
-e
+ation
 ;%0A  priv
@@ -313,16 +313,65 @@
  null;%0A%0A
+  public enum MEMOIZATION %7B%0A    ON,%0A    OFF%0A  %7D%0A%0A
   privat
@@ -416,39 +416,47 @@
 ring image, 
-boolean
+MEMOIZATION
  memoiz
-e
+ation
 ) %7B%0A    this
@@ -516,17 +516,21 @@
 s.memoiz
-e
+ation
  = memoi
@@ -530,17 +530,21 @@
 = memoiz
-e
+ation
 ;%0A  %7D%0A%0A 
@@ -662,12 +662,22 @@
 ge, 
-true
+MEMOIZATION.ON
 );%0A 
@@ -706,32 +706,37 @@
 zyExpression of(
+%0A    
 Supplier supplie
@@ -729,32 +729,36 @@
 pplier supplier,
+%0A   
  String image, b
@@ -759,24 +759,39 @@
 age,
- boolean memoize
+%0A    MEMOIZATION memoization%0A  
 ) %7B%0A
@@ -843,17 +843,21 @@
 , memoiz
-e
+ation
 );%0A  %7D%0A%0A
@@ -925,16 +925,38 @@
  %7C%7C 
-!
 memoiz
-e
+ation == MEMOIZATION.OFF
 ) %7B%0A

Switch from boolean to enum for memoization argument