-
Notifications
You must be signed in to change notification settings - Fork 32
Add MatchRegistry for custom match implementations. #390
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
Conversation
Pull Request Test Coverage Report for Build 1544
💛 - Coveralls |
Currently failing a single scenario in the FSC: |
1743c70
to
f30e088
Compare
ba30742
to
fd41198
Compare
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. few nits
private static final Map<String, Match> registry = new ConcurrentHashMap<>(); | ||
public static final String EXISTS = "exists"; | ||
public static final String EXACT = "exact"; | ||
public static final String GREATER_THAN = "gt"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetize.
throw new UnknownValueTypeException(); | ||
} | ||
|
||
if (!isValidNumber(o2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge into the above if
condition?
return compareUnsafe(o1, o2); | ||
} | ||
|
||
public static int compareUnsafe(Object o1, Object o2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc string will be helpful here.
@@ -18,11 +18,9 @@ | |||
|
|||
import javax.annotation.Nullable; | |||
|
|||
class SubstringMatch extends AttributeMatch<String> { | |||
String value; | |||
class SubstringMatch implements Match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update Copyright year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great. One change suggested.
@@ -20,5 +20,5 @@ | |||
|
|||
public interface Match { | |||
@Nullable | |||
Boolean eval(Object attributeValue); | |||
Boolean eval(Object conditionValue, Object attributeValue) throws UnexpectedValueTypeException, UnknownValueTypeException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need separate exception types for UnexpectedValueTypeException and UnknownValueTypeException?
They're similar and not much gain for additional complexity to differentiate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for backwards compatibility, albeit I can update the names perhaps. The difference is in the logging behavior. One error is communicated as an SDK compatibility issue warning to upgrade on the condition value, while the other is saying that the attribute value type is unknown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The distinction is since the conditionValue comes from the datafile, so if a value is of an "unexpected" type then its likely the result of an out of date SDK. Since the attributeValue is provided at runtime via the user attributes, then we log that the type is "unknown".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. We can consider adding some clarifications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added doc strings for all the exception classes in this package.
Summary
MatchType
in favor ofMatchRegistry
Match#match
interface.AttributeMatch
class.ExactNumberMatch
class.Incorporating a public MatchRegistry will allow consumers to provide their own implementations of the Match interface.