getter setter
all parameters in storage class
This commit is contained in:
parent
cded7c7d27
commit
3818b6d1c7
@ -15,32 +15,135 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
class Storage {
|
class Storage {
|
||||||
companion object {
|
companion object {
|
||||||
val obj = Storage()
|
private val obj = Storage()
|
||||||
fun getInstance(): Storage {
|
fun getInstance(): Storage {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mqttServer: String = "";
|
private var mqttServer: String = ""
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var mqttPort: Int = -1
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var dbName: String = ""
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var dbUser: String = ""
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var dbPassword: String = ""
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var dbPort: Int = -1
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private val prop = Properties()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init config file
|
* init config file
|
||||||
*/
|
*/
|
||||||
fun init() {
|
fun init() {
|
||||||
val prop = Properties()
|
|
||||||
try {
|
try {
|
||||||
// try to load existing config file
|
// try to load existing config file
|
||||||
val inp = FileInputStream("settings.prop")
|
val inp = FileInputStream("settings.prop")
|
||||||
prop.load(inp)
|
prop.load(inp)
|
||||||
|
|
||||||
|
mqttServer = prop.get("mqttserver") as String
|
||||||
} catch (ee: FileNotFoundException) {
|
} catch (ee: FileNotFoundException) {
|
||||||
// file not generated yet
|
// file not generated yet
|
||||||
prop.store(FileOutputStream("settings.prop"), "")
|
store()
|
||||||
Log.info("new Settings config file generated")
|
Log.info("new Settings config file generated")
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* store data to storage file
|
||||||
|
*/
|
||||||
|
fun store() {
|
||||||
|
prop["mqttserver"] = mqttServer
|
||||||
|
prop["mqttport"] = mqttPort
|
||||||
|
prop["dbname"] = dbName
|
||||||
|
prop["dbuser"] = dbUser
|
||||||
|
prop["dbpass"] = dbPassword
|
||||||
|
prop["dbport"] = dbPort
|
||||||
|
|
||||||
|
prop.store(FileOutputStream("settings.prop"), "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if all needed properties are set up correctly
|
||||||
|
*/
|
||||||
|
fun isEveryThingDefined(): Boolean {
|
||||||
|
return (mqttServer != "" &&
|
||||||
|
mqttPort != 0 &&
|
||||||
|
dbName != "" &&
|
||||||
|
dbUser != "" &&
|
||||||
|
dbPassword != "" &&
|
||||||
|
dbPort != -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the mqttservername defined?
|
||||||
|
*/
|
||||||
|
fun isMqttServerDefined(): Boolean {
|
||||||
|
return (mqttServer != "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the mqttserver port defined?
|
||||||
|
*/
|
||||||
|
fun isMqttPortDefined(): Boolean {
|
||||||
|
return (mqttPort != -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the dbname defined?
|
||||||
|
*/
|
||||||
|
fun isDBNameDefined(): Boolean {
|
||||||
|
return (dbName != "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the dbport defined?
|
||||||
|
*/
|
||||||
|
fun isDBPortDefined(): Boolean {
|
||||||
|
return (dbPort != -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the dbpassword defined?
|
||||||
|
*/
|
||||||
|
fun isDBPasswdDefined(): Boolean {
|
||||||
|
return (dbPassword != "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is the dbusername defined?
|
||||||
|
*/
|
||||||
|
fun isDBUsernameDefined(): Boolean {
|
||||||
|
return (dbUser != "")
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user