-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By name filter in feature flag processor (#536)
- Loading branch information
Showing
11 changed files
with
227 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/io/split/android/client/service/splits/FeatureFlagProcessStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.split.android.client.service.splits; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.List; | ||
|
||
import io.split.android.client.dtos.Split; | ||
import io.split.android.client.dtos.Status; | ||
|
||
interface FeatureFlagProcessStrategy { | ||
|
||
void process(List<Split> activeFeatureFlags, List<Split> archivedFeatureFlags, Split featureFlag); | ||
} | ||
|
||
class StatusProcessStrategy implements FeatureFlagProcessStrategy { | ||
|
||
@Override | ||
public void process(List<Split> activeFeatureFlags, List<Split> archivedFeatureFlags, Split featureFlag) { | ||
if (featureFlag.status == Status.ACTIVE) { | ||
activeFeatureFlags.add(featureFlag); | ||
} else { | ||
archivedFeatureFlags.add(featureFlag); | ||
} | ||
} | ||
} | ||
|
||
class NamesProcessStrategy implements FeatureFlagProcessStrategy { | ||
|
||
private final List<String> mConfiguredValues; | ||
private final StatusProcessStrategy mStatusProcessStrategy; | ||
|
||
NamesProcessStrategy(@NonNull List<String> configuredValues, @NonNull StatusProcessStrategy statusProcessStrategy) { | ||
mConfiguredValues = configuredValues; | ||
mStatusProcessStrategy = statusProcessStrategy; | ||
} | ||
|
||
@Override | ||
public void process(List<Split> activeFeatureFlags, List<Split> archivedFeatureFlags, Split featureFlag) { | ||
// If the feature flag name is in the filter, we process it according to its status. Otherwise it is ignored | ||
if (mConfiguredValues.contains(featureFlag.name)) { | ||
mStatusProcessStrategy.process(activeFeatureFlags, archivedFeatureFlags, featureFlag); | ||
} | ||
} | ||
} | ||
|
||
class SetsProcessStrategy implements FeatureFlagProcessStrategy { | ||
|
||
private final List<String> mConfiguredValues; | ||
private final StatusProcessStrategy mStatusProcessStrategy; | ||
|
||
SetsProcessStrategy(@NonNull List<String> configuredValues, @NonNull StatusProcessStrategy statusProcessStrategy) { | ||
mConfiguredValues = configuredValues; | ||
mStatusProcessStrategy = statusProcessStrategy; | ||
} | ||
|
||
@Override | ||
public void process(List<Split> activeFeatureFlags, List<Split> archivedFeatureFlags, Split featureFlag) { | ||
if (featureFlag.sets == null || featureFlag.sets.isEmpty()) { | ||
archivedFeatureFlags.add(featureFlag); | ||
return; | ||
} | ||
|
||
boolean shouldArchive = true; | ||
for (String set : featureFlag.sets) { | ||
if (mConfiguredValues.contains(set)) { | ||
// If the feature flag has at least one set that matches the configured sets, | ||
// we process it according to its status | ||
mStatusProcessStrategy.process(activeFeatureFlags, archivedFeatureFlags, featureFlag); | ||
shouldArchive = false; | ||
break; | ||
} | ||
} | ||
|
||
if (shouldArchive) { | ||
archivedFeatureFlags.add(featureFlag); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.