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 Object
A generic FileConfig/CommentedFileConfig/someOtherFileConfig builder. The default settings are:
  • Field Details

    • file

      protected final 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 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 Supplier<Map<String,Object>> mapCreator
  • Method Details

    • charset

      public GenericBuilder<Base,Result> charset(Charset charset)
      Sets the charset used for FileConfig.save() and FileConfig.load().
      Returns:
      this builder
    • writingMode

      public GenericBuilder<Base,Result> writingMode(WritingMode writingMode)
      Sets the WritingMode used for FileConfig.save()
      Returns:
      this builder
    • parsingMode

      public GenericBuilder<Base,Result> parsingMode(ParsingMode parsingMode)
      Sets the ParsingMode used for FileConfig.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(String resourcePath)
      Sets the resource (in the jar) to copy when the config's file is not found. This is a shortcut for onFileNotFound(FileNotFoundAction.copyResource(resourcePath))
      Parameters:
      resourcePath - the resource's path
      Returns:
      this builder
    • defaultData

      public GenericBuilder<Base,Result> defaultData(File file)
      Sets the file to copy when the config's file is not found. This is a shortcut for onFileNotFound(FileNotFoundAction.copyData(file))
      Parameters:
      file - the data file
      Returns:
      this builder
    • defaultData

      public GenericBuilder<Base,Result> defaultData(Path file)
      Sets the file to copy when the config's file is not found. This is a shortcut for onFileNotFound(FileNotFoundAction.copyData(file))
      Parameters:
      file - the data file
      Returns:
      this builder
    • defaultData

      public GenericBuilder<Base,Result> defaultData(URL url)
      Sets the URL of the data to copy when the config's file is not found. This is a shortcut for onFileNotFound(FileNotFoundAction.copyData(url))
      Parameters:
      url - the data url
      Returns:
      this builder
    • sync

      public GenericBuilder<Base,Result> sync()
      Makes the configuration "write-synchronized", that is, its FileConfig.save() method blocks until the write operation completes.
      Returns:
      this builder
    • autosave

      public GenericBuilder<Base,Result> autosave()
      Makes the configuration "autosaved", that is, its FileConfig.save() method is automatically called when it is modified.
      Returns:
      this builder
    • autoreload

      public GenericBuilder<Base,Result> autoreload()
      Makes the configuration "autoreloaded", that is, its FileConfig.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(Supplier<Map<String,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 : if autoreload() 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()