/****************************************************************************
 * Copyright 2018-2019, Optimizely, Inc. and contributors                   *
 *                                                                          *
 * Licensed under the Apache License, Version 2.0 (the "License");          *
 * you may not use this file except in compliance with the License.         *
 * You may obtain a copy of the License at                                  *
 *                                                                          *
 *    http://www.apache.org/licenses/LICENSE-2.0                            *
 *                                                                          *
 * Unless required by applicable law or agreed to in writing, software      *
 * distributed under the License is distributed on an "AS IS" BASIS,        *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 * See the License for the specific language governing permissions and      *
 * limitations under the License.                                           *
 ***************************************************************************/
package com.optimizely;

import com.optimizely.ab.Optimizely;
import com.optimizely.ab.OptimizelyFactory;
import com.optimizely.ab.config.Variation;

import java.util.Collections;
import java.util.Map;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Example {

    private final Optimizely optimizely;

    private Example(Optimizely optimizely) {
        this.optimizely = optimizely;
    }

    private void processVisitor(String userId, Map<String, String> attributes) {
        Variation variation = optimizely.activate("background_experiment", userId, attributes);

        if (variation != null) {
            optimizely.track("sample_conversion", userId, attributes);
            System.out.println(String.format("Found variation %s", variation.getKey()));
        }
        else {
            System.out.println("didn't get a variation");
        }

        if (optimizely.isFeatureEnabled("eet_feature", userId, attributes)) {
            optimizely.track("eet_conversion", userId, attributes);
            System.out.println("feature enabled");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Optimizely optimizely = OptimizelyFactory.newDefaultInstance("BX9Y3bTa4YErpHZEMpAwHm");

        Example example = new Example(optimizely);
        Random random = new Random();

        for (int i = 0; i < 10; i++) {
            String userId = String.valueOf(random.nextInt());
            example.processVisitor(userId, Collections.emptyMap());
            TimeUnit.MILLISECONDS.sleep(500);
        }
    }
}

@@ -1298,24 +1298,149 @@
 .ab.
-config.Variation
+OptimizelyUserContext;%0Aimport com.optimizely.ab.optimizelydecision.OptimizelyDecision;%0Aimport com.optimizely.ab.optimizelyjson.OptimizelyJSON
 ;%0A%0Ai
@@ -1490,17 +1490,16 @@
 il.Map;%0A
-%0A
 import j
@@ -1769,22 +1769,22 @@
 String, 
-String
+Object
 %3E attrib
@@ -1803,289 +1803,248 @@
     
-Variation variation = optimizely.activate(%22background_experiment%22, userId, attributes);%0A%0A        if (variation != null) %7B%0A            optimizely.track(%22sample_conver
+OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);%0A%0A        OptimizelyDecision deci
 sion
-%22,
+ =
  user
-Id, attributes);%0A            System.out.println(String.format(%22Found variation %25s%22, variation.getKey()));
+.decide(%22eet_feature%22);%0A        String variationKey = decision.getVariationKey();%0A%0A        if (variationKey != null) %7B
 %0A   
@@ -2052,91 +2052,135 @@
     
-%7D%0A
     
-    else %7B%0A            System.out.println(%22didn't get a variation%22
+boolean enabled = decision.getEnabled();%0A            System.out.println(%22%5BExample%5D feature enabled: %22 + enabled
 );%0A
+%0A
         
 %7D%0A%0A 
@@ -2179,88 +2179,152 @@
     
-%7D%0A%0A
     
-    if (optimizely.isFeatureEnabled(%22eet_feature%22, userId, attributes)) %7B
+OptimizelyJSON variables = decision.getVariables();%0A            System.out.println(%22%5BExample%5D feature variables: %22 + variables.toString());%0A
 %0A   
@@ -2336,24 +2336,23 @@
     
-optimizely
+user
 .track
+Event
 (%22ee
@@ -2368,30 +2368,35 @@
 ion%22
-, userId, attributes);
+);%0A        %7D%0A        else %7B
 %0A   
@@ -2428,24 +2428,71 @@
 ln(%22
-feature enabled%22
+%5BExample%5D decision failed: %22 + decision.getReasons().toString()
 );%0A 
@@ -2864,16 +2864,33 @@
 nextInt(
+Integer.MAX_VALUE
 ));%0A    

fix sample codes to use decide apis (#414)