Class GenericBuilder<Base extends Config,Result extends FileConfig>
- java.lang.Object
-
- com.electronwill.nightconfig.core.file.GenericBuilder<Base,Result>
-
- Direct Known Subclasses:
CommentedFileConfigBuilder,FileConfigBuilder
public abstract class GenericBuilder<Base extends Config,Result extends FileConfig> extends java.lang.ObjectA generic FileConfig/CommentedFileConfig/someOtherFileConfig builder. The default settings are:- Charset: UTF-8 - change it with
charset(Charset) - WritingMode: REPLACE - change it with
writingMode(WritingMode) - ParsingMode: REPLACE - change it with
parsingMode(ParsingMode) - FileNotFoundAction: CREATE_EMPTY - change it with
onFileNotFound(FileNotFoundAction) - Asynchronous writing, ie config.save() returns quickly and operates in the background -
change it with
sync() - Not autosaved - change it with
autosave() - Not autoreloaded - change it with
autoreload() - Not thread-safe - change it with
concurrent() - Values' insertion order preserved if
Config.isInsertionOrderPreserved()returns true when the builder is constructed.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanautoreloadprotected booleanautosaveprotected java.nio.charset.Charsetcharsetprotected booleanconcurrentprotected java.nio.file.Pathfileprotected ConfigFormat<? extends Base>formatprotected booleaninsertionOrderprotected java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>>mapCreatorprotected FileNotFoundActionnefActionprotected ConfigParser<? extends Base>parserprotected ParsingModeparsingModeprotected booleansyncprotected ConfigWriterwriterprotected WritingModewritingMode
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description GenericBuilder<Base,Result>autoreload()Makes the configuration "autoreloaded", that is, itsFileConfig.load()method is automatically called when the file is modified.GenericBuilder<Base,Result>autosave()Makes the configuration "autosaved", that is, itsFileConfig.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.Resultbuild()Creates a new FileConfig with the chosen settings.protected abstract ResultbuildAutosave(FileConfig chain)protected abstract ResultbuildNormal(FileConfig chain)GenericBuilder<Base,Result>charset(java.nio.charset.Charset charset)Sets the charset used forFileConfig.save()andFileConfig.load().GenericBuilder<Base,Result>concurrent()Makes the configuration concurrent, that is, thread-safe.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.net.URL url)Sets the URL of the data 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>defaultResource(java.lang.String resourcePath)Sets the resource (in the jar) to copy when the config's file is not found.protected BasegetConfig()GenericBuilder<Base,Result>onFileNotFound(FileNotFoundAction nefAction)Sets the action to execute when the config's file is not found.GenericBuilder<Base,Result>parsingMode(ParsingMode parsingMode)Sets the ParsingMode used forFileConfig.load()GenericBuilder<Base,Result>preserveInsertionOrder()Makes the configuration preserve the insertion order of its values.GenericBuilder<Base,Result>sync()Makes the configuration "write-synchronized", that is, itsFileConfig.save()method blocks until the write operation completes.GenericBuilder<Base,Result>writingMode(WritingMode writingMode)Sets the WritingMode used forFileConfig.save()
-
-
-
Field Detail
-
file
protected final java.nio.file.Path file
-
format
protected final ConfigFormat<? extends Base extends Config> format
-
writer
protected final ConfigWriter writer
-
parser
protected final ConfigParser<? extends Base extends Config> parser
-
charset
protected java.nio.charset.Charset charset
-
writingMode
protected WritingMode writingMode
-
parsingMode
protected ParsingMode parsingMode
-
nefAction
protected FileNotFoundAction nefAction
-
sync
protected boolean sync
-
autosave
protected boolean autosave
-
autoreload
protected boolean autoreload
-
concurrent
protected boolean concurrent
-
insertionOrder
protected boolean insertionOrder
-
mapCreator
protected java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator
-
-
Method Detail
-
charset
public GenericBuilder<Base,Result> charset(java.nio.charset.Charset charset)
Sets the charset used forFileConfig.save()andFileConfig.load().- Returns:
- this builder
-
writingMode
public GenericBuilder<Base,Result> writingMode(WritingMode writingMode)
Sets the WritingMode used forFileConfig.save()- Returns:
- this builder
-
parsingMode
public GenericBuilder<Base,Result> parsingMode(ParsingMode parsingMode)
Sets the ParsingMode used forFileConfig.load()- Returns:
- this builder
-
onFileNotFound
public GenericBuilder<Base,Result> onFileNotFound(FileNotFoundAction nefAction)
Sets the action to execute when the config's file is not found.- Returns:
- this builder
-
defaultResource
public GenericBuilder<Base,Result> defaultResource(java.lang.String resourcePath)
Sets the resource (in the jar) to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyResource(resourcePath))- Parameters:
resourcePath- the resource's path- Returns:
- this builder
-
defaultData
public GenericBuilder<Base,Result> defaultData(java.io.File file)
Sets the file to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(file))- Parameters:
file- the data file- Returns:
- this builder
-
defaultData
public GenericBuilder<Base,Result> defaultData(java.nio.file.Path file)
Sets the file to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(file))- Parameters:
file- the data file- Returns:
- this builder
-
defaultData
public GenericBuilder<Base,Result> defaultData(java.net.URL url)
Sets the URL of the data to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(url))- Parameters:
url- the data url- Returns:
- this builder
-
sync
public GenericBuilder<Base,Result> sync()
Makes the configuration "write-synchronized", that is, itsFileConfig.save()method blocks until the write operation completes.- Returns:
- this builder
-
autosave
public GenericBuilder<Base,Result> autosave()
Makes the configuration "autosaved", that is, itsFileConfig.save()method is automatically called when it is modified.- Returns:
- this builder
-
autoreload
public GenericBuilder<Base,Result> autoreload()
Makes the configuration "autoreloaded", that is, itsFileConfig.load()method is automatically called when the file is modified.- Returns:
- this builder
-
concurrent
public GenericBuilder<Base,Result> concurrent()
Makes the configuration concurrent, that is, thread-safe.- Returns:
- this builder
-
preserveInsertionOrder
public GenericBuilder<Base,Result> preserveInsertionOrder()
Makes the configuration preserve the insertion order of its values.- Returns:
- this builder
-
backingMapCreator
public 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.
Warning : ifautoreload()is called, the map creator must return thread-safe maps, because the autoreloading system will modify the configuration from another thread.- Parameters:
s- the map supplier to use- Returns:
- this builder
-
build
public Result build()
Creates a new FileConfig with the chosen settings.- Returns:
- the config
-
buildAutosave
protected abstract Result buildAutosave(FileConfig chain)
-
buildNormal
protected abstract Result buildNormal(FileConfig chain)
-
getConfig
protected final Base getConfig()
-
-