2323import com .optimizely .ab .Optimizely ;
2424import com .optimizely .ab .UnknownEventTypeException ;
2525import com .optimizely .ab .config .Experiment ;
26+ import com .optimizely .ab .config .ProjectConfig ;
2627import com .optimizely .ab .config .Variation ;
2728import com .optimizely .ab .notification .NotificationListener ;
2829
@@ -60,10 +61,10 @@ public class OptimizelyClient {
6061 */
6162 public @ Nullable Variation activate (@ NonNull String experimentKey ,
6263 @ NonNull String userId ) {
63- if (optimizely != null ) {
64+ if (isValid () ) {
6465 return optimizely .activate (experimentKey , userId );
6566 } else {
66- logger .warn ("Optimizely is not initialized, can't activate experiment {} for user {}" ,
67+ logger .warn ("Optimizely is not initialized, could not activate experiment {} for user {}" ,
6768 experimentKey , userId );
6869 return null ;
6970 }
@@ -81,15 +82,28 @@ public class OptimizelyClient {
8182 public @ Nullable Variation activate (@ NonNull String experimentKey ,
8283 @ NonNull String userId ,
8384 @ NonNull Map <String , String > attributes ) {
84- if (optimizely != null ) {
85+ if (isValid () ) {
8586 return optimizely .activate (experimentKey , userId , attributes );
8687 } else {
87- logger .warn ("Optimizely is not initialized, can't activate experiment {} for user {} " +
88+ logger .warn ("Optimizely is not initialized, could not activate experiment {} for user {} " +
8889 "with attributes" , experimentKey , userId );
8990 return null ;
9091 }
9192 }
9293
94+ /**
95+ * Get the {@link ProjectConfig} instance
96+ * @return the current {@link ProjectConfig} instance
97+ */
98+ public @ Nullable ProjectConfig getProjectConfig () {
99+ if (isValid ()) {
100+ return optimizely .getProjectConfig ();
101+ } else {
102+ logger .warn ("Optimizely is not initialized, could not get project config" );
103+ return null ;
104+ }
105+ }
106+
93107 /**
94108 * Check that this is a valid instance
95109 * @return True if the OptimizelyClient instance was instantiated correctly
@@ -105,7 +119,7 @@ public boolean isValid() {
105119 */
106120 public void track (@ NonNull String eventName ,
107121 @ NonNull String userId ) {
108- if (optimizely != null ) {
122+ if (isValid () ) {
109123 optimizely .track (eventName , userId );
110124 } else {
111125 logger .warn ("Optimizely is not initialized, could not track event {} for user {}" , eventName , userId );
@@ -121,7 +135,7 @@ public void track(@NonNull String eventName,
121135 public void track (@ NonNull String eventName ,
122136 @ NonNull String userId ,
123137 @ NonNull Map <String , String > attributes ) throws UnknownEventTypeException {
124- if (optimizely != null ) {
138+ if (isValid () ) {
125139 optimizely .track (eventName , userId , attributes );
126140
127141 } else {
@@ -141,7 +155,7 @@ public void track(@NonNull String eventName,
141155 @ NonNull String userId ,
142156 @ NonNull Map <String , String > attributes ,
143157 @ NonNull Map <String , ?> eventTags ) throws UnknownEventTypeException {
144- if (optimizely != null ) {
158+ if (isValid () ) {
145159 optimizely .track (eventName , userId , attributes , eventTags );
146160
147161 } else {
@@ -160,7 +174,7 @@ public void track(@NonNull String eventName,
160174 public void track (@ NonNull String eventName ,
161175 @ NonNull String userId ,
162176 long eventValue ) throws UnknownEventTypeException {
163- if (optimizely != null ) {
177+ if (isValid () ) {
164178 optimizely .track (eventName , userId , eventValue );
165179 } else {
166180 logger .warn ("Optimizely is not initialized, could not track event {} for user {}" +
@@ -181,7 +195,7 @@ public void track(@NonNull String eventName,
181195 @ NonNull String userId ,
182196 @ NonNull Map <String , String > attributes ,
183197 long eventValue ) {
184- if (optimizely != null ) {
198+ if (isValid () ) {
185199 optimizely .track (eventName , userId , attributes , eventValue );
186200 } else {
187201 logger .warn ("Optimizely is not initialized, could not track event {} for user {}" +
@@ -215,7 +229,7 @@ public void track(@NonNull String eventName,
215229 @ NonNull String userId ,
216230 @ NonNull Map <String , String > attributes ,
217231 boolean activateExperiment ) {
218- if (optimizely != null ) {
232+ if (isValid () ) {
219233 return optimizely .getVariableString (variableKey , userId , attributes ,
220234 activateExperiment );
221235 } else {
@@ -251,7 +265,7 @@ public void track(@NonNull String eventName,
251265 @ NonNull String userId ,
252266 @ NonNull Map <String , String > attributes ,
253267 boolean activateExperiment ) {
254- if (optimizely != null ) {
268+ if (isValid () ) {
255269 return optimizely .getVariableBoolean (variableKey , userId , attributes ,
256270 activateExperiment );
257271 } else {
@@ -287,7 +301,7 @@ public void track(@NonNull String eventName,
287301 @ NonNull String userId ,
288302 @ NonNull Map <String , String > attributes ,
289303 boolean activateExperiment ) {
290- if (optimizely != null ) {
304+ if (isValid () ) {
291305 return optimizely .getVariableInteger (variableKey , userId , attributes ,
292306 activateExperiment );
293307 } else {
@@ -323,7 +337,7 @@ public void track(@NonNull String eventName,
323337 @ NonNull String userId ,
324338 @ NonNull Map <String , String > attributes ,
325339 boolean activateExperiment ) {
326- if (optimizely != null ) {
340+ if (isValid () ) {
327341 return optimizely .getVariableDouble (variableKey , userId , attributes ,
328342 activateExperiment );
329343 } else {
@@ -343,7 +357,7 @@ public void track(@NonNull String eventName,
343357 @ SuppressWarnings ("WeakerAccess" )
344358 public @ Nullable Variation getVariation (@ NonNull String experimentKey ,
345359 @ NonNull String userId ) {
346- if (optimizely != null ) {
360+ if (isValid () ) {
347361 return optimizely .getVariation (experimentKey , userId );
348362 } else {
349363 logger .warn ("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -364,7 +378,7 @@ public void track(@NonNull String eventName,
364378 public @ Nullable Variation getVariation (@ NonNull String experimentKey ,
365379 @ NonNull String userId ,
366380 @ NonNull Map <String , String > attributes ) {
367- if (optimizely != null ) {
381+ if (isValid () ) {
368382 return optimizely .getVariation (experimentKey , userId , attributes );
369383 } else {
370384 logger .warn ("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -385,7 +399,7 @@ public void track(@NonNull String eventName,
385399 * @param listener listener to add
386400 */
387401 public void addNotificationListener (@ NonNull NotificationListener listener ) {
388- if (optimizely != null ) {
402+ if (isValid () ) {
389403 optimizely .addNotificationListener (listener );
390404 } else {
391405 logger .warn ("Optimizely is not initialized, could not add notification listener" );
@@ -398,7 +412,7 @@ public void addNotificationListener(@NonNull NotificationListener listener) {
398412 * @param listener listener to remove
399413 */
400414 public void removeNotificationListener (@ NonNull NotificationListener listener ) {
401- if (optimizely != null ) {
415+ if (isValid () ) {
402416 optimizely .removeNotificationListener (listener );
403417 } else {
404418 logger .warn ("Optimizely is not initialized, could not remove notification listener" );
@@ -409,7 +423,7 @@ public void removeNotificationListener(@NonNull NotificationListener listener) {
409423 * Remove all {@link NotificationListener} instances.
410424 */
411425 public void clearNotificationListeners () {
412- if (optimizely != null ) {
426+ if (isValid () ) {
413427 optimizely .clearNotificationListeners ();
414428 } else {
415429 logger .warn ("Optimizely is not initialized, could not clear notification listeners" );
0 commit comments