public class Config extends CSection implements IConfig
renew() is called.getNewConfig(Logger, File, String)| Modifier and Type | Field and Description |
|---|---|
protected File |
file |
protected List<String> |
lines
The original contents of the config file.
|
protected List<Line> |
lines2
Holds the converted configuration.
|
protected ReentrantReadWriteLock |
lock |
protected Logger |
logger |
protected LinkedHashMap<String,Line> |
map
Allows fast, non blocking access to this configuration, only contains ValueLines and ListLines.
|
| Constructor and Description |
|---|
Config(Logger logger,
File file) |
Config(Logger logger,
File folder,
String filename) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCommentsAbove(String path,
boolean belowExistingComments,
String... comments)
Adds the given comments above the Entry at the given path.
|
void |
addCommentsBelow(String path,
boolean belowExistingComments,
String... comments)
Adds the given comments below the Entry at the given path.
|
void |
addEntry(Line line) |
protected boolean |
changeTo(Line line,
boolean renew) |
void |
clear()
Clears the memory configuration.
|
boolean |
contains(String path)
Returns if this section contains a list or single value for the given path.
|
protected String |
convert(Object value)
Convenience method for overriding classes :)
|
Line |
get(String path)
Gets the line with the given path.
Returns null if no line with the given path exists. |
List<Line> |
getEntries() |
List<Line> |
getEntries(String path) |
Set<String> |
getKeys(boolean deep)
Gets a set containing all keys in this section.
If deep is set to true, then this will contain all the keys within any child Sections (and their children, etc). These will be in a valid path notation for you to use. If deep is set to false, then this will contain only the keys of any direct children, and not their own children. |
Set<String> |
getKeys(String path,
boolean deep)
Gets a set containing all keys that start with the given path in this section.
If deep is set to true, then this will contain all the keys within any child Sections (and their children, etc). These will be in a valid path notation for you to use. If deep is set to false, then this will contain only the keys of any direct children, and not their own children. |
Set<String> |
getKeys(String path,
boolean deep,
boolean strippath) |
protected Logger |
getLogger()
Convenience for overriding classes :)
|
String |
getName()
Returns the name of this Section.
|
static Config |
getNewConfig(Logger logger,
File folder,
String name)
Creates a new config and loads it.
If the file doesn't exist, will save the default config. Example usage:
public static Config config;You can then get values by doing:
String str = config.getString("path.to.str");You can set values like so:
config.set("Section1.tutorial", "This is a tutorial!"); |
protected ListLine |
getNewListLine(String path,
boolean shorttype)
Can by overridden by classes that override this class to implement a different type of ListLine.
Now you don't have to rewrite parse() :) |
protected ValueLine |
getNewValueLine(String path,
String value)
Can by overridden by classes that override this class to implement a different type of ValueLine.
Now you don't have to rewrite parse() :) |
ISection |
getParent() |
String |
getPath()
Returns the path of this Section, relative to the main config.
|
ISection |
getSection(String path)
Gets the requested
Section by path.Returns an empty section if it didn't exist. |
ISection |
getSectionSnapshot(String path)
Deprecated.
Not all functions work as you would expect them to. Please use
getSection(String) instead. |
protected void |
insertCorrectly(Line line,
boolean renew) |
boolean |
load()
(Re)loads this config from disk.
|
boolean |
load(File file) |
boolean |
reloadConfig()
Reloads this config from disk.
|
boolean |
remove(String path,
boolean renew)
Removes a Single value, List or Section from the config.
|
int |
removeComment(String comment,
boolean caseSensitive,
int amount)
Removes matching comments from this Config.
|
boolean |
removeEntry(Line line) |
void |
renew()
|
boolean |
saveConfig()
Saves this config and returns its success.
|
boolean |
saveDefaultConfig()
Saves the default config if this config file doesn't exist yet.
Otherwise does nothing. |
boolean |
set(String path,
boolean renew,
Object value)
Sets the value of the item at the given path to the given value.
If value is null, the entry is removed.NOTE: Calling this method WILL affect the actual config, but the changes may or may not be reflected in this IConfigSection. (Removals and Insertions will not affect SectionSnapshots, but will affect the config.) |
boolean |
setList(String path,
boolean removeComments,
boolean renew,
Iterable<?> value)
Sets the entry at the specified path to a list with the given value.
If this path defines an already existing list entry, it is changed. If this path defines an already existing single entry, it will be changed into a list. If this path defines a non existant entry, it and required sections are created and inserted at the right position in the config. |
getBoolean, getBoolean, getBooleanList, getByte, getByte, getByteList, getChar, getChar, getCharacterList, getDouble, getDouble, getDoubleList, getFloat, getFloat, getFloatList, getInt, getInt, getIntegerList, getLong, getLong, getLongList, getMixedList, getObject, getObject, getShort, getShort, getShortList, getString, getString, getStringList, getT, getT, getTList, isBoolean, isByte, isChar, isDouble, isFloat, isInt, isLong, isShort, isString, isT, remove, removeBatch, removeBatch, setList, setList, setListclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitremove, removeBatch, removeBatch, setList, setList, setListgetBoolean, getBoolean, getBooleanList, getByte, getByte, getByteList, getChar, getChar, getCharacterList, getDouble, getDouble, getDoubleList, getFloat, getFloat, getFloatList, getInt, getInt, getIntegerList, getLong, getLong, getLongList, getMixedList, getObject, getObject, getShort, getShort, getShortList, getString, getString, getStringList, getT, getT, getTList, isBoolean, isByte, isChar, isDouble, isFloat, isInt, isLong, isShort, isString, isTprotected final ReentrantReadWriteLock lock
protected LinkedHashMap<String,Line> map
protected File file
protected Logger logger
public static Config getNewConfig(Logger logger, File folder, String name)
public static Config config;
public void load(){
config = Config.getNewConfig(this.getLogger(), new File(""), "config.yml");
}
String str = config.getString("path.to.str");
int i = config.getInt("path.to.i");
List<Boolean> booleans = config.getBooleanList("path.to.list");
ISection section1 = config.getSection("Section1");
//Gets Section1.hey, if it doesn't exist, returns 20.
int hey = section1.getInt("hey", 20);
config.set("Section1.tutorial", "This is a tutorial!");
config.set("Section1.tutorial", null); //removes tuturial
config.remove("Section1"); //Removes Section1 and everything in it
List<String> l = new ArrayList<>();
l.add("Entry 1");
l.add("Entry 2");
config.set("Section1.list", l);
//You can also keep comments that were in Section1.list
config.setList("Section1.list", false, l);
//Don't forget to save.
config.saveConfig();
logger - - The logger where warnings are logged.folder - - The folder where this config should go.name - - The name of this config.IllegalArgumentException - If logger is null.IllegalArgumentException - If folder is null.IllegalArgumentException - If name is null, empty or ends with a dot (.).public boolean load()
IConfigpublic boolean load(File file)
public boolean reloadConfig()
reloadConfig in interface IConfigIConfig.load()public boolean saveDefaultConfig()
saveDefaultConfig in interface IConfigpublic boolean saveConfig()
saveConfig in interface IConfigsaveConfig in interface ISectionpublic void clear()
protected ValueLine getNewValueLine(String path, String value)
parse() :)new ValueLine(path, value);protected ListLine getNewListLine(String path, boolean shorttype)
parse() :)new ListLine(path, shorttype);public void renew()
ISectionpublic Line get(String path)
ISectionnull if no line with the given path exists.public Set<String> getKeys(boolean deep)
ISectionpublic Set<String> getKeys(String path, boolean deep)
ISectionpublic String getName()
ISectionpublic String getPath()
ISectionpublic boolean contains(String path)
ISectionpublic ISection getSection(String path)
ISectionSection by path.getSection in interface ISectionpath - - Path of the Section to get.Section@Deprecated public ISection getSectionSnapshot(String path)
getSection(String) instead.path - - Path of the Section to get a SnapShot of.public void addCommentsAbove(String path, boolean belowExistingComments, String... comments)
ISectionaddCommentsAbove in interface ISectionpath - - The path of the entry to add the comments above. If path is empty, comments will be added at the top.belowExistingComments - - Should the given comments be added below existing ones?comments - - The comments to addpublic void addCommentsBelow(String path, boolean belowExistingComments, String... comments)
ISectionaddCommentsBelow in interface ISectionpath - - The path of the entry to add the comments below. If path is empty, comments will be added at the top.belowExistingComments - - Should the given comments be added below existing ones?comments - - The comments to addpublic boolean remove(String path, boolean renew)
ISectionISection.renew().
For removals, this can easily be achieved by calling removeBatch(String...)."", this function will CLEAR the config.public int removeComment(String comment, boolean caseSensitive, int amount)
comment - - The comment to remove.caseSensitive - - If it should scan for comments case sensitive.amount - - The max amount of comments to remove. -1 is infinite.public boolean setList(String path, boolean removeComments, boolean renew, Iterable<?> value)
ISectionsetList in interface ISectionpath - - The path of the list to set.removeComments - - If the list already exists, should comments in it be removed?renew - - If the map should be renewed (when applicable).value - - The values this list should have.public boolean set(String path, boolean renew, Object value)
ISectionnull, the entry is removed.SectionSnapshots, but will affect the config.)public List<Line> getEntries()
getEntries in interface ISectionpublic List<Line> getEntries(String path)
getEntries in interface ISectionpublic boolean removeEntry(Line line)
removeEntry in interface ISectionprotected void insertCorrectly(Line line, boolean renew)
protected boolean changeTo(Line line, boolean renew)
protected Logger getLogger()
Copyright © 2014. All rights reserved.