-
Couldn't load subscription status.
- Fork 189
Feat operators #1225
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
Open
abnegate
wants to merge
19
commits into
master
Choose a base branch
from
feat-operators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,181
−37
Open
Feat operators #1225
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
091dc69
Add operator classes
abnegate bbb6700
Add tests
abnegate 2489906
Fix Android/Kotlin filter
abnegate c6398f6
Fix dart/flutter filter
abnegate e6a0c1f
Add condition enum
abnegate f23cb97
Fix tests
abnegate 611e8b2
Fix tests
abnegate c734f3a
Fix tests
abnegate 3d1df1f
Fix PHP test
abnegate 8df4a60
Fix chromium test
abnegate ed20156
Add isNull + isNotNull conditions
abnegate 3c4dc84
Block divide by 0
abnegate c26f8d6
Fix web chrome test
abnegate c4af38b
Add divide by zero checks
abnegate 75c4f07
Fix Android nullable
abnegate b38d7d0
Merge remote-tracking branch 'origin/master' into feat-operators
abnegate e891fc7
Align exceptions
abnegate fd4027e
Merge remote-tracking branch 'origin/master' into feat-operators
abnegate 92f13d8
Add more numeric checks
abnegate 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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
130 changes: 130 additions & 0 deletions
130
templates/android/library/src/main/java/io/package/Operator.kt.twig
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,130 @@ | ||
| package {{ sdk.namespace | caseDot }} | ||
|
|
||
| import {{ sdk.namespace | caseDot }}.extensions.toJson | ||
|
|
||
| enum class Condition(val value: String) { | ||
| EQUAL("equal"), | ||
| NOT_EQUAL("notEqual"), | ||
| GREATER_THAN("greaterThan"), | ||
| GREATER_THAN_EQUAL("greaterThanEqual"), | ||
| LESS_THAN("lessThan"), | ||
| LESS_THAN_EQUAL("lessThanEqual"), | ||
| CONTAINS("contains"), | ||
| IS_NULL("isNull"), | ||
| IS_NOT_NULL("isNotNull"); | ||
|
|
||
| override fun toString() = value | ||
| } | ||
|
|
||
| class Operator( | ||
| val method: String, | ||
| val values: List<Any?>? = null, | ||
| ) { | ||
| override fun toString() = this.toJson() | ||
|
|
||
| companion object { | ||
| fun increment(value: Number = 1, max: Number? = null): String { | ||
| require(!value.toDouble().isNaN() && !value.toDouble().isInfinite()) { "Value cannot be NaN or Infinity" } | ||
| max?.let { require(!it.toDouble().isNaN() && !it.toDouble().isInfinite()) { "Max cannot be NaN or Infinity" } } | ||
| val values = mutableListOf<Any?>(value) | ||
| max?.let { values.add(it) } | ||
| return Operator("increment", values).toJson() | ||
| } | ||
|
|
||
| fun decrement(value: Number = 1, min: Number? = null): String { | ||
| require(!value.toDouble().isNaN() && !value.toDouble().isInfinite()) { "Value cannot be NaN or Infinity" } | ||
| min?.let { require(!it.toDouble().isNaN() && !it.toDouble().isInfinite()) { "Min cannot be NaN or Infinity" } } | ||
| val values = mutableListOf<Any?>(value) | ||
| min?.let { values.add(it) } | ||
| return Operator("decrement", values).toJson() | ||
| } | ||
|
|
||
| fun multiply(factor: Number, max: Number? = null): String { | ||
| require(!factor.toDouble().isNaN() && !factor.toDouble().isInfinite()) { "Factor cannot be NaN or Infinity" } | ||
| max?.let { require(!it.toDouble().isNaN() && !it.toDouble().isInfinite()) { "Max cannot be NaN or Infinity" } } | ||
| val values = mutableListOf<Any?>(factor) | ||
| max?.let { values.add(it) } | ||
| return Operator("multiply", values).toJson() | ||
| } | ||
|
|
||
| fun divide(divisor: Number, min: Number? = null): String { | ||
| require(!divisor.toDouble().isNaN() && !divisor.toDouble().isInfinite()) { "Divisor cannot be NaN or Infinity" } | ||
| min?.let { require(!it.toDouble().isNaN() && !it.toDouble().isInfinite()) { "Min cannot be NaN or Infinity" } } | ||
| require(divisor.toDouble() != 0.0) { "Divisor cannot be zero" } | ||
| val values = mutableListOf<Any?>(divisor) | ||
| min?.let { values.add(it) } | ||
| return Operator("divide", values).toJson() | ||
| } | ||
|
|
||
| fun modulo(divisor: Number): String { | ||
| require(!divisor.toDouble().isNaN() && !divisor.toDouble().isInfinite()) { "Divisor cannot be NaN or Infinity" } | ||
| require(divisor.toDouble() != 0.0) { "Divisor cannot be zero" } | ||
| return Operator("modulo", listOf(divisor)).toJson() | ||
| } | ||
|
|
||
| fun power(exponent: Number, max: Number? = null): String { | ||
| require(!exponent.toDouble().isNaN() && !exponent.toDouble().isInfinite()) { "Exponent cannot be NaN or Infinity" } | ||
| max?.let { require(!it.toDouble().isNaN() && !it.toDouble().isInfinite()) { "Max cannot be NaN or Infinity" } } | ||
| val values = mutableListOf<Any?>(exponent) | ||
| max?.let { values.add(it) } | ||
| return Operator("power", values).toJson() | ||
| } | ||
|
|
||
| fun arrayAppend(values: List<Any?>): String { | ||
| return Operator("arrayAppend", values).toJson() | ||
| } | ||
|
|
||
| fun arrayPrepend(values: List<Any?>): String { | ||
| return Operator("arrayPrepend", values).toJson() | ||
| } | ||
|
|
||
| fun arrayInsert(index: Int, value: Any): String { | ||
| return Operator("arrayInsert", listOf(index, value)).toJson() | ||
| } | ||
|
|
||
| fun arrayRemove(value: Any): String { | ||
| return Operator("arrayRemove", listOf(value)).toJson() | ||
| } | ||
|
|
||
| fun arrayUnique(): String { | ||
| return Operator("arrayUnique", emptyList()).toJson() | ||
| } | ||
|
|
||
| fun arrayIntersect(values: List<Any?>): String { | ||
| return Operator("arrayIntersect", values).toJson() | ||
| } | ||
|
|
||
| fun arrayDiff(values: List<Any?>): String { | ||
| return Operator("arrayDiff", values).toJson() | ||
| } | ||
|
|
||
| fun arrayFilter(condition: Condition, value: Any? = null): String { | ||
| val values = listOf<Any?>(condition.value, value) | ||
| return Operator("arrayFilter", values).toJson() | ||
| } | ||
|
|
||
| fun concat(value: Any): String { | ||
| return Operator("concat", listOf(value)).toJson() | ||
| } | ||
|
|
||
| fun replace(search: String, replace: String): String { | ||
| return Operator("replace", listOf(search, replace)).toJson() | ||
| } | ||
|
|
||
| fun toggle(): String { | ||
| return Operator("toggle", emptyList()).toJson() | ||
| } | ||
|
|
||
| fun dateAddDays(days: Int): String { | ||
| return Operator("dateAddDays", listOf(days)).toJson() | ||
| } | ||
|
|
||
| fun dateSubDays(days: Int): String { | ||
| return Operator("dateSubDays", listOf(days)).toJson() | ||
| } | ||
|
|
||
| fun dateSetNow(): String { | ||
| return Operator("dateSetNow", emptyList()).toJson() | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.