-
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.
refactor: split files for IR arguments and parameters
- Loading branch information
Showing
21 changed files
with
219 additions
and
147 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
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,58 +1,29 @@ | ||
package technology.idlab.intermediate | ||
|
||
sealed interface Argument { | ||
val parameter: Parameter | ||
|
||
fun findAll(type: LiteralParameterType, parameter: Parameter): List<String> | ||
} | ||
|
||
class LiteralArgument( | ||
override val parameter: LiteralParameter, | ||
val values: MutableList<String> = mutableListOf(), | ||
) : Argument { | ||
override fun findAll(type: LiteralParameterType, parameter: Parameter): List<String> { | ||
if (parameter !is LiteralParameter) { | ||
return emptyList() | ||
} | ||
|
||
return if (parameter.type == type) { | ||
this.values | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} | ||
|
||
class NestedArgument( | ||
override val parameter: NestedParameter, | ||
val values: MutableList<Map<String, Argument>> = mutableListOf(), | ||
) : Argument { | ||
override fun findAll(type: LiteralParameterType, parameter: Parameter): List<String> { | ||
if (parameter !is NestedParameter) { | ||
throw IllegalStateException() | ||
} | ||
|
||
val result = mutableListOf<String>() | ||
|
||
for (value in this.values) { | ||
for ((key, argument) in value) { | ||
result.addAll(argument.findAll(type, parameter[key])) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} | ||
import technology.idlab.intermediate.argument.Argument | ||
import technology.idlab.intermediate.parameter.LiteralParameterType | ||
|
||
class IRArgument( | ||
val parameter: IRParameter, | ||
val values: Map<String, Argument> = mutableMapOf(), | ||
val root: Map<String, Argument> = mutableMapOf(), | ||
) { | ||
/** | ||
* Get the argument for a given key. | ||
* | ||
* @param key The key of the argument. | ||
* @return The argument. | ||
* @throws IllegalArgumentException If the argument is not found. | ||
*/ | ||
operator fun get(key: String): Argument { | ||
return values[key] ?: throw IllegalArgumentException("Argument $key not found.") | ||
return root[key] ?: throw IllegalArgumentException("Argument $key not found.") | ||
} | ||
|
||
fun findAll(type: LiteralParameterType, parameter: Parameter): List<String> { | ||
return this.values.values.map { it.findAll(type, parameter) }.flatten() | ||
/** | ||
* Find all values of a certain type for a given parameter. | ||
* | ||
* @param type The type of the literal parameter to find. | ||
* @result A flattened list of all values of the given type for the given parameter. | ||
*/ | ||
fun findAll(type: LiteralParameterType): List<String> { | ||
return root.values.map { it.findAll(type) }.flatten() | ||
} | ||
} |
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,55 +1,18 @@ | ||
package technology.idlab.intermediate | ||
|
||
class IRParameter( | ||
uri: String, | ||
type: Map<String, Parameter>, | ||
) : | ||
NestedParameter( | ||
uri, | ||
type, | ||
single = false, | ||
optional = false, | ||
) | ||
|
||
sealed interface Parameter { | ||
val uri: String | ||
val single: Boolean | ||
val optional: Boolean | ||
} | ||
import technology.idlab.intermediate.parameter.Parameter | ||
|
||
open class NestedParameter( | ||
override val uri: String, | ||
class IRParameter( | ||
val type: Map<String, Parameter>, | ||
override val single: Boolean = false, | ||
override val optional: Boolean = false | ||
) : Parameter { | ||
) { | ||
/** | ||
* Get the parameter with the given key. | ||
* | ||
* @param key The key of the parameter. | ||
* @return The parameter. | ||
* @throws IllegalArgumentException If the parameter is not found. | ||
*/ | ||
operator fun get(key: String): Parameter { | ||
return type[key] ?: throw IllegalArgumentException("Parameter $key not found.") | ||
return type[key] ?: throw IllegalArgumentException("No such parameter: $key") | ||
} | ||
} | ||
|
||
enum class LiteralParameterType { | ||
BOOLEAN, | ||
BYTE, | ||
DATE, | ||
DOUBLE, | ||
FLOAT, | ||
INT, | ||
LONG, | ||
STRING, | ||
WRITER, | ||
READER, | ||
} | ||
|
||
data class LiteralParameter( | ||
override val uri: String, | ||
val type: LiteralParameterType, | ||
override val single: Boolean = false, | ||
override val optional: Boolean = false, | ||
) : Parameter |
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,15 +1,11 @@ | ||
package technology.idlab.intermediate | ||
|
||
import java.io.File | ||
import technology.idlab.intermediate.runner.RunnerType | ||
|
||
data class IRRunner( | ||
val uri: String, | ||
val directory: File? = null, | ||
val entrypoint: String? = null, | ||
val type: Type, | ||
) { | ||
enum class Type { | ||
GRPC, | ||
BUILT_IN, | ||
} | ||
} | ||
val type: RunnerType, | ||
) |
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
18 changes: 18 additions & 0 deletions
18
orchestrator/src/main/kotlin/intermediate/argument/Argument.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,18 @@ | ||
package technology.idlab.intermediate.argument | ||
|
||
import technology.idlab.intermediate.parameter.LiteralParameterType | ||
import technology.idlab.intermediate.parameter.Parameter | ||
|
||
/** IR representation of a concrete argument. It holds it's corresponding parameter as a field. */ | ||
sealed interface Argument { | ||
// The parameter that this argument corresponds to. | ||
val parameter: Parameter | ||
|
||
/** | ||
* Find all values of a certain type for a given parameter. | ||
* | ||
* @param type The type of the literal parameter to find. | ||
* @return A flattened list of all values of the given type for the given parameter. | ||
*/ | ||
fun findAll(type: LiteralParameterType): List<String> | ||
} |
21 changes: 21 additions & 0 deletions
21
orchestrator/src/main/kotlin/intermediate/argument/LiteralArgument.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 technology.idlab.intermediate.argument | ||
|
||
import technology.idlab.intermediate.parameter.LiteralParameter | ||
import technology.idlab.intermediate.parameter.LiteralParameterType | ||
|
||
/** Representation of a literal argument in IR as a list of strings. */ | ||
class LiteralArgument( | ||
override val parameter: LiteralParameter, | ||
val values: MutableList<String> = mutableListOf(), | ||
) : Argument { | ||
/* | ||
* If the argument holds the correct type, we can simply return the whole list. | ||
*/ | ||
override fun findAll(type: LiteralParameterType): List<String> { | ||
return if (parameter.type == type) { | ||
values | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
orchestrator/src/main/kotlin/intermediate/argument/NestedArgument.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,26 @@ | ||
package technology.idlab.intermediate.argument | ||
|
||
import technology.idlab.intermediate.parameter.LiteralParameterType | ||
import technology.idlab.intermediate.parameter.NestedParameter | ||
|
||
/** Representation of a single nested argument in IR as a list of key-value pairs. */ | ||
class NestedArgument( | ||
override val parameter: NestedParameter, | ||
val values: MutableList<Map<String, Argument>> = mutableListOf(), | ||
) : Argument { | ||
/* | ||
* The function simply loops over all values in the list and recursively calls findAll on each of | ||
* them. | ||
*/ | ||
override fun findAll(type: LiteralParameterType): List<String> { | ||
val result = mutableListOf<String>() | ||
|
||
for (value in this.values) { | ||
for ((_, argument) in value) { | ||
result.addAll(argument.findAll(type)) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
orchestrator/src/main/kotlin/intermediate/parameter/LiteralParameter.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,13 @@ | ||
package technology.idlab.intermediate.parameter | ||
|
||
/** Representation of a (list of) literal parameter(s) in IR. */ | ||
data class LiteralParameter( | ||
// The path of the parameter as specified in the config. | ||
override val path: String, | ||
// The datatype of the parameter. | ||
val type: LiteralParameterType, | ||
// True if there is only one instance of the parameter at most. | ||
override val single: Boolean = false, | ||
// True if there may be zero instances of the parameter. | ||
override val optional: Boolean = false, | ||
) : Parameter |
15 changes: 15 additions & 0 deletions
15
orchestrator/src/main/kotlin/intermediate/parameter/LiteralParameterType.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,15 @@ | ||
package technology.idlab.intermediate.parameter | ||
|
||
/** Specifies the type of literal parameter. */ | ||
enum class LiteralParameterType { | ||
BOOLEAN, | ||
BYTE, | ||
DATE, | ||
DOUBLE, | ||
FLOAT, | ||
INT, | ||
LONG, | ||
STRING, | ||
WRITER, | ||
READER, | ||
} |
19 changes: 19 additions & 0 deletions
19
orchestrator/src/main/kotlin/intermediate/parameter/NestedParameter.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,19 @@ | ||
package technology.idlab.intermediate.parameter | ||
|
||
/** Representation of nested parameter in IR. */ | ||
open class NestedParameter( | ||
override val path: String, | ||
val type: Map<String, Parameter>, | ||
override val single: Boolean = false, | ||
override val optional: Boolean = false | ||
) : Parameter { | ||
/** | ||
* Get the parameter with the given key. | ||
* | ||
* @param key The key of the parameter. | ||
* @return The parameter. | ||
*/ | ||
operator fun get(key: String): Parameter { | ||
return type[key] ?: throw IllegalArgumentException("Parameter $key not found.") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
orchestrator/src/main/kotlin/intermediate/parameter/Parameter.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,20 @@ | ||
package technology.idlab.intermediate.parameter | ||
|
||
/** | ||
* Generic representation of a parameter in IR, which may be either a literal or a nested parameter. | ||
*/ | ||
sealed interface Parameter { | ||
// The path of the parameter as specified in the config. | ||
val path: String | ||
// True if there is only one instance of the parameter at most. | ||
val single: Boolean | ||
// True if there may be zero instances of the parameter. | ||
val optional: Boolean | ||
// True if there can be more than one instance of the parameter. | ||
val list: Boolean | ||
get() = !single | ||
|
||
// True if the parameter is not optional. | ||
val required: Boolean | ||
get() = !optional | ||
} |
9 changes: 9 additions & 0 deletions
9
orchestrator/src/main/kotlin/intermediate/runner/RunnerType.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,9 @@ | ||
package technology.idlab.intermediate.runner | ||
|
||
/** The types of runner supported by the Orchestrator. */ | ||
enum class RunnerType { | ||
// A runner which communicates over GRPC. | ||
GRPC, | ||
// A runner which is built into the Orchestrator. | ||
BuiltIn, | ||
} |
Oops, something went wrong.