public class Section extends CSection
Simple Value 1: True
Simple Value 2: 20
Simple Value 3: 10.01
Simple Value 4: This is a simple string
Simple Value 5: "Quotes \" are required \'"
Short List 1: ["10", "Hey", "Yes"]
List 2:
- Yes
- 20
- 10.01
- This is a simple string
Section 1:
A value: 10
Subsection 1:
A value: 20
A list:
- 20
- 30
Section 2:
Subsection:
A value: true
Config config = Config.getNewConfig(getLogger(), new File(""), "config.yml");
ISection section1 = config.getSection("Section 1");
config.getKeys("section1", false);
//[Section1.A value, Section1.Subsection 1, Section1.A list]
section1.getKeys(false);
//[A value, Subsection 1, A list]
section1.getKeys(true);
//[A value, Subsection 1, Subsection 1.A value, A list]
//(Returned order can be different)
config.getString("Section1.A value");
//10
section1.getString("A value");
//10
section1.set("A list", new int[] {20, 30});
config.getIntegerList("Section1.A list");
//[20, 30]
config.getDoubleList("Section1.A list");
//[20.0, 30.0]
section1.getStringList("A list");
//["20", "30"]
section1.set("A list", new double[] {11.0, 12.9, 9.9999999});
section1.getIntegerList("A list");
//[11, 12, 9]
section1.getStringList("A list");
//["11.0", "12.9", "9.99999"] (rounded to 5 decimals)
| Modifier and Type | Field and Description |
|---|---|
protected ISection |
parent |
protected String |
path |
| 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) |
boolean |
contains(String path)
Returns if this section contains a list or single value for the given path.
|
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. |
String |
getName()
Returns the name of this Section.
|
ISection |
getParent() |
String |
getPath()
Returns the path of this Section, relative to the main config.
|
protected String |
getPathTo(String path) |
ISection |
getSection(String path)
Gets the requested
Section by path.Returns an empty section if it didn't exist. |
boolean |
remove(String path,
boolean renew)
Removes a Single value, List or Section from the config.
|
boolean |
removeEntry(Line line) |
void |
renew()
|
boolean |
saveConfig() |
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. |
protected static void |
validatePath(String path) |
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, setListpublic Section(ISection parent, String path)
path - IllegalArgumentException - If path is null or ends with a dot.public ISection getParent()
public ISection getSection(String path)
ISectionSection by path.public Set<String> getKeys(boolean deep)
ISectiondeep - - Whether or not to get a deep list, as opposed to a shallow list.public Set<String> getKeys(String path, boolean deep)
ISectionpath - - The path the key has to start with to be included in the returned set.deep - - Whether or not to get a deep list, as opposed to a shallow list.public String getPath()
ISectionpublic String getName()
ISectionpublic Line get(String path)
ISectionnull if no line with the given path exists.public boolean contains(String path)
ISectionpath - - The path to check.public 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.path - - The path to remove.renew - - If the configuration should be updated to reflect the changes.public boolean setList(String path, boolean removeComments, boolean renew, Iterable<?> value)
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.)path - - The path of the entry you want to change.renew - - If the config should be updated. Only applies for removals and insertions.public void renew()
ISectionpublic void addEntry(Line line)
public boolean removeEntry(Line line)
protected static void validatePath(String path)
public boolean saveConfig()
public void addCommentsAbove(String path, boolean belowExistingComments, String... comments)
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)
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 addCopyright © 2014. All rights reserved.