Class YamlCommentFormatter

java.lang.Object
org.simpleyaml.configuration.comments.format.YamlCommentFormatter
All Implemented Interfaces:
CommentFormatter
Direct Known Subclasses:
BlankLineYamlCommentFormatter, PrettyYamlCommentFormatter

public class YamlCommentFormatter extends Object implements CommentFormatter
Comment formatter to parse and dump YAML comments (using the # prefix).

Default format is YamlCommentFormat.DEFAULT.

  • Field Details

  • Constructor Details

  • Method Details

    • parse

      public String parse(Reader raw, CommentType type, KeyTree.Node node) throws IOException
      Description copied from interface: CommentFormatter
      Parse the comment from a reader that may contain a raw-formatted comment (for instance from a configuration file) to a human-friendly contentful representation of that comment.
      Specified by:
      parse in interface CommentFormatter
      Parameters:
      raw - the comment to parse that may contain special format characters with leading and trailing space
      type - the comment type
      node - the comment node
      Returns:
      the comment in the expected format to be read by humans
      Throws:
      IOException - if comment cannot be parsed
    • parseCommentLine

      protected String parseCommentLine(String line, String prefix, boolean strip)
    • dump

      public String dump(String comment, CommentType type, KeyTree.Node node)
      Description copied from interface: CommentFormatter
      Given a comment returns the raw-formatted string to be dumped somewhere like a file.
      Specified by:
      dump in interface CommentFormatter
      Parameters:
      comment - the comment to be dumped
      type - the comment type
      node - the comment node
      Returns:
      the raw-formatted comment string to be dumped, for instance to a configuration file
    • blockFormatter

      public final YamlCommentFormatterConfiguration blockFormatter()
    • sideFormatter

      public final YamlSideCommentFormatterConfiguration sideFormatter()
    • formatterConfiguration

      public final YamlCommentFormatterConfiguration formatterConfiguration(CommentType type)
    • stripPrefix

      public YamlCommentFormatter stripPrefix(boolean strip)
      Set if stripping the prefix is desired.

      If strip is true then the comment prefix will be stripped away.

      Default is true.

      Parameters:
      strip - if stripping the prefix is desired
      Returns:
      this object, for chaining
    • trim

      public YamlCommentFormatter trim(boolean trim)
      Set if leading and trailing spaces and blank lines at the beginning and end of the comments should be stripped away.

      This does not affect to every line of a multiline comment. Only to the beginning and end of the whole comment.

      Default is true.

      Parameters:
      trim - if String.trim() should be applied to comments
      Returns:
      this object, for chaining
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object