Package me.neznamy.tab.api.config
Class ConfigurationFile
java.lang.Object
me.neznamy.tab.api.config.ConfigurationFile
- Direct Known Subclasses:
YamlConfigurationFile
Abstract class for configuration file
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConfigurationFile(InputStream source, File destination) Constructs new instance and attempts to load specified configuration file. -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts header back into file.booleangetBoolean(String path, boolean defaultValue) Returns config option with specified path asBoolean.<K,V> Map<K, V> Returns config option with specified path asMap<K, V>.Returns config option with specified path asDouble.getFile()Returns config option with specified path asInteger.Returns config option with specified path asInteger.getName()Returns simple name of the fileReturns config option with specified path.Gets config option with specified path.Returns config option with specified path asString.Returns config option with specified path asString.getStringList(String path) Returns config option with specified path asList<String>.getStringList(String path, List<String> defaultValue) Returns config option with specified path asList<String>.Returns the root value mapbooleanhasConfigOption(String path) Returnstrueif the file has option with specified path,falseif not.abstract voidsave()Saves values from map to the filevoidSets value to the specified path and saves the file to disk by callingsave().void
-
Field Details
-
header
Comments on top of the file -
values
Configuration file content -
file
File to use
-
-
Constructor Details
-
ConfigurationFile
Constructs new instance and attempts to load specified configuration file. If file does not exist, default file is copied fromsource.- Parameters:
source- Source to copy file from if it does not existdestination- File destination to use- Throws:
IllegalArgumentException- ifdestinationis nullIllegalStateException- if file does not exist and source is nullIOException- if I/O operation with the file unexpectedly fails
-
-
Method Details
-
save
public abstract void save()Saves values from map to the file -
getName
Returns simple name of the file- Returns:
- simple name of the file
-
getValues
Returns the root value map- Returns:
- the root value map
-
setValues
-
getObject
Gets config option with specified path. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path to the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file
-
getObject
Returns config option with specified path. If option is not present,nullis returned.- Parameters:
path- Path to the option with sections separated with "."- Returns:
- value from configuration file or null if not present
-
getObject
-
getString
Returns config option with specified path asString. Returnsnullif option is not present.- Parameters:
path- Path to the option with sections separated with "."- Returns:
- value from file or null if not present
-
getString
Returns config option with specified path asString. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path to the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file as
String
-
getStringList
Returns config option with specified path asList<String>. Returnsnullif option is not present.- Parameters:
path- Path to the option with sections separated with "."- Returns:
- value from file or null if not present
-
getStringList
Returns config option with specified path asList<String>. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path of the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file as
List<String>
-
getInt
Returns config option with specified path asInteger. Returnsnullif option is not present.- Parameters:
path- Path to the option with sections separated with "."- Returns:
- value from file or null if not present
-
getInt
Returns config option with specified path asInteger. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path to the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file as
Integer
-
getBoolean
Returns config option with specified path asBoolean. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path to the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file as
Boolean
-
getDouble
Returns config option with specified path asDouble. If the option is not present anddefaultValueis notnull, value is inserted,save()called anddefaultValuereturned.- Parameters:
path- Path to the option with sections separated with "."defaultValue- Value to be inserted and returned if option is not present- Returns:
- value from configuration file as
Double
-
getConfigurationSection
Returns config option with specified path asMap<K, V>. If the option is not present or value is not aMap, new emptyMapis returned.- Parameters:
path- Path to the option with sections separated with "."- Returns:
- value from configuration file as
Map<K, V>
-
hasConfigOption
Returnstrueif the file has option with specified path,falseif not.- Parameters:
path- Path to the option with sections separated with "."- Returns:
trueif present,falseif not
-
set
Sets value to the specified path and saves the file to disk by callingsave().- Parameters:
path- Path to the option with sections separated with "."value- Value to save
-
fixHeader
Inserts header back into file. This is required after callingsave(), because it destroys the header.- Throws:
IOException- if I/O operation fails
-
getFile
-