-
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.
- Loading branch information
Showing
9 changed files
with
46 additions
and
56 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
package runner.jvm | ||
|
||
import java.util.Optional | ||
import technology.idlab.runner.jvm.Arguments | ||
import technology.idlab.util.Log | ||
|
||
abstract class Processor( | ||
/** | ||
* The arguments of a processor are stored in a map and can be accessed by name. At the time of | ||
* writing, the user must manually cast the arguments to the correct type. | ||
*/ | ||
private val arguments: Map<String, Any>, | ||
protected val arguments: Arguments, | ||
) { | ||
/** | ||
* Processors which wish to log messages should use the logger provided by the template class. | ||
* This logger is created with the name of the class which extends the template. | ||
*/ | ||
@JvmField protected val log = Log.shared | ||
|
||
fun <T> getArgument(name: String): T { | ||
val result = arguments.get(name) as List<T> ?: log.fatal("Argument $name is missing") | ||
return result.get(0) ?: log.fatal("Argument $name is missing") | ||
} | ||
|
||
fun <T> getNullableArgument(name: String): T? { | ||
val result = arguments.get(name) as List<T>? | ||
return result?.get(0) | ||
} | ||
|
||
fun <T> getOptionalArgument(name: String): Optional<T> { | ||
val result = (arguments.get(name) as List<T>?)?.get(0) ?: log.fatal("Argument $name is missing") | ||
|
||
if (result is Optional<*>) { | ||
return result as Optional<T> | ||
} | ||
|
||
log.fatal("Argument $name is not optional") | ||
} | ||
|
||
abstract suspend fun exec() | ||
} |
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
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
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
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