Class YamlHeaderFormatter
java.lang.Object
org.simpleyaml.configuration.comments.format.YamlHeaderFormatter
- All Implemented Interfaces:
org.simpleyaml.configuration.comments.format.CommentFormatter
public class YamlHeaderFormatter
extends Object
implements org.simpleyaml.configuration.comments.format.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, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.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, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.KeyTree.Node node) parse(String raw, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.simpleyaml.configuration.comments.format.CommentFormatter
dump, dump, parse, parse, parse, parse
-
Field Details
-
configuration
-
-
Constructor Details
-
YamlHeaderFormatter
-
YamlHeaderFormatter
-
YamlHeaderFormatter
public YamlHeaderFormatter()
-
-
Method Details
-
parse
public String parse(String raw, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.KeyTree.Node node) throws IOException 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 interfaceorg.simpleyaml.configuration.comments.format.CommentFormatter- Parameters:
raw- the string to parse- Returns:
- the header
- Throws:
IOException
-
parse
public String parse(Reader raw, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.KeyTree.Node node) throws IOException - Specified by:
parsein interfaceorg.simpleyaml.configuration.comments.format.CommentFormatter- Throws:
IOException
-
dump
public String dump(String header, org.simpleyaml.configuration.comments.CommentType type, org.simpleyaml.configuration.comments.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. 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 interfaceorg.simpleyaml.configuration.comments.format.CommentFormatter- Parameters:
header- the header to dump- 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()
-