Package top.focess.qq.api.util.config
Class Config
- java.lang.Object
-
- top.focess.qq.api.util.config.Config
-
- Direct Known Subclasses:
DefaultConfig,LangConfig
public abstract class Config extends Object
Represents a configuration.
-
-
Field Summary
Fields Modifier and Type Field Description protected top.focess.util.yaml.YamlConfigurationyaml
-
Constructor Summary
Constructors Modifier Constructor Description protectedConfig(@Nullable File file)Loads the configuration from the given file Note: if the file is null or not exists, it will create an empty configuration.protectedConfig(@Nullable InputStream stream)Loads the configuration from the given input streamprotectedConfig(@Nullable Map<String,Object> values)Loads the configuration from the given valuesprotectedConfig(top.focess.util.yaml.YamlConfiguration yaml)Loads the configuration from the given YamlConfiguration
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancontains(String key)Indicate there is a configuration named keyprotected <T> @Nullable Tget(String key)Get the value of the specified key@Nullable FilegetFile()Get the file of this configurationprotected abstract ConfiggetSection(String key)Get the section named key Note: if the section named key does not exist, it will be createdprotected Map<String,Object>getValues()Get all the configuration as a mapprotected voidremove(String key)Remove the configuration named keyprotected voidsave()Save the configuration to the fileprotected voidset(String key, @Nullable Object value)Set the value of the specified key
-
-
-
Constructor Detail
-
Config
protected Config(@Nullable File file) throws top.focess.util.yaml.YamlLoadException
Loads the configuration from the given file Note: if the file is null or not exists, it will create an empty configuration.- Parameters:
file- the file- Throws:
top.focess.util.yaml.YamlLoadException- if the file is not a valid yaml file
-
Config
protected Config(@Nullable InputStream stream)
Loads the configuration from the given input stream- Parameters:
stream- the given input stream
-
Config
protected Config(@Nullable Map<String,Object> values)
Loads the configuration from the given values- Parameters:
values- the given values
-
Config
protected Config(top.focess.util.yaml.YamlConfiguration yaml)
Loads the configuration from the given YamlConfiguration- Parameters:
yaml- the given YamlConfiguration
-
-
Method Detail
-
getFile
public @Nullable File getFile()
Get the file of this configuration- Returns:
- the file of this configuration or null if this configuration is not loaded from a file
-
get
protected <T> @Nullable T get(String key)
Get the value of the specified key- Type Parameters:
T- the value type- Parameters:
key- the key- Returns:
- the value
- Throws:
ClassCastException- if the value is not the specified type
-
set
protected void set(String key, @Nullable Object value)
Set the value of the specified key- Parameters:
key- the keyvalue- the value
-
save
protected void save()
Save the configuration to the file- Throws:
UnsupportedOperationException- if the configuration is not loaded from a file
-
getValues
protected Map<String,Object> getValues()
Get all the configuration as a map- Returns:
- all the configuration as a map
-
contains
protected boolean contains(String key)
Indicate there is a configuration named key- Parameters:
key- the key- Returns:
- true there is a configuration named key, false otherwise
-
remove
protected void remove(String key)
Remove the configuration named key- Parameters:
key- the key
-
getSection
protected abstract Config getSection(String key)
Get the section named key Note: if the section named key does not exist, it will be created- Parameters:
key- the key of the Section- Returns:
- the section named key
- Throws:
UnsupportedOperationException- if there is no section named key or the config does not support section
-
-