mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add comments to the new configuration classes.
This commit is contained in:
parent
21b7bd5e2b
commit
5aba5c350b
|
@ -1,7 +1,20 @@
|
|||
package org.nwapw.abacus.config
|
||||
|
||||
/**
|
||||
* A class that holds information that tells Abacus how to behave.
|
||||
*
|
||||
* Configuration stores information about how Abacus should behave, for
|
||||
* instance, what number implementation it should use and what
|
||||
* plugins should be ignored during loading.
|
||||
*
|
||||
* @property numberImplementation the number implementation Abacus should use for loading.
|
||||
* @param disabledPlugins the plugins that should be disabled and not loaded by the plugin manager.
|
||||
*/
|
||||
open class Configuration(var numberImplementation: String = "<default>", disabledPlugins: Array<String> = emptyArray()) {
|
||||
|
||||
/**
|
||||
* The set of disabled plugins that should be ignored by the plugin manager.
|
||||
*/
|
||||
val disabledPlugins = disabledPlugins.toMutableSet()
|
||||
|
||||
}
|
|
@ -5,25 +5,53 @@ import com.moandjiezana.toml.TomlWriter
|
|||
import org.nwapw.abacus.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Additional settings for user interface.
|
||||
*
|
||||
* ExtendedConfiguration is used to add other settings
|
||||
* that aren't built into Abacus core, but are necessary
|
||||
* for the fx module.
|
||||
*
|
||||
* @property computationDelay the delay before which the computation stops.
|
||||
* @param implementation the number implementation, same as [Configuration.numberImplementation]
|
||||
* @param disabledPlugins the list of plugins that should be disabled, same as [Configuration.disabledPlugins]
|
||||
*/
|
||||
class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||
implementation: String = "<default>",
|
||||
disabledPlugins: Array<String> = emptyArray())
|
||||
: Configuration(implementation, disabledPlugins) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* The default TOML.
|
||||
*/
|
||||
val DEFAULT_TOML_STRING = """
|
||||
computationDelay=0.0
|
||||
implementation="naive"
|
||||
disabledPlugins=[]
|
||||
"""
|
||||
/**
|
||||
* A reader with the default TOML data.
|
||||
*/
|
||||
val DEFAULT_TOML_READER = Toml().read(DEFAULT_TOML_STRING)
|
||||
/**
|
||||
* A writer used to writing the configuration to disk.
|
||||
*/
|
||||
val DEFAULT_TOML_WRITER = TomlWriter()
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new configuration from a file on disk.
|
||||
* @param tomlFile the file from disk to load.
|
||||
*/
|
||||
constructor(tomlFile: File) : this() {
|
||||
copyFrom(Toml(DEFAULT_TOML_READER).read(tomlFile).to(ExtendedConfiguration::class.java))
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies data from another configuration into this one.
|
||||
* @param config the configuration to copy from.
|
||||
*/
|
||||
fun copyFrom(config: ExtendedConfiguration) {
|
||||
computationDelay = config.computationDelay
|
||||
numberImplementation = config.numberImplementation
|
||||
|
@ -31,6 +59,10 @@ class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
|||
disabledPlugins.addAll(config.disabledPlugins)
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this configuration to a file.
|
||||
* @param file the file to save to.
|
||||
*/
|
||||
fun saveTo(file: File) {
|
||||
DEFAULT_TOML_WRITER.write(this, file)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user