-
Notifications
You must be signed in to change notification settings - Fork 23
Updated Evaluator #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Updated Evaluator #541
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
380bcc3
Updated Evaluator
chillaq f7bea94
Update client/src/main/java/io/split/client/SplitFactoryImpl.java
chillaq a9982a9
Added unit test for RBS matcher
chillaq b607793
Merge branch 'rbs-evaluator' of https://github.com/splitio/java-clien…
chillaq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
client/src/main/java/io/split/engine/matchers/RuleBasedSegmentMatcher.java
This file contains hidden or 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,83 @@ | ||
| package io.split.engine.matchers; | ||
|
|
||
| import io.split.engine.evaluator.EvaluationContext; | ||
| import io.split.engine.experiments.ParsedCondition; | ||
| import io.split.engine.experiments.ParsedRuleBasedSegment; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * A matcher that checks if the key is part of a user defined segment. This class | ||
| * assumes that the logic for refreshing what keys are part of a segment is delegated | ||
| * to SegmentFetcher. | ||
| * | ||
| * @author adil | ||
| */ | ||
| public class RuleBasedSegmentMatcher implements Matcher { | ||
| private final String _segmentName; | ||
|
|
||
| public RuleBasedSegmentMatcher(String segmentName) { | ||
| _segmentName = checkNotNull(segmentName); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean match(Object matchValue, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) { | ||
| if (!(matchValue instanceof String)) { | ||
| return false; | ||
| } | ||
| ParsedRuleBasedSegment parsedRuleBasedSegment = evaluationContext.getRuleBasedSegmentCache().get(_segmentName); | ||
| if (parsedRuleBasedSegment == null) { | ||
| return false; | ||
| } | ||
|
|
||
| if (parsedRuleBasedSegment.excludedKeys().contains(matchValue)) { | ||
| return false; | ||
| } | ||
|
|
||
| for (String segmentName: parsedRuleBasedSegment.excludedSegments()) { | ||
| if (evaluationContext.getSegmentCache().isInSegment(segmentName, (String) matchValue)) { | ||
| return false; | ||
| } | ||
| } | ||
| List<ParsedCondition> conditions = parsedRuleBasedSegment.parsedConditions(); | ||
| for (ParsedCondition parsedCondition : conditions) { | ||
| if (parsedCondition.matcher().match((String) matchValue, bucketingKey, attributes, evaluationContext)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result = 17; | ||
| result = 31 * result + _segmentName.hashCode(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj == null) return false; | ||
| if (this == obj) return true; | ||
| if (!(obj instanceof RuleBasedSegmentMatcher)) return false; | ||
|
|
||
| RuleBasedSegmentMatcher other = (RuleBasedSegmentMatcher) obj; | ||
|
|
||
| return _segmentName.equals(other._segmentName); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder bldr = new StringBuilder(); | ||
| bldr.append("in segment "); | ||
| bldr.append(_segmentName); | ||
| return bldr.toString(); | ||
| } | ||
|
|
||
| public String getSegmentName() { | ||
| return _segmentName; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.