-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add a MapVariableValueProvider and move existing NONE provid…
…er to an object
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/noxcrew/smp/provider/MapVariableValueProvider.kt
This file contains 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,21 @@ | ||
package com.noxcrew.smp.provider | ||
|
||
import com.noxcrew.smp.VariableValueProvider | ||
|
||
/** | ||
* A variable value provider that is backed by a map. | ||
* | ||
* If a value is not present in the map for a given key, an exception will be thrown | ||
* as this implementation uses [getValue]. If you wish to avoid this, consider creating | ||
* the backing map using [withDefault]. | ||
* | ||
* @property backingMap The backing map | ||
* @since 1.1 | ||
*/ | ||
public data class MapVariableValueProvider( | ||
public val backingMap: Map<String, Double>, | ||
) : VariableValueProvider { | ||
override suspend fun getValue(name: String): Double { | ||
return backingMap.getValue(name) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/noxcrew/smp/provider/NoOpVariableValueProvider.kt
This file contains 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,14 @@ | ||
package com.noxcrew.smp.provider | ||
|
||
import com.noxcrew.smp.VariableValueProvider | ||
|
||
/** | ||
* A value provider that throws [UnsupportedOperationException] for all calls. | ||
* | ||
* @since 1.1 | ||
*/ | ||
public data object NoOpVariableValueProvider : VariableValueProvider { | ||
override suspend fun getValue(name: String): Double { | ||
throw UnsupportedOperationException("Variables are not supported in this parser!") | ||
} | ||
} |