Class EntryValidator.EntryValidatorBuilder
java.lang.Object
org.skriptlang.skript.lang.entry.EntryValidator.EntryValidatorBuilder
- Enclosing class:
EntryValidator
A utility builder for creating an entry validator that can be used to parse
and validate a
SectionNode.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default separator used for allKeyValueEntryData. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a newKeyValueEntryDatato this validator that returns the raw, unhandled string value.Adds a newKeyValueEntryDatato this validator that returns the raw, unhandled string value.addEntryData(EntryData<?> entryData) A method to add customEntryDatato a validator.addSection(String key, boolean optional) Adds a new, potentially optionalSectionEntryDatato this validator.addSection(String key, boolean optional, boolean multiple) Adds a new, potentially optionalSectionEntryDatato this validator.build()entrySeparator(String separator) Updates the separator to be used when creating key/value entries.protected StringmissingRequiredEntryMessage(Function<String, String> message) A function to create an error message from an expected node's key when that node is missing during validation.unexpectedEntryMessage(Function<String, String> unexpectedEntryMessage) A function to create an error message from an unexpected node's key when an unexpected node is encountered during validation (i.e., the node is not allowed byunexpectedNodeTester).unexpectedNodeTester(Predicate<Node> unexpectedNodeTester) A predicate to be supplied for checking whether a node not explicitly handled by anygetEntryData()should cause an error (not be permitted).
-
Field Details
-
DEFAULT_ENTRY_SEPARATOR
The default separator used for allKeyValueEntryData.- See Also:
-
-
Constructor Details
-
EntryValidatorBuilder
protected EntryValidatorBuilder()
-
-
Method Details
-
getMissingRequiredEntryMessage
-
getUnexpectedEntryMessage
-
getUnexpectedNodeTester
-
getEntryData
-
getEntrySeparator
-
entrySeparator
Updates the separator to be used when creating key/value entries. Please note that this will not update the separator for already registered key/value entries.- Parameters:
separator- The new separator for key/value entries.- Returns:
- The builder instance.
-
unexpectedNodeTester
public EntryValidator.EntryValidatorBuilder unexpectedNodeTester(Predicate<Node> unexpectedNodeTester) A predicate to be supplied for checking whether a node not explicitly handled by anygetEntryData()should cause an error (not be permitted). The default behavior is that the predicate returns true for every node tested (i.e., no unknown nodes are permitted).- Parameters:
unexpectedNodeTester- The predicate to use.- Returns:
- The builder instance.
-
unexpectedEntryMessage
public EntryValidator.EntryValidatorBuilder unexpectedEntryMessage(Function<String, String> unexpectedEntryMessage) A function to create an error message from an unexpected node's key when an unexpected node is encountered during validation (i.e., the node is not allowed byunexpectedNodeTester).- Parameters:
unexpectedEntryMessage- The function to use.- Returns:
- The builder instance.
-
missingRequiredEntryMessage
public EntryValidator.EntryValidatorBuilder missingRequiredEntryMessage(Function<String, String> message) A function to create an error message from an expected node's key when that node is missing during validation.- Parameters:
message- The function to use.- Returns:
- The builder instance.
-
addEntry
public EntryValidator.EntryValidatorBuilder addEntry(String key, @Nullable @Nullable String defaultValue, boolean optional) Adds a newKeyValueEntryDatato this validator that returns the raw, unhandled string value. The added entry is optional and will use the provided default value as a backup. The entry data can be included only once within a single entry container.- Parameters:
key- The key of the entry.defaultValue- The default value of this entry to use if the user does not include this entry.optional- Whether the entry is optional- Returns:
- The builder instance.
-
addEntry
public EntryValidator.EntryValidatorBuilder addEntry(String key, @Nullable @Nullable String defaultValue, boolean optional, boolean multiple) Adds a newKeyValueEntryDatato this validator that returns the raw, unhandled string value. The added entry is optional and will use the provided default value as a backup.- Parameters:
key- The key of the entry.defaultValue- The default value of this entry to use if the user does not include this entry.optional- Whether the entry is optionalmultiple- Whether the entry can be included multiple times within a single section node- Returns:
- The builder instance.
-
addSection
Adds a new, potentially optionalSectionEntryDatato this validator. The entry data can be included only once within a single entry container.- Parameters:
key- The key of the section entry.optional- Whether the entry is optional- Returns:
- The builder instance.
-
addSection
public EntryValidator.EntryValidatorBuilder addSection(String key, boolean optional, boolean multiple) Adds a new, potentially optionalSectionEntryDatato this validator.- Parameters:
key- The key of the section entry.optional- Whether the entry is optionalmultiple- Whether the entry can be included multiple times within a single section node- Returns:
- The builder instance.
-
addEntryData
A method to add customEntryDatato a validator. Custom entry data should be preferred when the default methods included in this builder are not expansive enough. Please note that for customKeyValueEntryDataimplementations, the default entry separator value of this builder will not be used. Instead,DEFAULT_ENTRY_SEPARATORwill be used.- Parameters:
entryData- The custom entry data to include in this validator.- Returns:
- The builder instance.
-
build
- Returns:
- The final, built entry validator.
-