Class EntryBuilder

java.lang.Object
org.apache.juneau.config.EntryBuilder

public class EntryBuilder extends Object
A fluent builder for adding or updating a single Config entry.

This is an ergonomic, self-documenting alternative to the multi-argument Config.set(String, Object, Serializer, String, String, List) overload. That overload packs several distinct "leave-unchanged versus clear" sentinel conventions into one call (a null comment leaves the existing comment untouched while a blank comment clears it; a null pre-lines list leaves the existing pre-lines untouched while an empty list clears them). This builder replaces those sentinels with explicit methods:

The write is performed by the terminal set(Object) or set() method. The result is identical to the equivalent Config.set(String, Object, Serializer, String, String, List) call.

Example:

// Add an entry with a comment and pre-lines. config.entry("MySection/myKey") .comment("My comment") .preLines(List.of("# A pre-line")) .set("My value"); // Update only the comment on an existing entry, leaving the value and pre-lines untouched. config.entry("MySection/myKey") .comment("Updated comment") .set(); // Clear the comment on an existing entry. config.entry("MySection/myKey") .clearComment() .set();

Notes:
  • This builder is not thread safe and is intended to be used and discarded within a single statement.
See Also:
  • Constructor Details

    • EntryBuilder

      protected EntryBuilder(Config config, String key)
      Constructor.
      Parameters:
      config - The config that the entry belongs to.
      key - The key of the entry to add or update.
      Must not be null.
  • Method Details

    • value

      public EntryBuilder value(Object value)
      Specifies the value to store on the entry.

      Equivalent to passing the value to the terminal set(Object) method.

      Parameters:
      value - The new value POJO.
      Serialized to a string using the registered (or specified) serializer.
      Returns:
      This object.
    • serializer

      Specifies the serializer to use to serialize the value.

      If not called, the serializer registered on the config is used.

      Parameters:
      value - The serializer to use for serializing the value.
      Returns:
      This object.
    • modifiers

      public EntryBuilder modifiers(String value)
      Specifies the modifiers to apply to the value (e.g. "*" for encoded values).

      If not called, the modifiers on any existing entry are left untouched.

      Parameters:
      value - The modifiers to apply to the value.
      Returns:
      This object.
    • comment

      public EntryBuilder comment(String value)
      Specifies the same-line comment to add to the entry.

      If not called, the comment on any existing entry is left untouched.
      Use clearComment() to explicitly remove an existing comment.

      Parameters:
      value - The same-line comment to add to the entry. Must not be null (use clearComment() instead).
      Returns:
      This object.
    • clearComment

      Explicitly clears the same-line comment on the entry.
      Returns:
      This object.
    • preLines

      public EntryBuilder preLines(List<String> value)
      Specifies the comment or blank lines to add before the entry.

      If not called, the pre-lines on any existing entry are left untouched.
      Use clearPreLines() to explicitly remove existing pre-lines.

      Parameters:
      value - The comment or blank lines to add before the entry. Must not be null (use clearPreLines() instead).
      Returns:
      This object.
    • clearPreLines

      Explicitly clears the pre-lines on the entry.
      Returns:
      This object.
    • set

      public Config set() throws SerializeException
      Adds or updates the entry using the value specified via value(Object).
      Returns:
      The config that this builder belongs to.
      Throws:
      SerializeException - If serializer could not serialize the value or if a serializer is not registered with this config file.
      UnsupportedOperationException - If configuration is read only.
    • set

      public Config set(Object value) throws SerializeException
      Adds or updates the entry using the specified value.
      Parameters:
      value - The new value POJO.
      Serialized to a string using the registered (or specified) serializer.
      Returns:
      The config that this builder belongs to.
      Throws:
      SerializeException - If serializer could not serialize the value or if a serializer is not registered with this config file.
      UnsupportedOperationException - If configuration is read only.