Add comments to the new configuration classes.

This commit is contained in:
Danila Fedorin 2017-09-11 18:15:40 -07:00
parent 21b7bd5e2b
commit 5aba5c350b
2 changed files with 45 additions and 0 deletions

View File

@ -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()
}

View File

@ -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)
}