-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add semver support (FF-1573) #37
Conversation
try { | ||
switch (condition.getOperator()) { | ||
case GreaterThanEqualTo: | ||
return Compare.compareNumber(value.doubleValue(), condition.getValue().doubleValue() |
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.
deleted compareNumber
helper
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.
🙌
} | ||
|
||
if (isValueSemVer && isConditionSemVer) { | ||
return Version.parse(value.stringValue()).isHigherThanOrEquivalentTo(Version.parse(condition.getValue().stringValue())); |
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.
since we passed isValid
we should be confident that parse
will succeed without an exception
targetingRules.add(targetingRule); | ||
|
||
SubjectAttributes subjectAttributes = new SubjectAttributes(); | ||
subjectAttributes.put("appVersion", "1.15.5"); |
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.
15 > 5
@@ -87,7 +79,7 @@ public JsonElement jsonValue() { | |||
|
|||
public boolean isNumeric() { | |||
try { | |||
Long.parseLong(value, 10); | |||
Double.parseDouble(value); |
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.
decimal values returned false
always
public int intValue() { | ||
return Integer.parseInt(value, 10); | ||
} | ||
|
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.
these were unused - unclear to me why we would want to
@@ -43,6 +43,21 @@ public void addNumericConditionToRule(TargetingRule TargetingRule) { | |||
addConditionToRule(TargetingRule, condition2); | |||
} | |||
|
|||
public void addSemVerConditionToRule(TargetingRule TargetingRule) { |
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.
👍
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.
Look good!! Added one minor comment
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.
Great stuff! 🎉
public static boolean compareNumber(double a, double b, IConditionFunc<Double> conditionFunc) { | ||
return conditionFunc.check(a, b); | ||
} |
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.
🪓
// Android API version 21 does not have access to the java.util.Optional class. | ||
// Version.tryParse returns a Optional<Version> would be ideal. | ||
// Instead use Version.parse which throws an exception if the string is not a valid SemVer. | ||
// We front-load the parsing here so many evaluation of gte, gt, lte, lt operations | ||
// more straight-forward. |
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.
Thanks for the helpful comment!
try { | ||
switch (condition.getOperator()) { | ||
case GreaterThanEqualTo: | ||
return Compare.compareNumber(value.doubleValue(), condition.getValue().doubleValue() |
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.
🙌
context
Related implementation to Java (Eppo-exp/java-server-sdk@11c33e3). Since we are targeting android api 21, we are limited to an older API.
isPresent, which require API level 24 or higher, you'll need to find alternative approaches. The Optional class and its methods were introduced in Java 8, and Android started supporting Java 8 language features from API level 24 onwards. This means methods like isPresent and isEmpty are not directly available on devices running lower API levels.
description
implementation of semver support using available APIs.