public abstract class GenericBuilder<Base extends Config,Result extends FileConfig>
extends java.lang.Object
charset(Charset)writingMode(WritingMode)parsingMode(ParsingMode)onFileNotFound(FileNotFoundAction)sync()autosave()autoreload()Config.isInsertionOrderPreserved()
returns true when the builder is constructed.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
atomicMove |
protected java.lang.Runnable |
autoLoadListener |
protected FileWatcher |
autoreloadFileWatcher |
protected boolean |
autosave |
protected java.lang.Runnable |
autoSaveListener |
protected java.nio.charset.Charset |
charset |
protected java.nio.file.Path |
file |
protected ConfigFormat<? extends Base> |
format |
protected java.lang.Runnable |
loadListener |
protected java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> |
mapCreator |
protected FileNotFoundAction |
nefAction |
protected ConfigParser<? extends Base> |
parser |
protected ParsingMode |
parsingMode |
protected boolean |
preserveInsertionOrder |
protected java.lang.Runnable |
saveListener |
protected boolean |
sync |
protected ConfigWriter |
writer |
protected WritingMode |
writingMode |
| Modifier and Type | Method and Description |
|---|---|
GenericBuilder<Base,Result> |
async()
Makes the configuration "write-asynchronous", that is, its
FileConfig.save()
method does not wait for the write operation to complete. |
GenericBuilder<Base,Result> |
asyncWithDebouncing(java.time.Duration debounceTime)
Makes the configuration "write-asynchronous" and specifies its debouncing time.
|
GenericBuilder<Base,Result> |
autoreload()
Makes the configuration "autoreloaded", that is, its
FileConfig.load() method is
automatically called when the file is modified. |
GenericBuilder<Base,Result> |
autoreload(FileWatcher fileWatcher)
Makes the configuration "autoreloaded", using the given FileWatcher to monitor the config file.
|
GenericBuilder<Base,Result> |
autosave()
Makes the configuration "autosaved", that is, its
FileConfig.save() method is
automatically called when it is modified. |
GenericBuilder<Base,Result> |
backingMapCreator(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> s)
Uses a specific Supplier to create the backing maps (one for the top level
and one for each sub-configuration) of the configuration.
|
Result |
build()
Creates a new FileConfig with the chosen settings.
|
protected Result |
buildAutosave(CommentedFileConfig chain) |
protected Result |
buildNormal(CommentedFileConfig chain) |
GenericBuilder<Base,Result> |
charset(java.nio.charset.Charset charset)
Sets the charset used for
FileConfig.save() and FileConfig.load(). |
GenericBuilder<Base,Result> |
concurrent()
Deprecated.
Since NightConfig v3.7, this method has no effect because all FileConfig are thread-safe,
backed by
ConcurrentConfig. |
GenericBuilder<Base,Result> |
defaultData(java.io.File file)
Sets the file to copy when the config's file is not found.
|
GenericBuilder<Base,Result> |
defaultData(java.nio.file.Path file)
Sets the file to copy when the config's file is not found.
|
GenericBuilder<Base,Result> |
defaultData(java.net.URL url)
Sets the URL of the data to copy when the config's file is not found.
|
GenericBuilder<Base,Result> |
defaultResource(java.lang.String resourcePath)
Sets the resource (in the jar) to copy when the config's file is not found.
|
GenericBuilder<Base,Result> |
onAutoReload(java.lang.Runnable listener)
When the configuration is automatically (re)loaded, calls the given listener.
|
GenericBuilder<Base,Result> |
onAutoSave(java.lang.Runnable listener)
When the configuration triggers an automatic save, calls the given listener.
|
GenericBuilder<Base,Result> |
onFileNotFound(FileNotFoundAction notFoundAction)
Sets the action to execute when the config's file is not found.
|
GenericBuilder<Base,Result> |
onLoad(java.lang.Runnable listener)
When the configuration is (re)loaded, calls the given listener.
|
GenericBuilder<Base,Result> |
onLoadFilter(ConfigLoadFilter filter)
When the configuration is (re)loaded, applies the given filter first.
|
GenericBuilder<Base,Result> |
onSave(java.lang.Runnable listener)
When the configuration is saved, calls the given listener.
|
GenericBuilder<Base,Result> |
parsingMode(ParsingMode parsingMode)
Sets the ParsingMode used for
FileConfig.load(). |
GenericBuilder<Base,Result> |
preserveInsertionOrder()
Makes the configuration preserve the insertion order of its values.
|
GenericBuilder<Base,Result> |
sync()
Makes the configuration "write-synchronous", that is, its
FileConfig.save()
method blocks until the write operation completes. |
GenericBuilder<Base,Result> |
writingMode(WritingMode writingMode)
Sets the WritingMode used for
FileConfig.save(). |
protected final java.nio.file.Path file
protected final ConfigFormat<? extends Base extends Config> format
protected final ConfigWriter writer
protected final ConfigParser<? extends Base extends Config> parser
protected java.nio.charset.Charset charset
protected WritingMode writingMode
protected ParsingMode parsingMode
protected FileNotFoundAction nefAction
protected boolean sync
protected boolean autosave
protected boolean atomicMove
protected FileWatcher autoreloadFileWatcher
protected boolean preserveInsertionOrder
protected java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator
protected java.lang.Runnable loadListener
protected java.lang.Runnable saveListener
protected java.lang.Runnable autoLoadListener
protected java.lang.Runnable autoSaveListener
public GenericBuilder<Base,Result> charset(java.nio.charset.Charset charset)
FileConfig.save() and FileConfig.load().charset - the charset to decode the characters withpublic GenericBuilder<Base,Result> writingMode(WritingMode writingMode)
FileConfig.save().
Example:
FileConfig config = FileConfig.builder(file).writingMode(WritingMode.REPLACE_ATOMIC).build();
writingMode - how to write to the filepublic GenericBuilder<Base,Result> parsingMode(ParsingMode parsingMode)
FileConfig.load().parsingMode - how to handle conflicts between the existing entries and the new entries that are read
from the filepublic GenericBuilder<Base,Result> onFileNotFound(FileNotFoundAction notFoundAction)
notFoundAction - what to do when the file does not existpublic GenericBuilder<Base,Result> defaultResource(java.lang.String resourcePath)
onFileNotFound(FileNotFoundAction.copyResource(resourcePath))resourcePath - the resource's pathpublic GenericBuilder<Base,Result> defaultData(java.io.File file)
onFileNotFound(FileNotFoundAction.copyData(file))file - the data filepublic GenericBuilder<Base,Result> defaultData(java.nio.file.Path file)
onFileNotFound(FileNotFoundAction.copyData(file))file - the data filepublic GenericBuilder<Base,Result> defaultData(java.net.URL url)
onFileNotFound(FileNotFoundAction.copyData(url))url - the data urlpublic GenericBuilder<Base,Result> sync()
FileConfig.save()
method blocks until the write operation completes.public GenericBuilder<Base,Result> async()
FileConfig.save()
method does not wait for the write operation to complete.
An automatic debouncing of unspecified duration is applied.
public GenericBuilder<Base,Result> asyncWithDebouncing(java.time.Duration debounceTime)
The config's FileConfig.save() method will not wait for the write operation to complete,
and perform a debouncing of the given duration. Calling FileConfig.save() twice with
less than debounceTime in between will cancel the first save and only perform the second.
debounceTime - the minimal time between two savespublic GenericBuilder<Base,Result> autosave()
FileConfig.save() method is
automatically called when it is modified.public GenericBuilder<Base,Result> autoreload()
FileConfig.load() method is
automatically called when the file is modified.public GenericBuilder<Base,Result> autoreload(FileWatcher fileWatcher)
fileWatcher - the FileWatcher to register a watch to, in order to reload the config when the file
changespublic GenericBuilder<Base,Result> onAutoReload(java.lang.Runnable listener)
onAutoReload multiple times will replace the listener.
The listener is called once the loading operation is complete.
If a ConfigLoadFilter is set and rejects the operation, the listener is not called.
If FileConfig.load() is called manually rather than automatically, the listener is not called.
Use onLoad(Runnable) to be notified of every call to FileConfig.load(), including manual
ones.
If autoreload() is not called, setting a listener has no effect.
listener - the listener to call when the FileConfig is automatically reloadedpublic GenericBuilder<Base,Result> onAutoSave(java.lang.Runnable listener)
onAutoSave multiple times will replace the listener.
If the FileConfig is asynchronous and a debouncing occurs, the listener can be called without an actual saving operation being executed (due to the debouncing, the actual save will occur later). Otherwise, the listener is called once the saving operation is complete.
If FileConfig.save() is called manually rather than automatically, the listener is not called.
Use onSave(Runnable) to be notified of every call to FileConfig.save(), including manual
ones.
If autosave() is not called on the builder, setting a listener has no effect.
listener - the listener to call when the FileConfig is automatically savedpublic GenericBuilder<Base,Result> onLoad(java.lang.Runnable listener)
onLoad multiple times will replace the listener.
It is possible to set both an "auto-load" listener and a "load" listener at the same time.
The listener is called once the loading operation is complete.
If a ConfigLoadFilter is set and rejects the operation, the listener is not called.
If autoreload() is not called on the builder, setting a listener has no effect.
listener - the listener to call when the FileConfig is automatically reloadedpublic GenericBuilder<Base,Result> onSave(java.lang.Runnable listener)
onSave multiple times will replace the listener.
It is possible to set both an "auto-save" listener and a "save" listener at the same time.
The listener is called once the saving operation is complete.
If a ConfigLoadFilter is set and rejects the operation, the listener is not called.
If autosave() is not called, setting a listener has no effect.
listener - the listener to call when the FileConfig is automatically savedpublic GenericBuilder<Base,Result> onLoadFilter(ConfigLoadFilter filter)
If a listener is set and the filter accepts the operation, the listener is called after the filter. If a listener is set and the filter rejects the operation, the listener is not called.
filter - the filter to call on FileConfig.load()@Deprecated public GenericBuilder<Base,Result> concurrent()
ConcurrentConfig.public GenericBuilder<Base,Result> preserveInsertionOrder()
If this method is not called, the default value of Config.isInsertionOrderPreserved() is applied.
public GenericBuilder<Base,Result> backingMapCreator(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> s)
s - the map supplier to usepublic Result build()
protected Result buildAutosave(CommentedFileConfig chain)
protected Result buildNormal(CommentedFileConfig chain)