55
66import java .util .Optional ;
77
8- import static com .github .switcherapi .client .SwitcherProperties .DEFAULT_TIMEOUT_MS ;
9- import static com .github .switcherapi .client .remote .Constants .DEFAULT_POOL_SIZE ;
8+ import static com .github .switcherapi .client .remote .Constants .*;
109
1110public class ContextBuilder {
1211
1312 private static ContextBuilder context ;
1413
15- private SwitcherProperties properties ;
14+ private SwitcherProperties switcherProperties ;
1615
17- private ContextBuilder () {
18- properties = new SwitcherProperties () ;
16+ private ContextBuilder (SwitcherProperties switcherProperties ) {
17+ this . switcherProperties = switcherProperties ;
1918 }
2019
2120 public static void preConfigure (SwitcherProperties switcherProperties ) {
@@ -40,25 +39,25 @@ public static ContextBuilder builder() {
4039 */
4140 public static ContextBuilder builder (boolean init ) {
4241 if (context == null || init )
43- context = new ContextBuilder ();
42+ context = new ContextBuilder (new SwitcherPropertiesImpl () );
4443
4544 return context ;
4645 }
4746
4847 void preBuild (SwitcherProperties properties ) {
49- this .properties = properties ;
48+ this .switcherProperties = properties ;
5049 }
51-
50+
5251 SwitcherProperties build () {
53- return this .properties ;
52+ return this .switcherProperties ;
5453 }
5554
5655 /**
5756 * @param contextLocation Feature class that extends SwitcherContext
5857 * @return ContextBuilder
5958 */
6059 public ContextBuilder contextLocation (String contextLocation ) {
61- properties .setValue (ContextKey .CONTEXT_LOCATION , contextLocation );
60+ switcherProperties .setValue (ContextKey .CONTEXT_LOCATION , contextLocation );
6261 return this ;
6362 }
6463
@@ -67,7 +66,7 @@ public ContextBuilder contextLocation(String contextLocation) {
6766 * @return ContextBuilder
6867 */
6968 public ContextBuilder url (String url ) {
70- properties .setValue (ContextKey .URL , url );
69+ switcherProperties .setValue (ContextKey .URL , url );
7170 return this ;
7271 }
7372
@@ -76,7 +75,7 @@ public ContextBuilder url(String url) {
7675 * @return ContextBuilder
7776 */
7877 public ContextBuilder apiKey (String apiKey ) {
79- properties .setValue (ContextKey .APIKEY , apiKey );
78+ switcherProperties .setValue (ContextKey .APIKEY , apiKey );
8079 return this ;
8180 }
8281
@@ -85,7 +84,7 @@ public ContextBuilder apiKey(String apiKey) {
8584 * @return ContextBuilder
8685 */
8786 public ContextBuilder domain (String domain ) {
88- properties .setValue (ContextKey .DOMAIN , domain );
87+ switcherProperties .setValue (ContextKey .DOMAIN , domain );
8988 return this ;
9089 }
9190
@@ -94,7 +93,7 @@ public ContextBuilder domain(String domain) {
9493 * @return ContextBuilder
9594 */
9695 public ContextBuilder component (String component ) {
97- properties .setValue (ContextKey .COMPONENT , component );
96+ switcherProperties .setValue (ContextKey .COMPONENT , component );
9897 return this ;
9998 }
10099
@@ -103,7 +102,8 @@ public ContextBuilder component(String component) {
103102 * @return ContextBuilder
104103 */
105104 public ContextBuilder environment (String environment ) {
106- properties .setValue (ContextKey .ENVIRONMENT , properties .getValueDefault (environment , SwitcherProperties .DEFAULT_ENV ));
105+ switcherProperties .setValue (ContextKey .ENVIRONMENT ,
106+ Optional .ofNullable (environment ).orElse (DEFAULT_ENV ));
107107 return this ;
108108 }
109109
@@ -112,7 +112,7 @@ public ContextBuilder environment(String environment) {
112112 * @return ContextBuilder
113113 */
114114 public ContextBuilder snapshotLocation (String snapshotLocation ) {
115- properties .setValue (ContextKey .SNAPSHOT_LOCATION , snapshotLocation );
115+ switcherProperties .setValue (ContextKey .SNAPSHOT_LOCATION , snapshotLocation );
116116 return this ;
117117 }
118118
@@ -121,22 +121,11 @@ public ContextBuilder snapshotLocation(String snapshotLocation) {
121121 * @return ContextBuilder
122122 */
123123 public ContextBuilder snapshotAutoUpdateInterval (String snapshotAutoUpdateInterval ) {
124- properties .setValue (ContextKey .SNAPSHOT_AUTO_UPDATE_INTERVAL , snapshotAutoUpdateInterval );
124+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_UPDATE_INTERVAL , snapshotAutoUpdateInterval );
125125
126126 if (snapshotAutoUpdateInterval != null )
127- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
128-
129- return this ;
130- }
127+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
131128
132- /**
133- * Java 8 only
134- *
135- * @param regexTimeout Time in ms given to Timed Match Worker used for local Regex (ReDoS safety mechanism) - 3000 default value
136- * @return ContextBuilder
137- */
138- public ContextBuilder regexTimeout (int regexTimeout ) {
139- properties .setValue (ContextKey .REGEX_TIMEOUT , regexTimeout );
140129 return this ;
141130 }
142131
@@ -145,7 +134,7 @@ public ContextBuilder regexTimeout(int regexTimeout) {
145134 * @return ContextBuilder
146135 */
147136 public ContextBuilder snapshotAutoLoad (boolean snapshotAutoLoad ) {
148- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , snapshotAutoLoad );
137+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , snapshotAutoLoad );
149138 return this ;
150139 }
151140
@@ -154,7 +143,7 @@ public ContextBuilder snapshotAutoLoad(boolean snapshotAutoLoad) {
154143 * @return ContextBuilder
155144 */
156145 public ContextBuilder snapshotSkipValidation (boolean snapshotSkipValidation ) {
157- properties .setValue (ContextKey .SNAPSHOT_SKIP_VALIDATION , snapshotSkipValidation );
146+ switcherProperties .setValue (ContextKey .SNAPSHOT_SKIP_VALIDATION , snapshotSkipValidation );
158147 return this ;
159148 }
160149
@@ -163,10 +152,10 @@ public ContextBuilder snapshotSkipValidation(boolean snapshotSkipValidation) {
163152 * @return ContextBuilder
164153 */
165154 public ContextBuilder silentMode (String retryAfter ) {
166- properties .setValue (ContextKey .SILENT_MODE , retryAfter );
155+ switcherProperties .setValue (ContextKey .SILENT_MODE , retryAfter );
167156
168157 if (StringUtils .isNotBlank (retryAfter )) {
169- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
158+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
170159 }
171160
172161 return this ;
@@ -177,7 +166,7 @@ public ContextBuilder silentMode(String retryAfter) {
177166 * @return ContextBuilder
178167 */
179168 public ContextBuilder local (boolean local ) {
180- properties .setValue (ContextKey .LOCAL_MODE , local );
169+ switcherProperties .setValue (ContextKey .LOCAL_MODE , local );
181170 return this ;
182171 }
183172
@@ -186,7 +175,7 @@ public ContextBuilder local(boolean local) {
186175 * @return ContextBuilder
187176 */
188177 public ContextBuilder truststorePath (String truststorePath ) {
189- properties .setValue (ContextKey .TRUSTSTORE_PATH , truststorePath );
178+ switcherProperties .setValue (ContextKey .TRUSTSTORE_PATH , truststorePath );
190179 return this ;
191180 }
192181
@@ -195,7 +184,7 @@ public ContextBuilder truststorePath(String truststorePath) {
195184 * @return ContextBuilder
196185 */
197186 public ContextBuilder truststorePassword (String truststorePassword ) {
198- properties .setValue (ContextKey .TRUSTSTORE_PASSWORD , truststorePassword );
187+ switcherProperties .setValue (ContextKey .TRUSTSTORE_PASSWORD , truststorePassword );
199188 return this ;
200189 }
201190
@@ -204,8 +193,8 @@ public ContextBuilder truststorePassword(String truststorePassword) {
204193 * @return ContextBuilder
205194 */
206195 public ContextBuilder timeoutMs (Integer timeoutMs ) {
207- properties .setValue (ContextKey .TIMEOUT_MS ,
208- Optional .ofNullable (timeoutMs ).orElse (DEFAULT_TIMEOUT_MS ));
196+ switcherProperties .setValue (ContextKey .TIMEOUT_MS ,
197+ Optional .ofNullable (timeoutMs ).orElse (DEFAULT_TIMEOUT ));
209198 return this ;
210199 }
211200
@@ -214,7 +203,7 @@ public ContextBuilder timeoutMs(Integer timeoutMs) {
214203 * @return ContextBuilder
215204 */
216205 public ContextBuilder poolConnectionSize (Integer poolSize ) {
217- properties .setValue (ContextKey .POOL_CONNECTION_SIZE ,
206+ switcherProperties .setValue (ContextKey .POOL_CONNECTION_SIZE ,
218207 Optional .ofNullable (poolSize ).orElse (DEFAULT_POOL_SIZE ));
219208 return this ;
220209 }
0 commit comments