2626
2727import com .hubspot .jinjava .interpret .Context ;
2828import com .hubspot .jinjava .interpret .Context .Library ;
29+ import com .hubspot .jinjava .random .RandomNumberGeneratorStrategy ;
2930
3031public class JinjavaConfig {
3132
@@ -44,17 +45,18 @@ public class JinjavaConfig {
4445 private Map <Context .Library , Set <String >> disabled ;
4546 private final boolean failOnUnknownTokens ;
4647 private final boolean nestedInterpretationEnabled ;
48+ private final RandomNumberGeneratorStrategy randomNumberGenerator ;
4749
4850 public static Builder newBuilder () {
4951 return new Builder ();
5052 }
5153
5254 public JinjavaConfig () {
53- this (StandardCharsets .UTF_8 , Locale .ENGLISH , ZoneOffset .UTC , 10 , new HashMap <>(), false , false , true , false , false , 0 , true );
55+ this (StandardCharsets .UTF_8 , Locale .ENGLISH , ZoneOffset .UTC , 10 , new HashMap <>(), false , false , true , false , false , 0 , true , RandomNumberGeneratorStrategy . THREAD_LOCAL );
5456 }
5557
5658 public JinjavaConfig (Charset charset , Locale locale , ZoneId timeZone , int maxRenderDepth ) {
57- this (charset , locale , timeZone , maxRenderDepth , new HashMap <>(), false , false , true , false , false , 0 , true );
59+ this (charset , locale , timeZone , maxRenderDepth , new HashMap <>(), false , false , true , false , false , 0 , true , RandomNumberGeneratorStrategy . THREAD_LOCAL );
5860 }
5961
6062 private JinjavaConfig (Charset charset ,
@@ -69,7 +71,8 @@ private JinjavaConfig(Charset charset,
6971 boolean enableRecursiveMacroCalls ,
7072 boolean failOnUnknownTokens ,
7173 long maxOutputSize ,
72- boolean nestedInterpretationEnabled ) {
74+ boolean nestedInterpretationEnabled ,
75+ RandomNumberGeneratorStrategy randomNumberGenerator ) {
7376 this .charset = charset ;
7477 this .locale = locale ;
7578 this .timeZone = timeZone ;
@@ -82,6 +85,7 @@ private JinjavaConfig(Charset charset,
8285 this .failOnUnknownTokens = failOnUnknownTokens ;
8386 this .maxOutputSize = maxOutputSize ;
8487 this .nestedInterpretationEnabled = nestedInterpretationEnabled ;
88+ this .randomNumberGenerator = randomNumberGenerator ;
8589 }
8690
8791 public Charset getCharset () {
@@ -104,6 +108,10 @@ public long getMaxOutputSize() {
104108 return maxOutputSize ;
105109 }
106110
111+ public RandomNumberGeneratorStrategy getRandomNumberGeneratorStrategy () {
112+ return randomNumberGenerator ;
113+ }
114+
107115 public boolean isTrimBlocks () {
108116 return trimBlocks ;
109117 }
@@ -147,6 +155,7 @@ public static class Builder {
147155 private boolean enableRecursiveMacroCalls ;
148156 private boolean failOnUnknownTokens ;
149157 private boolean nestedInterpretationEnabled = true ;
158+ private RandomNumberGeneratorStrategy randomNumberGeneratorStrategy = RandomNumberGeneratorStrategy .THREAD_LOCAL ;
150159
151160 private Builder () {}
152161
@@ -175,6 +184,12 @@ public Builder withMaxRenderDepth(int maxRenderDepth) {
175184 return this ;
176185 }
177186
187+ public Builder withRandomNumberGeneratorStrategy (RandomNumberGeneratorStrategy randomNumberGeneratorStrategy ) {
188+ this .randomNumberGeneratorStrategy = randomNumberGeneratorStrategy ;
189+ return this ;
190+ }
191+
192+
178193 public Builder withTrimBlocks (boolean trimBlocks ) {
179194 this .trimBlocks = trimBlocks ;
180195 return this ;
@@ -211,7 +226,7 @@ public Builder withNestedInterpretationEnabled(boolean nestedInterpretationEnabl
211226 }
212227
213228 public JinjavaConfig build () {
214- return new JinjavaConfig (charset , locale , timeZone , maxRenderDepth , disabled , trimBlocks , lstripBlocks , readOnlyResolver , enableRecursiveMacroCalls , failOnUnknownTokens , maxOutputSize , nestedInterpretationEnabled );
229+ return new JinjavaConfig (charset , locale , timeZone , maxRenderDepth , disabled , trimBlocks , lstripBlocks , readOnlyResolver , enableRecursiveMacroCalls , failOnUnknownTokens , maxOutputSize , nestedInterpretationEnabled , randomNumberGeneratorStrategy );
215230 }
216231
217232 }
0 commit comments