public class SettingsHolderClassValidator extends Object
This class's methods can be overridden for custom behavior. Depending on your needs, you can call the main
validate method and override single validation methods you want to customize or disable, or call the
individual validation methods separately.
| Constructor and Description |
|---|
SettingsHolderClassValidator() |
| Modifier and Type | Method and Description |
|---|---|
protected @NotNull ConfigurationData |
createConfigurationData(@NotNull Iterable<Class<? extends SettingsHolder>> classes) |
protected @NotNull Predicate<String> |
createValidLengthPredicate(@Nullable Integer minLength,
@Nullable Integer maxLength)
Creates a predicate based on input min length and max length that evaluates successfully for a string if
its length is within the given bounds:
minLength <= length <= maxLength. |
protected @NotNull List<String> |
gatherExpectedEnumNames(@NotNull Class<? extends Enum<?>> enumClass) |
protected @NotNull Stream<Field> |
getAllFields(@NotNull Class<?> clazz)
Returns all fields of the class, including all fields of parent classes, recursively.
|
protected @Nullable Class<? extends Enum<?>> |
getEnumTypeOfProperty(@NotNull Property<?> property)
Returns the type of the given property if it is an enum, otherwise null.
|
protected boolean |
hasNonEmptyComment(@Nullable List<String> comments) |
protected boolean |
hasValidConstructorSetup(@NotNull Class<? extends SettingsHolder> clazz) |
protected boolean |
isValidConstantField(@NotNull Field field) |
void |
validate(Class<? extends SettingsHolder>... settingHolders)
Runs all validations of this class with the given settings holder classes.
|
void |
validate(@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
Runs all validations of this class with the given settings holder classes.
|
void |
validateAllPropertiesAreConstants(@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
Throws an exception if any Property field of the given classes is not public, static, or final.
|
void |
validateClassesHaveHiddenNoArgConstructor(@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
Throws an exception if any of the provided setting holder classes does not have a single private
no-args constructor.
|
void |
validateCommentLengthsAreWithinBounds(@NotNull ConfigurationData configurationData,
@Nullable Integer minLength,
@Nullable Integer maxLength)
Throws an exception if any comment line in the configuration data has a length is not between the given
minLength and maxLength, inclusive:
minLength <= length <= maxLength. |
void |
validateConfigurationDataValidForMigrationService(@NotNull ConfigurationData configurationData,
@NotNull PropertyResource resource,
@NotNull MigrationService migrationService)
Validates that the migration service does not declare that a migration is required for the given
configuration data, which gets saved to the provided resource beforehand.
|
void |
validateHasAllEnumEntriesInComment(@NotNull ConfigurationData configurationData,
@Nullable Predicate<Property<?>> propertyFilter)
Throws an exception if the comments of an enum property do not list all entries of the enum type.
|
void |
validateHasCommentOnEveryProperty(@NotNull ConfigurationData configurationData,
@Nullable Predicate<Property<?>> propertyFilter)
Throws an exception if there isn't a non-empty comment for every property in the configuration data.
|
void |
validateSettingsHolderClassesFinal(@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
Throws an exception if any of the provided settings holder classes is not final.
|
@SafeVarargs public final void validate(@NotNull Class<? extends SettingsHolder>... settingHolders)
validate(Iterable).settingHolders - settings holder classes that make up the configuration data of the projectpublic void validate(@NotNull
@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - settings holder classes that make up the configuration data of the projectpublic void validateConfigurationDataValidForMigrationService(@NotNull
@NotNull ConfigurationData configurationData,
@NotNull
@NotNull PropertyResource resource,
@NotNull
@NotNull MigrationService migrationService)
configurationData - the configuration data (with default values, i.e. as created from the properties)resource - property resource to save to and read from (temporary medium for testing)migrationService - the migration service to checkpublic void validateAllPropertiesAreConstants(@NotNull
@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateSettingsHolderClassesFinal(@NotNull
@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateClassesHaveHiddenNoArgConstructor(@NotNull
@NotNull Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateHasCommentOnEveryProperty(@NotNull
@NotNull ConfigurationData configurationData,
@Nullable
@Nullable Predicate<Property<?>> propertyFilter)
configurationData - the configuration data to checkpropertyFilter - predicate determining which properties are checked (if null, are properties are checked)public void validateCommentLengthsAreWithinBounds(@NotNull
@NotNull ConfigurationData configurationData,
@Nullable
@Nullable Integer minLength,
@Nullable
@Nullable Integer maxLength)
minLength <= length <= maxLength. Either argument is nullable
if no min or max, respectively, is desired, but both arguments may not be null.configurationData - the configuration data with the comments to checkminLength - the number of characters each comment line must at least have (null to disable check)maxLength - the number of characters each comment may not surpass (null to disable check)public void validateHasAllEnumEntriesInComment(@NotNull
@NotNull ConfigurationData configurationData,
@Nullable
@Nullable Predicate<Property<?>> propertyFilter)
configurationData - the configuration data whose properties and comments should be checkedpropertyFilter - predicate determining which properties are checked (if null, are properties are checked)protected boolean isValidConstantField(@NotNull
@NotNull Field field)
@NotNull protected @NotNull ConfigurationData createConfigurationData(@NotNull @NotNull Iterable<Class<? extends SettingsHolder>> classes)
@NotNull protected @NotNull Predicate<String> createValidLengthPredicate(@Nullable @Nullable Integer minLength, @Nullable @Nullable Integer maxLength)
minLength <= length <= maxLength. Either length may be null,
but an exception is thrown if both are null.minLength - the min length (nullable)maxLength - the max length (nullable)@Nullable protected @Nullable Class<? extends Enum<?>> getEnumTypeOfProperty(@NotNull @NotNull Property<?> property)
property - the property to process@NotNull protected @NotNull List<String> gatherExpectedEnumNames(@NotNull @NotNull Class<? extends Enum<?>> enumClass)
protected boolean hasValidConstructorSetup(@NotNull
@NotNull Class<? extends SettingsHolder> clazz)
@NotNull protected @NotNull Stream<Field> getAllFields(@NotNull @NotNull Class<?> clazz)
clazz - the class whose fields should be retrievedCopyright © 2016–2023 The AuthMe Team. All rights reserved.