55
66import java .util .Optional ;
77
8- import static com .github .switcherapi .client .SwitcherProperties .DEFAULT_REGEX_TIMEOUT ;
9- import static com .github .switcherapi .client .SwitcherProperties .DEFAULT_TIMEOUT_MS ;
10- import static com .github .switcherapi .client .remote .Constants .DEFAULT_POOL_SIZE ;
8+ import static com .github .switcherapi .client .remote .Constants .*;
119
1210public class ContextBuilder {
1311
1412 private static ContextBuilder context ;
1513
16- private SwitcherProperties properties ;
14+ private SwitcherProperties switcherProperties ;
1715
18- private ContextBuilder () {
19- properties = new SwitcherProperties () ;
16+ private ContextBuilder (SwitcherProperties switcherProperties ) {
17+ this . switcherProperties = switcherProperties ;
2018 }
2119
2220 public static void preConfigure (SwitcherProperties switcherProperties ) {
@@ -41,25 +39,25 @@ public static ContextBuilder builder() {
4139 */
4240 public static ContextBuilder builder (boolean init ) {
4341 if (context == null || init )
44- context = new ContextBuilder ();
42+ context = new ContextBuilder (new SwitcherPropertiesImpl () );
4543
4644 return context ;
4745 }
4846
4947 void preBuild (SwitcherProperties properties ) {
50- this .properties = properties ;
48+ this .switcherProperties = properties ;
5149 }
52-
50+
5351 SwitcherProperties build () {
54- return this .properties ;
52+ return this .switcherProperties ;
5553 }
5654
5755 /**
5856 * @param contextLocation Feature class that extends SwitcherContext
5957 * @return ContextBuilder
6058 */
6159 public ContextBuilder contextLocation (String contextLocation ) {
62- properties .setValue (ContextKey .CONTEXT_LOCATION , contextLocation );
60+ switcherProperties .setValue (ContextKey .CONTEXT_LOCATION , contextLocation );
6361 return this ;
6462 }
6563
@@ -68,7 +66,7 @@ public ContextBuilder contextLocation(String contextLocation) {
6866 * @return ContextBuilder
6967 */
7068 public ContextBuilder url (String url ) {
71- properties .setValue (ContextKey .URL , url );
69+ switcherProperties .setValue (ContextKey .URL , url );
7270 return this ;
7371 }
7472
@@ -77,7 +75,7 @@ public ContextBuilder url(String url) {
7775 * @return ContextBuilder
7876 */
7977 public ContextBuilder apiKey (String apiKey ) {
80- properties .setValue (ContextKey .APIKEY , apiKey );
78+ switcherProperties .setValue (ContextKey .APIKEY , apiKey );
8179 return this ;
8280 }
8381
@@ -86,7 +84,7 @@ public ContextBuilder apiKey(String apiKey) {
8684 * @return ContextBuilder
8785 */
8886 public ContextBuilder domain (String domain ) {
89- properties .setValue (ContextKey .DOMAIN , domain );
87+ switcherProperties .setValue (ContextKey .DOMAIN , domain );
9088 return this ;
9189 }
9290
@@ -95,7 +93,7 @@ public ContextBuilder domain(String domain) {
9593 * @return ContextBuilder
9694 */
9795 public ContextBuilder component (String component ) {
98- properties .setValue (ContextKey .COMPONENT , component );
96+ switcherProperties .setValue (ContextKey .COMPONENT , component );
9997 return this ;
10098 }
10199
@@ -104,7 +102,8 @@ public ContextBuilder component(String component) {
104102 * @return ContextBuilder
105103 */
106104 public ContextBuilder environment (String environment ) {
107- properties .setValue (ContextKey .ENVIRONMENT , properties .getValueDefault (environment , SwitcherProperties .DEFAULT_ENV ));
105+ switcherProperties .setValue (ContextKey .ENVIRONMENT ,
106+ Optional .ofNullable (environment ).orElse (DEFAULT_ENV ));
108107 return this ;
109108 }
110109
@@ -113,7 +112,7 @@ public ContextBuilder environment(String environment) {
113112 * @return ContextBuilder
114113 */
115114 public ContextBuilder snapshotLocation (String snapshotLocation ) {
116- properties .setValue (ContextKey .SNAPSHOT_LOCATION , snapshotLocation );
115+ switcherProperties .setValue (ContextKey .SNAPSHOT_LOCATION , snapshotLocation );
117116 return this ;
118117 }
119118
@@ -122,10 +121,10 @@ public ContextBuilder snapshotLocation(String snapshotLocation) {
122121 * @return ContextBuilder
123122 */
124123 public ContextBuilder snapshotAutoUpdateInterval (String snapshotAutoUpdateInterval ) {
125- properties .setValue (ContextKey .SNAPSHOT_AUTO_UPDATE_INTERVAL , snapshotAutoUpdateInterval );
124+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_UPDATE_INTERVAL , snapshotAutoUpdateInterval );
126125
127126 if (snapshotAutoUpdateInterval != null )
128- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
127+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
129128
130129 return this ;
131130 }
@@ -137,7 +136,7 @@ public ContextBuilder snapshotAutoUpdateInterval(String snapshotAutoUpdateInterv
137136 * @return ContextBuilder
138137 */
139138 public ContextBuilder regexTimeout (Integer regexTimeout ) {
140- properties .setValue (ContextKey .REGEX_TIMEOUT ,
139+ switcherProperties .setValue (ContextKey .REGEX_TIMEOUT ,
141140 Optional .ofNullable (regexTimeout ).orElse (DEFAULT_REGEX_TIMEOUT ));
142141 return this ;
143142 }
@@ -147,7 +146,7 @@ public ContextBuilder regexTimeout(Integer regexTimeout) {
147146 * @return ContextBuilder
148147 */
149148 public ContextBuilder snapshotAutoLoad (boolean snapshotAutoLoad ) {
150- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , snapshotAutoLoad );
149+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , snapshotAutoLoad );
151150 return this ;
152151 }
153152
@@ -156,7 +155,7 @@ public ContextBuilder snapshotAutoLoad(boolean snapshotAutoLoad) {
156155 * @return ContextBuilder
157156 */
158157 public ContextBuilder snapshotSkipValidation (boolean snapshotSkipValidation ) {
159- properties .setValue (ContextKey .SNAPSHOT_SKIP_VALIDATION , snapshotSkipValidation );
158+ switcherProperties .setValue (ContextKey .SNAPSHOT_SKIP_VALIDATION , snapshotSkipValidation );
160159 return this ;
161160 }
162161
@@ -165,10 +164,10 @@ public ContextBuilder snapshotSkipValidation(boolean snapshotSkipValidation) {
165164 * @return ContextBuilder
166165 */
167166 public ContextBuilder silentMode (String retryAfter ) {
168- properties .setValue (ContextKey .SILENT_MODE , retryAfter );
167+ switcherProperties .setValue (ContextKey .SILENT_MODE , retryAfter );
169168
170169 if (StringUtils .isNotBlank (retryAfter )) {
171- properties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
170+ switcherProperties .setValue (ContextKey .SNAPSHOT_AUTO_LOAD , true );
172171 }
173172
174173 return this ;
@@ -179,7 +178,7 @@ public ContextBuilder silentMode(String retryAfter) {
179178 * @return ContextBuilder
180179 */
181180 public ContextBuilder local (boolean local ) {
182- properties .setValue (ContextKey .LOCAL_MODE , local );
181+ switcherProperties .setValue (ContextKey .LOCAL_MODE , local );
183182 return this ;
184183 }
185184
@@ -188,7 +187,7 @@ public ContextBuilder local(boolean local) {
188187 * @return ContextBuilder
189188 */
190189 public ContextBuilder truststorePath (String truststorePath ) {
191- properties .setValue (ContextKey .TRUSTSTORE_PATH , truststorePath );
190+ switcherProperties .setValue (ContextKey .TRUSTSTORE_PATH , truststorePath );
192191 return this ;
193192 }
194193
@@ -197,7 +196,7 @@ public ContextBuilder truststorePath(String truststorePath) {
197196 * @return ContextBuilder
198197 */
199198 public ContextBuilder truststorePassword (String truststorePassword ) {
200- properties .setValue (ContextKey .TRUSTSTORE_PASSWORD , truststorePassword );
199+ switcherProperties .setValue (ContextKey .TRUSTSTORE_PASSWORD , truststorePassword );
201200 return this ;
202201 }
203202
@@ -206,8 +205,8 @@ public ContextBuilder truststorePassword(String truststorePassword) {
206205 * @return ContextBuilder
207206 */
208207 public ContextBuilder timeoutMs (Integer timeoutMs ) {
209- properties .setValue (ContextKey .TIMEOUT_MS ,
210- Optional .ofNullable (timeoutMs ).orElse (DEFAULT_TIMEOUT_MS ));
208+ switcherProperties .setValue (ContextKey .TIMEOUT_MS ,
209+ Optional .ofNullable (timeoutMs ).orElse (DEFAULT_TIMEOUT ));
211210 return this ;
212211 }
213212
@@ -216,7 +215,7 @@ public ContextBuilder timeoutMs(Integer timeoutMs) {
216215 * @return ContextBuilder
217216 */
218217 public ContextBuilder poolConnectionSize (Integer poolSize ) {
219- properties .setValue (ContextKey .POOL_CONNECTION_SIZE ,
218+ switcherProperties .setValue (ContextKey .POOL_CONNECTION_SIZE ,
220219 Optional .ofNullable (poolSize ).orElse (DEFAULT_POOL_SIZE ));
221220 return this ;
222221 }
0 commit comments