Skip to content
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

Merged
merged 4 commits into from
Mar 8, 2024
Merged

Add semver support (FF-1573) #37

merged 4 commits into from
Mar 8, 2024

Conversation

leoromanovsky
Copy link
Member

@leoromanovsky leoromanovsky commented Mar 7, 2024

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.

try {
switch (condition.getOperator()) {
case GreaterThanEqualTo:
return Compare.compareNumber(value.doubleValue(), condition.getValue().doubleValue()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted compareNumber helper

Copy link
Contributor

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()));
Copy link
Member Author

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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 > 5

@leoromanovsky
Copy link
Member Author

Screenshot 2024-03-07 at 6 14 08 PM Screenshot 2024-03-07 at 6 12 51 PM

@@ -87,7 +79,7 @@ public JsonElement jsonValue() {

public boolean isNumeric() {
try {
Long.parseLong(value, 10);
Double.parseDouble(value);
Copy link
Member Author

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

Comment on lines -60 to -63
public int intValue() {
return Integer.parseInt(value, 10);
}

Copy link
Member Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@agamkrbit agamkrbit left a 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

Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! 🎉

Comment on lines -18 to -20
public static boolean compareNumber(double a, double b, IConditionFunc<Double> conditionFunc) {
return conditionFunc.check(a, b);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓

Comment on lines +54 to +58
// 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.
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@leoromanovsky leoromanovsky merged commit 04fe3ed into main Mar 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants