Class YamlHeaderFormatter
java.lang.Object
org.simpleyaml.configuration.comments.format.YamlHeaderFormatter
- All Implemented Interfaces:
CommentFormatter
The header is the first block comment at the top of the configuration file.
It ends with a blank line or with the end of the file.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionYamlHeaderFormatter(String commentPrefix, boolean strip) protectedYamlHeaderFormatter(YamlCommentFormatterConfiguration configuration) -
Method Summary
Modifier and TypeMethodDescriptionGets the comment prefix to apply to every line of the header.commentPrefix(String commentPrefix) Sets the comment prefix to apply to every line of the header.commentSuffix(String suffixMultiline) Set the comment suffix to append to every line of the header.dump(String header, CommentType type, KeyTree.Node node) Given the header (for instance the one returned byparse(java.lang.String, org.simpleyaml.configuration.comments.CommentType, org.simpleyaml.configuration.comments.KeyTree.Node)), returns the final string formatted to be dumped somewhere like a file.booleaninthashCode()parse(Reader raw, CommentType type, KeyTree.Node node) 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.parse(String raw, CommentType type, KeyTree.Node node) Parse the header of a contents string, like a file contents.prefixFirst(String commentPrefixFirst) Sets the comment prefix to apply to the beginning of the header.booleanIf strip is true thenString.trim()will be applied to every line of the header and thecommentPrefix()will be stripped away.stripPrefix(boolean stripPrefix) Set if stripping the prefix is desired.suffixLast(String suffixLast) Set the suffix to append to the end of the header.
-
Field Details
-
configuration
-
-
Constructor Details
-
YamlHeaderFormatter
-
YamlHeaderFormatter
-
YamlHeaderFormatter
public YamlHeaderFormatter()
-
-
Method Details
-
parse
Parse the header of a contents string, like a file contents. The header is the first block comment at the top of the configuration file. It ends with a blank line or with the end of the file. If no blank line is found after the first block comment and it is not the end of the file then null is returned (the comment will be attached to the first key, so that comment is not considered a header). The blank line suffix will be stripped away, i.e. the result string will not have a blank line at the end. IfstripPrefix()is true thenString.trim()will be applied to every line of the header and thecommentPrefix()will be stripped away.- Specified by:
parsein interfaceCommentFormatter- Parameters:
raw- the string to parsetype- the comment typenode- the comment node- Returns:
- the header
- Throws:
IOException
-
parse
Description copied from interface:CommentFormatterParse 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:
parsein interfaceCommentFormatter- Parameters:
raw- the comment to parse that may contain special format characters with leading and trailing spacetype- the comment typenode- the comment node- Returns:
- the comment in the expected format to be read by humans
- Throws:
IOException- if comment cannot be parsed
-
dump
Given the header (for instance the one returned byparse(java.lang.String, org.simpleyaml.configuration.comments.CommentType, org.simpleyaml.configuration.comments.KeyTree.Node)), returns the final string formatted to be dumped somewhere like a file. The header ends with a blank line and every line is prefixed with thecommentPrefix().If all header lines are already prefixed with a # then the
commentPrefix()is not applied.- Specified by:
dumpin interfaceCommentFormatter- Parameters:
header- the header to dumptype- the comment typenode- the comment node- Returns:
- the final string to be dumped
-
stripPrefix
public boolean stripPrefix()If strip is true thenString.trim()will be applied to every line of the header and thecommentPrefix()will be stripped away. Default is false.- Returns:
- if stripping the prefix is desired
-
stripPrefix
Set if stripping the prefix is desired. If strip is true thenString.trim()will be applied to every line of the header and thecommentPrefix()will be stripped away. Default is false.- Parameters:
stripPrefix- if stripping the prefix is desired- Returns:
- this object, for chaining
-
commentPrefix
Gets the comment prefix to apply to every line of the header. By default is "# ", i.e. a # followed by a space.- Returns:
- the comment prefix
-
commentPrefix
Sets the comment prefix to apply to every line of the header. By default is "# ", i.e. a # followed by a space.- Parameters:
commentPrefix- the comment prefix- Returns:
- this object, for chaining
-
prefixFirst
Sets the comment prefix to apply to the beginning of the header.- Parameters:
commentPrefixFirst- the comment prefix to apply to the beginning of the header- Returns:
- this object, for chaining
-
commentSuffix
Set the comment suffix to append to every line of the header.- Parameters:
suffixMultiline- the suffix to append to every line of the header- Returns:
- this object, for chaining
-
suffixLast
Set the suffix to append to the end of the header. If not included, a blank line \n\n will be added to the suffix. Default is a blank line.- Parameters:
suffixLast- the suffix to append to the end of the header- Returns:
- this object, for chaining
-
equals
-
hashCode
public int hashCode()
-