public class

OptimizelyCodeBlock

extends Object
java.lang.Object
   ↳ com.optimizely.CodeBlocks.OptimizelyCodeBlock

Class Overview

Code Blocks allow developers to create variations that execute different code paths. CodeBlocks are declared as static variables and then can be accessed anywhere in your application. When #execute(DefaultCodeBranch, CodeBranch...)} is called only one branch (represented by a CodeBranch) will be executed. To use a codeblock, first define your CodeBlock with al possible branch names as a static variable, using Optimizely.codeBlockWithBranchNames(String, String...) and then call #execute(DefaultCodeBranch, CodeBranch...) on the instance with default code block and each of the possible branch code block.

Summary

Nested Classes
interface OptimizelyCodeBlock.Callback  
Public Methods
void execute(DefaultCodeBranch defaultCodeBlock, CodeBranch... codeBranches)
First initialize the code block with provided code block definitions and then executes the correct code block depending on the active variation and experiments as stored in OptimizelyData.
Pair<String, CodeBranch> findActiveCodeBlock()
Iterates through all the active experiments/variations to find if any of the code blocks from blockKeys is active.
String getBlockName()
Set<String> getBranchNames()
String getDefaultBranchName()
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void execute (DefaultCodeBranch defaultCodeBlock, CodeBranch... codeBranches)

First initialize the code block with provided code block definitions and then executes the correct code block depending on the active variation and experiments as stored in OptimizelyData. Also locks the code block to make sure in future re-executions, only this code block is executed again. In Editor mode, notifies the socket about discovery of a new code block.

Parameters
defaultCodeBlock default code block logic.
codeBranches list of code block definition with branchNames.

public Pair<String, CodeBranch> findActiveCodeBlock ()

Iterates through all the active experiments/variations to find if any of the code blocks from blockKeys is active. If yes, returns that else returns default code block.

Returns
  • active code block which might be null.

public String getBlockName ()

Returns
  • the name of this block which will show as the block label in the editor

public Set<String> getBranchNames ()

Returns
  • a list of the block names which will show in the dropdown list in the editor

public String getDefaultBranchName ()

Returns
  • the name of the default block