Skip to content

Commit e7b12c9

Browse files
Merge pull request #15 from simplecloudapp/feat/numerical-operation-matcher
feat: added NumericOperationMatcher and GreaterThanOperation
2 parents 23faff9 + 1a9ee8f commit e7b12c9

17 files changed

+122
-83
lines changed

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/OperationType.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
package app.simplecloud.plugin.api.shared.matcher
22

3-
import app.simplecloud.plugin.api.shared.matcher.operation.*
3+
import app.simplecloud.plugin.api.shared.matcher.operation.NumericOperationMatcher
4+
import app.simplecloud.plugin.api.shared.matcher.operation.OperationMatcher
5+
import app.simplecloud.plugin.api.shared.matcher.operation.StringOperationMatcher
6+
import app.simplecloud.plugin.api.shared.matcher.operation.impl.*
47

58
enum class OperationType(
6-
private val matcher: OperationMatcher
9+
private val matcher: OperationMatcher<*, *>
710
) {
811

912
REGEX(RegexOperationMatcher),
1013
PATTERN(PatternOperationMatcher),
1114
EQUALS(EqualsOperationMatcher),
1215
CONTAINS(ContainsOperationMatcher),
1316
STARTS_WITH(StartsWithOperationMatcher),
14-
ENDS_WITH(EndsWithOperationMatcher);
17+
ENDS_WITH(EndsWithOperationMatcher),
18+
GREATER_THAN(GreaterThanOperationMatcher);
1519

16-
fun matches(name: String, value: String, negate: Boolean): Boolean {
17-
val matches = this.matcher.matches(name, value)
18-
if (negate) {
19-
return matches.not()
20+
fun matches(key: Any, value: Any, negate: Boolean): Boolean {
21+
val matches = when (matcher) {
22+
is StringOperationMatcher -> {
23+
if (key is String && value is String) {
24+
matcher.matches(key, value)
25+
} else false
26+
}
27+
28+
is NumericOperationMatcher -> {
29+
if (key is Int && value is Int) {
30+
matcher.matches(key, value)
31+
} else false
32+
}
33+
34+
else -> false
2035
}
21-
return matches
36+
37+
return if (negate) matches.not() else matches
2238
}
2339

2440
fun anyMatches(names: List<String>, value: String, negate: Boolean): Boolean {

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/ContainsOperationMatcher.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/EndsWithOperationMatcher.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/EqualsOperationMatcher.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package app.simplecloud.plugin.api.shared.matcher.operation
2+
3+
interface NumericOperationMatcher : OperationMatcher<Int, Int>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package app.simplecloud.plugin.api.shared.matcher.operation
22

3-
interface OperationMatcher {
3+
interface OperationMatcher<K, V> {
44

5-
fun matches(name: String, value: String): Boolean
5+
fun matches(key: K, value: V): Boolean
66

77
}

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/PatternOperationMatcher.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/RegexOperationMatcher.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/matcher/operation/StartsWithOperationMatcher.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package app.simplecloud.plugin.api.shared.matcher.operation
2+
3+
interface StringOperationMatcher : OperationMatcher<String, String>

0 commit comments

Comments
 (0)