Skip to content

Commit

Permalink
Refact: Copying attributes into new copiedAttributes variable (#227)
Browse files Browse the repository at this point in the history
* Refact: Copying attributes into new copiedAttributes variable

* changed description of copyAttribute function
  • Loading branch information
mnoman09 authored and thomaszurkan-optimizely committed Nov 7, 2018
1 parent b9a75d9 commit f42e3ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ else if (userId == null) {
logger.info("No feature flag was found for key \"{}\".", featureKey);
return false;
}

Map<String, ?> copiedAttributes = copyAttributes(attributes);
FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);

if (featureDecision.variation != null) {
if (featureDecision.decisionSource.equals(FeatureDecision.DecisionSource.EXPERIMENT)) {
sendImpression(
Expand Down Expand Up @@ -647,7 +649,6 @@ else if (userId == null) {

String variableValue = variable.getDefaultValue();
Map<String, ?> copiedAttributes = copyAttributes(attributes);

FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);
if (featureDecision.variation != null) {
LiveVariableUsageInstance liveVariableUsageInstance =
Expand Down Expand Up @@ -686,9 +687,10 @@ public List<String> getEnabledFeatures(@Nonnull String userId, @Nonnull Map<Stri
return enabledFeaturesList;
}

Map<String, ?> copiedAttributes = copyAttributes(attributes);
for (FeatureFlag featureFlag : projectConfig.getFeatureFlags()){
String featureKey = featureFlag.getKey();
if(isFeatureEnabled(featureKey, userId, attributes))
if(isFeatureEnabled(featureKey, userId, copiedAttributes))
enabledFeaturesList.add(featureKey);
}

Expand Down Expand Up @@ -826,9 +828,9 @@ private boolean validateUserId(String userId) {
}

/**
* Helper function to check that the provided attributes are null if not than it returns a copy
* Helper method which makes separate copy of attributesMap variable and returns it
*
* @param attributes the attributes map being validated
* @param attributes map to copy
* @return copy of attributes
*/
private Map<String, ?> copyAttributes(Map<String, ?> attributes) {
Expand Down

0 comments on commit f42e3ad

Please sign in to comment.