@@ -53,7 +53,7 @@ public class OptimizelyClient {
53
53
private final Logger logger ;
54
54
55
55
@ Nullable private Optimizely optimizely ;
56
- @ NonNull private Map <String , String > defaultAttributes = new HashMap <>();
56
+ @ NonNull private Map <String , ? > defaultAttributes = new HashMap <>();
57
57
58
58
OptimizelyClient (@ Nullable Optimizely optimizely , @ NonNull Logger logger ) {
59
59
this .optimizely = optimizely ;
@@ -72,15 +72,15 @@ public class OptimizelyClient {
72
72
* This is set by the Optimizely manager and includes things like os version and sdk version.
73
73
* @param attrs a map of default attributes.
74
74
*/
75
- protected void setDefaultAttributes (@ NonNull Map <String , String > attrs ) {
75
+ protected void setDefaultAttributes (@ NonNull Map <String , ? > attrs ) {
76
76
this .defaultAttributes = attrs ;
77
77
}
78
78
79
79
/**
80
80
* Return the default attributes map
81
81
* @return the map of default attributes
82
82
*/
83
- public @ NonNull Map <String , String > getDefaultAttributes () {
83
+ public @ NonNull Map <String , ? > getDefaultAttributes () {
84
84
return this .defaultAttributes ;
85
85
}
86
86
@@ -90,11 +90,15 @@ protected void setDefaultAttributes(@NonNull Map<String, String> attrs) {
90
90
* @param attrs attributes that will be combined with default attributes.
91
91
* @return a new map of both the default attributes and attributes passed in.
92
92
*/
93
- private Map <String , String > getAllAttributes (@ NonNull Map <String , String > attrs ) {
94
- Map <String ,String > combinedMap = new HashMap <>(defaultAttributes );
93
+ private Map <String , ? > getAllAttributes (@ NonNull Map <String , ? > attrs ) {
94
+ Map <String , Object > combinedMap = new HashMap <>(defaultAttributes );
95
95
96
96
// this essentially overrides defaultAttributes if the attrs passed in have the same key.
97
- combinedMap .putAll (attrs );
97
+ if (attrs != null ) {
98
+ combinedMap .putAll (attrs );
99
+ } else if (combinedMap .isEmpty ()) {
100
+ combinedMap = null ;
101
+ }
98
102
99
103
return combinedMap ;
100
104
}
@@ -128,7 +132,7 @@ private Map<String, String> getAllAttributes(@NonNull Map<String, String> attrs)
128
132
@ SuppressWarnings ("WeakerAccess" )
129
133
public @ Nullable Variation activate (@ NonNull String experimentKey ,
130
134
@ NonNull String userId ,
131
- @ NonNull Map <String , String > attributes ) {
135
+ @ NonNull Map <String , ? > attributes ) {
132
136
if (isValid ()) {
133
137
return optimizely .activate (experimentKey , userId , getAllAttributes (attributes ));
134
138
} else {
@@ -156,7 +160,10 @@ private Map<String, String> getAllAttributes(@NonNull Map<String, String> attrs)
156
160
* @return True if the OptimizelyClient instance was instantiated correctly
157
161
*/
158
162
public boolean isValid () {
159
- return optimizely != null ;
163
+ if (optimizely != null )
164
+ return optimizely .isValid ();
165
+ else
166
+ return false ;
160
167
}
161
168
162
169
/**
@@ -185,7 +192,7 @@ public void track(@NonNull String eventName,
185
192
*/
186
193
public void track (@ NonNull String eventName ,
187
194
@ NonNull String userId ,
188
- @ NonNull Map <String , String > attributes ) throws UnknownEventTypeException {
195
+ @ NonNull Map <String , ? > attributes ) throws UnknownEventTypeException {
189
196
if (isValid ()) {
190
197
optimizely .track (eventName , userId , getAllAttributes (attributes ));
191
198
@@ -204,7 +211,7 @@ public void track(@NonNull String eventName,
204
211
*/
205
212
public void track (@ NonNull String eventName ,
206
213
@ NonNull String userId ,
207
- @ NonNull Map <String , String > attributes ,
214
+ @ NonNull Map <String , ? > attributes ,
208
215
@ NonNull Map <String , ?> eventTags ) throws UnknownEventTypeException {
209
216
if (isValid ()) {
210
217
optimizely .track (eventName , userId , getAllAttributes (attributes ), eventTags );
@@ -245,7 +252,7 @@ public void track(@NonNull String eventName,
245
252
@ SuppressWarnings ("WeakerAccess" )
246
253
public @ Nullable Variation getVariation (@ NonNull String experimentKey ,
247
254
@ NonNull String userId ,
248
- @ NonNull Map <String , String > attributes ) {
255
+ @ NonNull Map <String , ? > attributes ) {
249
256
if (isValid ()) {
250
257
return optimizely .getVariation (experimentKey , userId , getAllAttributes (attributes ));
251
258
} else {
@@ -310,7 +317,7 @@ public boolean setForcedVariation(@NonNull String experimentKey,
310
317
* @return List of the feature keys that are enabled for the user if the userId is empty it will
311
318
* return Empty List.
312
319
*/
313
- public List <String > getEnabledFeatures (@ NonNull String userId , @ NonNull Map <String , String > attributes ) {
320
+ public List <String > getEnabledFeatures (@ NonNull String userId , @ NonNull Map <String , ? > attributes ) {
314
321
if (isValid ()) {
315
322
return optimizely .getEnabledFeatures (userId , attributes );
316
323
} else {
@@ -355,7 +362,7 @@ Boolean isFeatureEnabled(@NonNull String featureKey,
355
362
*/
356
363
public @ NonNull Boolean isFeatureEnabled (@ NonNull String featureKey ,
357
364
@ NonNull String userId ,
358
- @ NonNull Map <String , String > attributes ) {
365
+ @ NonNull Map <String , ? > attributes ) {
359
366
if (isValid ()) {
360
367
return optimizely .isFeatureEnabled (featureKey , userId , attributes );
361
368
} else {
@@ -401,7 +408,7 @@ Boolean getFeatureVariableBoolean(@NonNull String featureKey,
401
408
Boolean getFeatureVariableBoolean (@ NonNull String featureKey ,
402
409
@ NonNull String variableKey ,
403
410
@ NonNull String userId ,
404
- @ NonNull Map <String , String > attributes ) {
411
+ @ NonNull Map <String , ? > attributes ) {
405
412
if (isValid ()) {
406
413
return optimizely .getFeatureVariableBoolean (featureKey , variableKey , userId , attributes );
407
414
} else {
@@ -445,7 +452,7 @@ Double getFeatureVariableDouble(@NonNull String featureKey,
445
452
Double getFeatureVariableDouble (@ NonNull String featureKey ,
446
453
@ NonNull String variableKey ,
447
454
@ NonNull String userId ,
448
- @ NonNull Map <String , String > attributes ) {
455
+ @ NonNull Map <String , ? > attributes ) {
449
456
if (isValid ()) {
450
457
return optimizely .getFeatureVariableDouble (featureKey , variableKey , userId , attributes );
451
458
} else {
@@ -489,7 +496,7 @@ Integer getFeatureVariableInteger(@NonNull String featureKey,
489
496
Integer getFeatureVariableInteger (@ NonNull String featureKey ,
490
497
@ NonNull String variableKey ,
491
498
@ NonNull String userId ,
492
- @ NonNull Map <String , String > attributes ) {
499
+ @ NonNull Map <String , ? > attributes ) {
493
500
if (isValid ()) {
494
501
return optimizely .getFeatureVariableInteger (featureKey , variableKey , userId , attributes );
495
502
} else {
@@ -533,7 +540,7 @@ String getFeatureVariableString(@NonNull String featureKey,
533
540
String getFeatureVariableString (@ NonNull String featureKey ,
534
541
@ NonNull String variableKey ,
535
542
@ NonNull String userId ,
536
- @ NonNull Map <String , String > attributes ) {
543
+ @ NonNull Map <String , ? > attributes ) {
537
544
if (isValid ()) {
538
545
return optimizely .getFeatureVariableString (featureKey , variableKey , userId , attributes );
539
546
} else {
0 commit comments