|  | 
|  | 1 | +package com.fwdekker.randomness.uds | 
|  | 2 | + | 
|  | 3 | +import com.fwdekker.randomness.DataGenerationException | 
|  | 4 | +import com.fwdekker.randomness.DataGroupAction | 
|  | 5 | +import com.fwdekker.randomness.DataInsertAction | 
|  | 6 | +import com.fwdekker.randomness.DataInsertArrayAction | 
|  | 7 | +import com.fwdekker.randomness.DataInsertRepeatAction | 
|  | 8 | +import com.fwdekker.randomness.DataInsertRepeatArrayAction | 
|  | 9 | +import com.fwdekker.randomness.DataQuickSwitchSchemeAction | 
|  | 10 | +import com.fwdekker.randomness.DataSettingsAction | 
|  | 11 | +import com.fwdekker.randomness.array.ArrayScheme | 
|  | 12 | +import com.fwdekker.randomness.array.ArraySettings | 
|  | 13 | +import com.fwdekker.randomness.array.ArraySettingsAction | 
|  | 14 | +import icons.RandomnessIcons | 
|  | 15 | + | 
|  | 16 | + | 
|  | 17 | +/** | 
|  | 18 | + * All actions related to inserting UDS-based strings. | 
|  | 19 | + */ | 
|  | 20 | +class UDSGroupAction : DataGroupAction(RandomnessIcons.Data.Base) { | 
|  | 21 | +    override val insertAction = UDSInsertAction() | 
|  | 22 | +    override val insertArrayAction = UDSInsertAction.ArrayAction() | 
|  | 23 | +    override val insertRepeatAction = UDSInsertAction.RepeatAction() | 
|  | 24 | +    override val insertRepeatArrayAction = UDSInsertAction.RepeatArrayAction() | 
|  | 25 | +    override val settingsAction = UDSSettingsAction() | 
|  | 26 | +    override val quickSwitchSchemeAction = UDSSettingsAction.UDSQuickSwitchSchemeAction() | 
|  | 27 | +    override val quickSwitchArraySchemeAction = ArraySettingsAction.ArrayQuickSwitchSchemeAction() | 
|  | 28 | +} | 
|  | 29 | + | 
|  | 30 | + | 
|  | 31 | +/** | 
|  | 32 | + * Inserts random arbitrary strings based on the UDS descriptor. | 
|  | 33 | + * | 
|  | 34 | + * @param scheme the scheme to use for generating UDS-based strings | 
|  | 35 | + */ | 
|  | 36 | +class UDSInsertAction(private val scheme: UDSScheme = UDSSettings.default.currentScheme) : | 
|  | 37 | +    DataInsertAction(RandomnessIcons.Data.Base) { | 
|  | 38 | +    override val name = "Random Decimal" | 
|  | 39 | + | 
|  | 40 | + | 
|  | 41 | +    /** | 
|  | 42 | +     * Returns random UDS-based strings based on the descriptor. | 
|  | 43 | +     * | 
|  | 44 | +     * @param count the number of strings to generate | 
|  | 45 | +     * @return random UDS-based strings based on the descriptor | 
|  | 46 | +     */ | 
|  | 47 | +    override fun generateStrings(count: Int) = | 
|  | 48 | +        try { | 
|  | 49 | +            UDSParser.parse(scheme.descriptor).also { it.random = this.random }.generateStrings(count) | 
|  | 50 | +        } catch (e: UDSParseException) { | 
|  | 51 | +            throw DataGenerationException(e.message, e) | 
|  | 52 | +        } | 
|  | 53 | + | 
|  | 54 | +    /** | 
|  | 55 | +     * Inserts an array-like string of UDS-based strings. | 
|  | 56 | +     * | 
|  | 57 | +     * @param arrayScheme the scheme to use for generating arrays | 
|  | 58 | +     * @param scheme the scheme to use for generating strings | 
|  | 59 | +     */ | 
|  | 60 | +    class ArrayAction( | 
|  | 61 | +        arrayScheme: ArrayScheme = ArraySettings.default.currentScheme, | 
|  | 62 | +        scheme: UDSScheme = UDSSettings.default.currentScheme | 
|  | 63 | +    ) : DataInsertArrayAction(arrayScheme, UDSInsertAction(scheme), RandomnessIcons.Data.Array) { | 
|  | 64 | +        override val name = "Random UDS Array" | 
|  | 65 | +    } | 
|  | 66 | + | 
|  | 67 | +    /** | 
|  | 68 | +     * Inserts repeated random UDS-based strings. | 
|  | 69 | +     * | 
|  | 70 | +     * @param scheme the settings to use for generating strings | 
|  | 71 | +     */ | 
|  | 72 | +    class RepeatAction(scheme: UDSScheme = UDSSettings.default.currentScheme) : | 
|  | 73 | +        DataInsertRepeatAction(UDSInsertAction(scheme), RandomnessIcons.Data.Repeat) { | 
|  | 74 | +        override val name = "Random Repeated UDS" | 
|  | 75 | +    } | 
|  | 76 | + | 
|  | 77 | +    /** | 
|  | 78 | +     * Inserts repeated array-like strings of UDS-based strings. | 
|  | 79 | +     * | 
|  | 80 | +     * @param arrayScheme the scheme to use for generating arrays | 
|  | 81 | +     * @param scheme the scheme to use for generating strings | 
|  | 82 | +     */ | 
|  | 83 | +    class RepeatArrayAction( | 
|  | 84 | +        arrayScheme: ArrayScheme = ArraySettings.default.currentScheme, | 
|  | 85 | +        scheme: UDSScheme = UDSSettings.default.currentScheme | 
|  | 86 | +    ) : DataInsertRepeatArrayAction(ArrayAction(arrayScheme, scheme), RandomnessIcons.Data.RepeatArray) { | 
|  | 87 | +        override val name = "Random Repeated UDS Array" | 
|  | 88 | +    } | 
|  | 89 | +} | 
|  | 90 | + | 
|  | 91 | + | 
|  | 92 | +/** | 
|  | 93 | + * Controller for random string generation settings. | 
|  | 94 | + * | 
|  | 95 | + * @see UDSSettings | 
|  | 96 | + * @see UDSSettingsComponent | 
|  | 97 | + */ | 
|  | 98 | +class UDSSettingsAction : DataSettingsAction(RandomnessIcons.Data.Settings) { | 
|  | 99 | +    override val name = "UDS Settings" | 
|  | 100 | + | 
|  | 101 | +    override val configurableClass = UDSSettingsConfigurable::class.java | 
|  | 102 | + | 
|  | 103 | + | 
|  | 104 | +    /** | 
|  | 105 | +     * Opens a popup to allow the user to quickly switch to the selected scheme. | 
|  | 106 | +     * | 
|  | 107 | +     * @param settings the settings containing the schemes that can be switched between | 
|  | 108 | +     */ | 
|  | 109 | +    class UDSQuickSwitchSchemeAction(settings: UDSSettings = UDSSettings.default) : | 
|  | 110 | +        DataQuickSwitchSchemeAction<UDSScheme>(settings, RandomnessIcons.Data.QuickSwitchScheme) { | 
|  | 111 | +        override val name = "Quick Switch UDS Scheme" | 
|  | 112 | +    } | 
|  | 113 | +} | 
0 commit comments