2121import java .util .ArrayList ;
2222import java .util .Collections ;
2323import java .util .HashMap ;
24- import java .util .HashSet ;
2524import java .util .List ;
2625import java .util .Map ;
27- import java .util .Set ;
28- import java .util .concurrent .ConcurrentHashMap ;
2926
3027import javax .annotation .Nonnull ;
3128import javax .annotation .Nullable ;
3229
3330/**
34- * HoldoutConfig manages collections of Holdout objects and their relationships to flags.
31+ * HoldoutConfig manages collections of Holdout objects.
32+ * All holdouts are global and apply to all flags.
3533 */
3634public class HoldoutConfig {
3735 private List <Holdout > allHoldouts ;
38- private List <Holdout > global ;
3936 private Map <String , Holdout > holdoutIdMap ;
40- private Map <String , List <Holdout >> flagHoldoutsMap ;
41- private Map <String , List <Holdout >> includedHoldouts ;
42- private Map <String , Set <Holdout >> excludedHoldouts ;
4337
4438 /**
4539 * Initializes a new HoldoutConfig with an empty list of holdouts.
@@ -55,91 +49,29 @@ public HoldoutConfig() {
5549 */
5650 public HoldoutConfig (@ Nonnull List <Holdout > allHoldouts ) {
5751 this .allHoldouts = new ArrayList <>(allHoldouts );
58- this .global = new ArrayList <>();
5952 this .holdoutIdMap = new HashMap <>();
60- this .flagHoldoutsMap = new ConcurrentHashMap <>();
61- this .includedHoldouts = new HashMap <>();
62- this .excludedHoldouts = new HashMap <>();
6353 updateHoldoutMapping ();
6454 }
6555
6656 /**
67- * Updates internal mappings of holdouts including the id map, global list,
68- * and per-flag inclusion/exclusion maps.
57+ * Updates internal mapping of holdout IDs to holdout objects.
6958 */
7059 private void updateHoldoutMapping () {
7160 holdoutIdMap .clear ();
7261 for (Holdout holdout : allHoldouts ) {
7362 holdoutIdMap .put (holdout .getId (), holdout );
7463 }
75-
76- flagHoldoutsMap .clear ();
77- global .clear ();
78- includedHoldouts .clear ();
79- excludedHoldouts .clear ();
80-
81- for (Holdout holdout : allHoldouts ) {
82- boolean hasIncludedFlags = !holdout .getIncludedFlags ().isEmpty ();
83- boolean hasExcludedFlags = !holdout .getExcludedFlags ().isEmpty ();
84-
85- if (!hasIncludedFlags && !hasExcludedFlags ) {
86- // Global holdout (applies to all flags)
87- global .add (holdout );
88- } else if (hasIncludedFlags ) {
89- // Holdout only applies to specific included flags
90- for (String flagId : holdout .getIncludedFlags ()) {
91- includedHoldouts .computeIfAbsent (flagId , k -> new ArrayList <>()).add (holdout );
92- }
93- } else {
94- // Global holdout with specific exclusions
95- global .add (holdout );
96-
97- for (String flagId : holdout .getExcludedFlags ()) {
98- excludedHoldouts .computeIfAbsent (flagId , k -> new HashSet <>()).add (holdout );
99- }
100- }
101- }
10264 }
10365
10466 /**
105- * Returns the applicable holdouts for the given flag ID by combining global holdouts
106- * (excluding any specified) and included holdouts, in that order.
107- * Caches the result for future calls.
67+ * Returns all holdouts for the given flag ID.
68+ * Since all holdouts are now global, this returns all holdouts.
10869 *
10970 * @param id The flag identifier
110- * @return A list of Holdout objects relevant to the given flag
71+ * @return A list of all Holdout objects
11172 */
11273 public List <Holdout > getHoldoutForFlag (@ Nonnull String id ) {
113- if (allHoldouts .isEmpty ()) {
114- return Collections .emptyList ();
115- }
116-
117- // Check cache and return persistent holdouts
118- if (flagHoldoutsMap .containsKey (id )) {
119- return flagHoldoutsMap .get (id );
120- }
121-
122- // Prioritize global holdouts first
123- List <Holdout > activeHoldouts = new ArrayList <>();
124- Set <Holdout > excluded = excludedHoldouts .getOrDefault (id , Collections .emptySet ());
125-
126- if (!excluded .isEmpty ()) {
127- for (Holdout holdout : global ) {
128- if (!excluded .contains (holdout )) {
129- activeHoldouts .add (holdout );
130- }
131- }
132- } else {
133- activeHoldouts .addAll (global );
134- }
135-
136- // Add included holdouts
137- activeHoldouts .addAll (includedHoldouts .getOrDefault (id , Collections .emptyList ()));
138-
139- // Cache the result
140- flagHoldoutsMap .put (id , activeHoldouts );
141-
142- return activeHoldouts ;
74+ return Collections .unmodifiableList (allHoldouts );
14375 }
14476
14577 /**
0 commit comments