public class SettingsHolderClassValidator extends Object
This class' 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 ConfigurationData |
createConfigurationData(Iterable<Class<? extends SettingsHolder>> classes) |
protected Predicate<String> |
createValidLengthPredicate(Integer minLength,
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 List<String> |
gatherExpectedEnumNames(Class<? extends Enum<?>> enumClass) |
protected Stream<Field> |
getAllFields(Class<?> clazz)
Returns all fields of the class, including all fields of parent classes, recursively.
|
protected Class<? extends Enum<?>> |
getEnumTypeOfProperty(Property<?> property)
Returns the type of the given property if it is an enum, otherwise null.
|
protected boolean |
hasNonEmptyComment(List<String> comments) |
protected boolean |
hasValidConstructorSetup(Class<? extends SettingsHolder> clazz) |
protected boolean |
isValidConstantField(Field field) |
void |
validate(Class<? extends SettingsHolder>... settingHolders)
Runs all validations of this class with the given settings holder classes.
|
void |
validate(Iterable<Class<? extends SettingsHolder>> settingHolders)
Runs all validations of this class with the given settings holder classes.
|
void |
validateAllPropertiesAreConstants(Iterable<Class<? extends SettingsHolder>> settingHolders)
Throws an exception if any Property field of the given classes is not public, static, or final.
|
void |
validateClassesHaveHiddenNoArgConstructor(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(ConfigurationData configurationData,
Integer minLength,
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(ConfigurationData configurationData,
PropertyResource resource,
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(ConfigurationData configurationData,
Predicate<Property<?>> propertyFilter)
Throws an exception if the comments of an enum property do not list all entries of the enum type.
|
void |
validateHasCommentOnEveryProperty(ConfigurationData configurationData,
Predicate<Property<?>> propertyFilter)
Throws an exception if there isn't a non-empty comment for every property in the configuration data.
|
void |
validateSettingsHolderClassesFinal(Iterable<Class<? extends SettingsHolder>> settingHolders)
Throws an exception if any of the provided settings holder classes is not final.
|
@SafeVarargs public final void validate(Class<? extends SettingsHolder>... settingHolders)
validate(Iterable).settingHolders - settings holder classes that make up the configuration data of the projectpublic void validate(Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - settings holder classes that make up the configuration data of the projectpublic void validateConfigurationDataValidForMigrationService(ConfigurationData configurationData, PropertyResource resource, 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(Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateSettingsHolderClassesFinal(Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateClassesHaveHiddenNoArgConstructor(Iterable<Class<? extends SettingsHolder>> settingHolders)
settingHolders - the classes to checkpublic void validateHasCommentOnEveryProperty(ConfigurationData configurationData, @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(ConfigurationData configurationData, @Nullable Integer minLength, @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(ConfigurationData configurationData, @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(Field field)
protected ConfigurationData createConfigurationData(Iterable<Class<? extends SettingsHolder>> classes)
protected Predicate<String> createValidLengthPredicate(@Nullable Integer minLength, @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 Class<? extends Enum<?>> getEnumTypeOfProperty(Property<?> property)
property - the property to processprotected List<String> gatherExpectedEnumNames(Class<? extends Enum<?>> enumClass)
protected boolean hasValidConstructorSetup(Class<? extends SettingsHolder> clazz)
Copyright © 2016–2021 The AuthMe Team. All rights reserved.