|
27 | 27 |
|
28 | 28 | import org.slf4j.Logger;
|
29 | 29 |
|
| 30 | +import java.util.Collections; |
30 | 31 | import java.util.Map;
|
31 | 32 |
|
32 | 33 | /**
|
@@ -165,6 +166,150 @@ public void track(@NonNull String eventName,
|
165 | 166 | }
|
166 | 167 | }
|
167 | 168 |
|
| 169 | + /** |
| 170 | + * Get the value of a String live variable |
| 171 | + * @param variableKey the String key for the variable |
| 172 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 173 | + * @param userId the user ID |
| 174 | + * @return String value of the live variable |
| 175 | + */ |
| 176 | + public @Nullable String getVariableString(@NonNull String variableKey, |
| 177 | + boolean activateExperiment, |
| 178 | + @NonNull String userId) { |
| 179 | + return getVariableString(variableKey, activateExperiment, userId, |
| 180 | + Collections.<String, String>emptyMap()); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Get the value of a String live variable |
| 185 | + * @param variableKey the String key for the variable |
| 186 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 187 | + * @param userId the user ID |
| 188 | + * @param attributes a map of attributes about the user |
| 189 | + * @return String value of the live variable |
| 190 | + */ |
| 191 | + public @Nullable String getVariableString(@NonNull String variableKey, |
| 192 | + boolean activateExperiment, |
| 193 | + @NonNull String userId, |
| 194 | + @NonNull Map<String, String> attributes) { |
| 195 | + if (optimizely != null) { |
| 196 | + return optimizely.getVariableString(variableKey, activateExperiment, userId, |
| 197 | + attributes); |
| 198 | + } else { |
| 199 | + logger.warn("Optimizely is not initialized, could not get live variable {} " + |
| 200 | + "for user {}", variableKey, userId); |
| 201 | + return null; |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * Get the value of a Boolean live variable |
| 207 | + * @param variableKey the String key for the variable |
| 208 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 209 | + * @param userId the user ID |
| 210 | + * @return Boolean value of the live variable |
| 211 | + */ |
| 212 | + public @Nullable Boolean getVariableBoolean(@NonNull String variableKey, |
| 213 | + boolean activateExperiment, |
| 214 | + @NonNull String userId) { |
| 215 | + return getVariableBoolean(variableKey, activateExperiment, userId, |
| 216 | + Collections.<String, String>emptyMap()); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Get the value of a Boolean live variable |
| 221 | + * @param variableKey the String key for the variable |
| 222 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 223 | + * @param userId the user ID |
| 224 | + * @param attributes a map of attributes about the user |
| 225 | + * @return Boolean value of the live variable |
| 226 | + */ |
| 227 | + public @Nullable Boolean getVariableBoolean(@NonNull String variableKey, |
| 228 | + boolean activateExperiment, |
| 229 | + @NonNull String userId, |
| 230 | + @NonNull Map<String, String> attributes) { |
| 231 | + if (optimizely != null) { |
| 232 | + return optimizely.getVariableBoolean(variableKey, activateExperiment, userId, |
| 233 | + attributes); |
| 234 | + } else { |
| 235 | + logger.warn("Optimizely is not initialized, could not get live variable {} " + |
| 236 | + "for user {}", variableKey, userId); |
| 237 | + return null; |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * Get the value of a Integer live variable |
| 243 | + * @param variableKey the String key for the variable |
| 244 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 245 | + * @param userId the user ID |
| 246 | + * @return Integer value of the live variable |
| 247 | + */ |
| 248 | + public @Nullable Integer getVariableInteger(@NonNull String variableKey, |
| 249 | + boolean activateExperiment, |
| 250 | + @NonNull String userId) { |
| 251 | + return getVariableInteger(variableKey, activateExperiment, userId, |
| 252 | + Collections.<String, String>emptyMap()); |
| 253 | + } |
| 254 | + |
| 255 | + /** |
| 256 | + * Get the value of a Integer live variable |
| 257 | + * @param variableKey the String key for the variable |
| 258 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 259 | + * @param userId the user ID |
| 260 | + * @param attributes a map of attributes about the user |
| 261 | + * @return Integer value of the live variable |
| 262 | + */ |
| 263 | + public @Nullable Integer getVariableInteger(@NonNull String variableKey, |
| 264 | + boolean activateExperiment, |
| 265 | + @NonNull String userId, |
| 266 | + @NonNull Map<String, String> attributes) { |
| 267 | + if (optimizely != null) { |
| 268 | + return optimizely.getVariableInteger(variableKey, activateExperiment, userId, |
| 269 | + attributes); |
| 270 | + } else { |
| 271 | + logger.warn("Optimizely is not initialized, could not get live variable {} " + |
| 272 | + "for user {}", variableKey, userId); |
| 273 | + return null; |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * Get the value of a Float live variable |
| 279 | + * @param variableKey the String key for the variable |
| 280 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 281 | + * @param userId the user ID |
| 282 | + * @return Float value of the live variable |
| 283 | + */ |
| 284 | + public @Nullable Float getVariableFloat(@NonNull String variableKey, |
| 285 | + boolean activateExperiment, |
| 286 | + @NonNull String userId) { |
| 287 | + return getVariableFloat(variableKey, activateExperiment, userId, |
| 288 | + Collections.<String, String>emptyMap()); |
| 289 | + } |
| 290 | + |
| 291 | + /** |
| 292 | + * Get the value of a Float live variable |
| 293 | + * @param variableKey the String key for the variable |
| 294 | + * @param activateExperiment the flag denoting whether to activate an experiment or not |
| 295 | + * @param userId the user ID |
| 296 | + * @param attributes a map of attributes about the user |
| 297 | + * @return Float value of the live variable |
| 298 | + */ |
| 299 | + public @Nullable Float getVariableFloat(@NonNull String variableKey, |
| 300 | + boolean activateExperiment, |
| 301 | + @NonNull String userId, |
| 302 | + @NonNull Map<String, String> attributes) { |
| 303 | + if (optimizely != null) { |
| 304 | + return optimizely.getVariableFloat(variableKey, activateExperiment, userId, |
| 305 | + attributes); |
| 306 | + } else { |
| 307 | + logger.warn("Optimizely is not initialized, could not get live variable {} " + |
| 308 | + "for user {}", variableKey, userId); |
| 309 | + return null; |
| 310 | + } |
| 311 | + } |
| 312 | + |
168 | 313 | /**
|
169 | 314 | * Get the variation the user is bucketed into
|
170 | 315 | * @see Optimizely#getVariation(Experiment, String)
|
|
0 commit comments