public class ArrangedPropertiesWriter extends Object implements Cloneable
Constructor and Description |
---|
ArrangedPropertiesWriter(JTS3ServerMod_Interface mainClass)
Create a new instance of the ArrangedPropertiesWriter.
|
ArrangedPropertiesWriter(JTS3ServerMod_Interface mainClass,
HashMap<String,String> hmHelp,
HashMap<String,String> hmValue,
HashMap<String,Boolean> hmSave,
Vector<String> vKeys)
Create a new instance with an already loaded configuration.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addKey(String key,
String helpText)
Add a new key at the current position.
|
boolean |
addKey(String key,
String helpText,
boolean saveToFile)
Add a new key at the current position.
|
boolean |
addKey(String key,
String helpText,
String defaultValue)
Add a new key at the current position.
|
boolean |
addKey(String key,
String helpText,
String defaultValue,
boolean saveToFile)
Add a new key at the current position.
|
void |
addSeparator()
Add a separator at the current position.
|
boolean |
canSaveToFile(String key)
Returns if this value can save to file.
|
ArrangedPropertiesWriter |
clone()
Get a new instance of the ArrangedPropertiesWriter with the same loaded configuration.
|
String |
getHelpText(String key)
Get the help text of a key.
|
int |
getKeyCount()
Returns number of stored keys.
|
Vector<String> |
getKeys()
Get a list of all known keys.
|
String |
getValue(String key)
Returns the value of the key.
|
String |
getValue(String key,
String defValue)
Returns the value of the key.
|
boolean |
insertKey(String key,
int pos,
String helpText)
Inserts a new key at the given position.
|
void |
insertSeparator(int pos)
Insert separator at a given position.
|
boolean |
loadValues(File file)
Load values from property file.
|
boolean |
loadValues(MySQLConnect mysqlConnect,
int instanceID)
Load values from SQL database.
|
boolean |
loadValues(String filename)
Load values from property file.
|
void |
removeAllSeparators()
Removes all separators.
|
void |
removeAllValues()
Clears all values.
|
boolean |
removeKey(String key)
Remove a key.
|
boolean |
save()
Save values to the last loading location!
|
boolean |
save(MySQLConnect mysqlConnect,
int instanceID)
Save values to SQL database.
|
boolean |
save(String filename,
String header)
Write arranged property file to disk.
|
void |
setDefaultConfigFileHeader(String header)
Set a default config file header.
|
void |
setNewMainClass(JTS3ServerMod_Interface mainClass)
Set a new main class.
|
boolean |
setValue(String key,
boolean value)
Sets a value for the given key.
|
boolean |
setValue(String key,
double value)
Sets a value for the given key.
|
boolean |
setValue(String key,
long value)
Sets a value for the given key.
|
boolean |
setValue(String key,
String value)
Sets a value for the given key.
|
void |
setWriteProtection(boolean flag)
Set write protection to
true to make sure, that no values will be changed, removed or added. |
public ArrangedPropertiesWriter(JTS3ServerMod_Interface mainClass)
mainClass
- A new main class, will be needed to access the addLogEntry method to write log entries.public ArrangedPropertiesWriter(JTS3ServerMod_Interface mainClass, HashMap<String,String> hmHelp, HashMap<String,String> hmValue, HashMap<String,Boolean> hmSave, Vector<String> vKeys)
mainClass
- A new main class, will be needed to access the addLogEntry method to write log entries.hmHelp
- Instance of hmHelphmValue
- Instance of hmValuehmSave
- Instance of hmSavevKeys
- Instance of vKeyspublic boolean addKey(String key, String helpText)
key
- Name of the keyhelpText
- Help text of the key or null
if not wanted.true
if the key was added, false
if the key is already known.public boolean addKey(String key, String helpText, boolean saveToFile)
key
- Name of the keyhelpText
- Help text of the key or null
if not wanted.saveToFile
- False if this config key should be ignored by the save method, if saving to file.true
if the key was added, false
if the key is already known.public boolean addKey(String key, String helpText, String defaultValue)
key
- Name of the keyhelpText
- Help text of the key or null
if not wanted.defaultValue
- Preset the key with a default value. Set null
if no default value should be set!true
if the key was added, false
if the key is already known.public boolean addKey(String key, String helpText, String defaultValue, boolean saveToFile)
key
- Name of the keyhelpText
- Help text of the key or null
if not wanted.defaultValue
- Preset the key with a default value. Set null
if no default value should be set!saveToFile
- False if this config key should be ignored by the save method, if saving to file.true
if the key was added, false
if the key is already known.public void addSeparator()
public boolean canSaveToFile(String key)
key
- Name of the keytrue
if the key can be saved to file or false
if not.public ArrangedPropertiesWriter clone()
null
.public String getHelpText(String key)
key
- Name of the keynull
if the key has no help text.public int getKeyCount()
public String getValue(String key)
key
- Name of the keynull
if there is no value.public String getValue(String key, String defValue)
key
- Name of the keydefValue
- Default valuepublic boolean insertKey(String key, int pos, String helpText)
key
- Name of the keypos
- Insert positionhelpText
- Help text of the key or null
if not wanted.true
if the key was inserted, false
if the key is already known.public void insertSeparator(int pos)
pos
- Position to insert separator.public boolean loadValues(File file)
file
- File object of the property file.true
if file was successfully read, false
if not.public boolean loadValues(MySQLConnect mysqlConnect, int instanceID)
mysqlConnect
- MySQLConnect
class.instanceID
- The instance ID in the database.true
if database was successfully read, false
if not.public boolean loadValues(String filename)
filename
- Path to the property file.true
if file was successfully read, false
if not.public void removeAllSeparators()
public void removeAllValues()
public boolean removeKey(String key)
key
- Name of the keytrue
if the key was removed, false
if key not found.public boolean save()
true
if values was successfully written, false
if not.public boolean save(MySQLConnect mysqlConnect, int instanceID)
mysqlConnect
- MySQLConnect
class.instanceID
- The instance ID in the database.true
if values was successfully written to database, false
if not.public boolean save(String filename, String header)
filename
- Path where the file should be saved.header
- The header of the file or null
if not wanted.true
if file was successfully written, false
if not.public void setDefaultConfigFileHeader(String header)
header
- A simple config file header as String.public void setNewMainClass(JTS3ServerMod_Interface mainClass)
mainClass
- A new main class, will be needed to access the addLogEntry method to write log entries.public boolean setValue(String key, boolean value)
key
- Name of the keyvalue
- Value for the key, will be converted to String.true
if the value was set, false
if key not found.public boolean setValue(String key, double value)
key
- Name of the keyvalue
- Value for the key, will be converted to String.true
if the value was set, false
if key not found.public boolean setValue(String key, long value)
key
- Name of the keyvalue
- Value for the key, will be converted to String.true
if the value was set, false
if key not found.public boolean setValue(String key, String value)
key
- Name of the keyvalue
- Value for the keytrue
if the value was set, false
if key not found.public void setWriteProtection(boolean flag)
true
to make sure, that no values will be changed, removed or added.flag
- Set true
to prevent any changes to the configuration.