Skip to content

Commit 8fc3cb7

Browse files
author
Varun Rathore
committed
Resolve comments related to Evaluator
1 parent a0b71bd commit 8fc3cb7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/com/google/firebase/remoteconfig/ConditionEvaluator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121

2222
import com.google.common.collect.ImmutableList;
23+
import com.google.common.collect.ImmutableMap;
2324
import com.google.firebase.internal.NonNull;
2425
import com.google.firebase.internal.Nullable;
2526

@@ -57,12 +58,15 @@ Map<String, Boolean> evaluateConditions(
5758
@Nullable KeysAndValues context) {
5859
checkNotNull(conditions, "List of conditions must not be null.");
5960
checkArgument(!conditions.isEmpty(), "List of conditions must not be empty.");
61+
if(context == null || conditions.isEmpty()){
62+
return ImmutableMap.of();
63+
}
6064
KeysAndValues evaluationContext = context != null
6165
? context
6266
: new KeysAndValues.Builder().build();
6367

6468
Map<String, Boolean> evaluatedConditions = conditions.stream()
65-
.collect(Collectors.toMap(
69+
.collect(ImmutableMap.toImmutableMap(
6670
ServerCondition::getName,
6771
condition ->
6872
evaluateCondition(condition.getCondition(), evaluationContext, /* nestingLevel= */0)

src/main/java/com/google/firebase/remoteconfig/ServerTemplateImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,8 @@ public ServerConfig evaluate(@Nullable KeysAndValues context)
9393
}
9494

9595
ConditionEvaluator conditionEvaluator = new ConditionEvaluator();
96-
ImmutableMap<String, Boolean> evaluatedCondition =
97-
context != null && !cache.getServerConditions().isEmpty()
98-
? ImmutableMap.copyOf(
99-
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context))
100-
: ImmutableMap.of();
96+
ImmutableMap<String, Boolean> evaluatedCondition = ImmutableMap.copyOf(
97+
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context));
10198
ImmutableMap<String, Parameter> parameters = ImmutableMap.copyOf(cache.getParameters());
10299
mergeDerivedConfigValues(evaluatedCondition, parameters, configValues);
103100

0 commit comments

Comments
 (0)