Controls

class Controls(aModel: Model)(source)

Holds all controls associated with a model instance, across three parallel families:

  • Numeric controls — properties annotated with KSLControl; values are Double and respect declared lower/upper bounds.

  • String controls — properties annotated with KSLStringControl; values are String, optionally constrained to a declared set of allowed values.

  • JSON controls — properties annotated with KSLJsonControl; values are any kotlinx.serialization-compatible Kotlin type transported as JSON strings (e.g. List<Double>, Map<String, Int>, @Serializable classes).

Controls are extracted in a single element-graph walk performed during init, which runs when the caller first calls model.controls(). This guarantees all model elements are fully constructed before any initial value is captured.

Commonly used functions:

Numeric:

  • controlKeys() — names of the numeric controls

  • control(key) — returns the named ControlIfc or null

  • asMap() — flat Map<String, Double> of all numeric controls

  • setControlsFromMap(map) — bulk-set numeric controls from a flat map

  • controlData() — list of ControlData DTOs for data transfer

String:

  • stringControlKeys() — names of the string controls

  • stringControl(key) — returns the named StringControlIfc or null

  • stringControlsAsMap() — flat Map<String, String> of all string controls

  • setStringControlsFromMap(map) — bulk-set string controls; invalid values are logged and skipped rather than aborting the entire update

  • stringControlData() — list of StringControlData DTOs for data transfer

JSON:

  • jsonControlKeys() — names of the JSON controls

  • jsonControl(key) — returns the named JsonControlIfc or null

  • jsonControlsAsMap() — flat Map<String, String> of all JSON controls (values are JSON strings)

  • setJsonControlsFromMap(map) — bulk-set JSON controls; invalid JSON is logged and skipped rather than aborting the entire update

  • jsonControlData() — list of JsonControlData DTOs for data transfer

Batch export / import (all families):

  • exportAll() — produces a ModelControlsExport snapshot of every control

  • exportAllAsJson() — pretty-printed JSON string of the full snapshot

  • importAll(export) — applies a ModelControlsExport; returns ControlImportResult

  • importAllFromJson(json) — deserializes then delegates to importAll

Constructors

Link copied to clipboard
constructor(aModel: Model)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Number of JSON controls extracted from the model.

Link copied to clipboard
val size: Int

Number of numeric/boolean controls extracted from the model.

Link copied to clipboard

Number of string controls extracted from the model.

Functions

Link copied to clipboard

Returns all numeric controls as a list.

Link copied to clipboard

Returns all numeric controls of the given controlType.

Link copied to clipboard

Returns a flat Map<String, Double> of all numeric controls. The key is ControlIfc.keyName and the value is the current control value.

Link copied to clipboard
fun control(controlKey: String): ControlIfc?

Returns the numeric control for controlKey, or null if not found.

Link copied to clipboard

Returns a list of ControlData DTOs for all numeric controls.

Link copied to clipboard

Returns the numeric control data as a formatted string.

Link copied to clipboard

Returns the set of numeric control key names.

Link copied to clipboard

Returns a map from model element type (simple class name) to the list of numeric controls belonging to elements of that type.

Link copied to clipboard

Returns a map from model element name to the list of numeric controls belonging to that element.

Link copied to clipboard

Returns a JSON string representation of the flat numeric controls map.

Link copied to clipboard

Returns the set of ControlType values present in the extracted controls.

Link copied to clipboard

Produces a ModelControlsExport snapshot of every control in this model.

Link copied to clipboard

Serializes exportAll to a pretty-printed JSON string.

Link copied to clipboard

Returns true if a numeric control with name exists.

Link copied to clipboard

Returns true if a JSON control with name exists.

Link copied to clipboard

Returns true if a string control with name exists.

Link copied to clipboard

Applies export to this model's controls, updating each control whose key is found in the respective map.

Link copied to clipboard

Deserializes json into a ModelControlsExport and delegates to importAll.

Link copied to clipboard

Returns the JSON control for key, or null if not found.

Link copied to clipboard

Returns a list of JsonControlData DTOs for all JSON controls.

Link copied to clipboard

Returns the JSON control data as a formatted string.

Link copied to clipboard

Returns the set of JSON control key names.

Link copied to clipboard

Returns all JSON controls as a list.

Link copied to clipboard

Returns a flat Map<String, String> of all JSON controls. The key is JsonControlIfc.keyName and the value is the current JSON string.

Link copied to clipboard

Prints all numeric controls as keyName = value pairs.

Link copied to clipboard

Sets numeric controls from a JSON string representing a Map<String, Double>.

Link copied to clipboard
fun setControlsFromMap(controlMap: Map<String, Double>): Int

Sets numeric controls from a flat map of key → value pairs. Keys not found in the extracted controls are logged as warnings and skipped.

Link copied to clipboard

Sets JSON controls from a flat map of key → JSON-string pairs.

Link copied to clipboard

Sets string controls from a flat map of key → value pairs.

Link copied to clipboard

Returns the string control for key, or null if not found.

Link copied to clipboard

Returns a list of StringControlData DTOs for all string controls.

Link copied to clipboard

Returns the string control data as a formatted string.

Link copied to clipboard

Returns the set of string control key names.

Link copied to clipboard

Returns all string controls as a list.

Link copied to clipboard

Returns a flat Map<String, String> of all string controls. The key is StringControlIfc.keyName and the value is the current control value.

Link copied to clipboard
fun Controls.toReport(title: String? = null, groupByElement: Boolean = false, includeAllowedValues: Boolean = true, jsonValueWidth: Int = 60, includeComment: Boolean = true, block: ReportBuilder.() -> Unit = run { val export = this.exportAll() val lambda: ReportBuilder.() -> Unit = { controlsReport( export = export, groupByElement = groupByElement, includeAllowedValues = includeAllowedValues, jsonValueWidth = jsonValueWidth, includeComment = includeComment, ) } lambda }): ReportNode.Document

Builds a ReportNode.Document for this Controls instance.

Link copied to clipboard
open override fun toString(): String