2323import javax .annotation .Nonnull ;
2424import javax .annotation .Nullable ;
2525import javax .annotation .concurrent .Immutable ;
26+ import java .util .Arrays ;
2627import java .util .Collections ;
28+ import java .util .HashSet ;
2729import java .util .List ;
2830import java .util .Map ;
31+ import java .util .Set ;
2932
3033/**
3134 * Represents the Optimizely Experiment configuration.
3639@ JsonIgnoreProperties (ignoreUnknown = true )
3740public class Experiment implements ExperimentCore {
3841
42+ /**
43+ * The set of experiment types supported by this SDK.
44+ * Experiments with a type not in this set will be skipped during flag decisions.
45+ * If an experiment has no type (null), it is still evaluated.
46+ */
47+ public static final Set <String > SUPPORTED_TYPES = Collections .unmodifiableSet (
48+ new HashSet <>(Arrays .asList ("a/b" , "mab" , "cmab" , "feature_rollouts" ))
49+ );
50+
3951 private final String id ;
4052 private final String key ;
53+ private final String type ;
4154 private final String status ;
4255 private final String layerId ;
4356 private final String groupId ;
@@ -72,30 +85,40 @@ public String toString() {
7285
7386 @ VisibleForTesting
7487 public Experiment (String id , String key , String layerId ) {
75- this (id , key , null , layerId , Collections .emptyList (), null , Collections .emptyList (), Collections .emptyMap (), Collections .emptyList (), "" , null );
88+ this (id , key , null , null , layerId , Collections .emptyList (), null , Collections .emptyList (), Collections .emptyMap (), Collections .emptyList (), "" , null );
7689 }
7790
7891 @ VisibleForTesting
7992 public Experiment (String id , String key , String status , String layerId ,
8093 List <String > audienceIds , Condition audienceConditions ,
8194 List <Variation > variations , Map <String , String > userIdToVariationKeyMap ,
8295 List <TrafficAllocation > trafficAllocation , String groupId ) {
83- this (id , key , status , layerId , audienceIds , audienceConditions , variations ,
84- userIdToVariationKeyMap , trafficAllocation , groupId , null ); // Default cmab=null
96+ this (id , key , null , status , layerId , audienceIds , audienceConditions , variations ,
97+ userIdToVariationKeyMap , trafficAllocation , groupId , null ); // Default type=null, cmab=null
8598 }
8699
87100 @ VisibleForTesting
88101 public Experiment (String id , String key , String status , String layerId ,
89102 List <String > audienceIds , Condition audienceConditions ,
90103 List <Variation > variations , Map <String , String > userIdToVariationKeyMap ,
91104 List <TrafficAllocation > trafficAllocation ) {
92- this (id , key , status , layerId , audienceIds , audienceConditions , variations ,
93- userIdToVariationKeyMap , trafficAllocation , "" , null ); // Default groupId="" and cmab=null
105+ this (id , key , null , status , layerId , audienceIds , audienceConditions , variations ,
106+ userIdToVariationKeyMap , trafficAllocation , "" , null ); // Default type=null, groupId="" and cmab=null
107+ }
108+
109+ @ VisibleForTesting
110+ public Experiment (String id , String key , String status , String layerId ,
111+ List <String > audienceIds , Condition audienceConditions ,
112+ List <Variation > variations , Map <String , String > userIdToVariationKeyMap ,
113+ List <TrafficAllocation > trafficAllocation , Cmab cmab ) {
114+ this (id , key , null , status , layerId , audienceIds , audienceConditions , variations ,
115+ userIdToVariationKeyMap , trafficAllocation , "" , cmab ); // Default type=null, groupId=""
94116 }
95117
96118 @ JsonCreator
97119 public Experiment (@ JsonProperty ("id" ) String id ,
98120 @ JsonProperty ("key" ) String key ,
121+ @ JsonProperty ("type" ) String type ,
99122 @ JsonProperty ("status" ) String status ,
100123 @ JsonProperty ("layerId" ) String layerId ,
101124 @ JsonProperty ("audienceIds" ) List <String > audienceIds ,
@@ -104,11 +127,12 @@ public Experiment(@JsonProperty("id") String id,
104127 @ JsonProperty ("forcedVariations" ) Map <String , String > userIdToVariationKeyMap ,
105128 @ JsonProperty ("trafficAllocation" ) List <TrafficAllocation > trafficAllocation ,
106129 @ JsonProperty ("cmab" ) Cmab cmab ) {
107- this (id , key , status , layerId , audienceIds , audienceConditions , variations , userIdToVariationKeyMap , trafficAllocation , "" , cmab );
130+ this (id , key , type , status , layerId , audienceIds , audienceConditions , variations , userIdToVariationKeyMap , trafficAllocation , "" , cmab );
108131 }
109132
110133 public Experiment (@ Nonnull String id ,
111134 @ Nonnull String key ,
135+ @ Nullable String type ,
112136 @ Nullable String status ,
113137 @ Nullable String layerId ,
114138 @ Nonnull List <String > audienceIds ,
@@ -120,6 +144,7 @@ public Experiment(@Nonnull String id,
120144 @ Nullable Cmab cmab ) {
121145 this .id = id ;
122146 this .key = key ;
147+ this .type = type ;
123148 this .status = status == null ? ExperimentStatus .NOT_STARTED .toString () : status ;
124149 this .layerId = layerId ;
125150 this .audienceIds = Collections .unmodifiableList (audienceIds );
@@ -141,6 +166,11 @@ public String getKey() {
141166 return key ;
142167 }
143168
169+ @ Nullable
170+ public String getType () {
171+ return type ;
172+ }
173+
144174 public String getStatus () {
145175 return status ;
146176 }
@@ -203,6 +233,7 @@ public String toString() {
203233 return "Experiment{" +
204234 "id='" + id + '\'' +
205235 ", key='" + key + '\'' +
236+ ", type='" + type + '\'' +
206237 ", groupId='" + groupId + '\'' +
207238 ", status='" + status + '\'' +
208239 ", audienceIds=" + audienceIds +
0 commit comments