Last active
November 16, 2018 18:56
-
-
Save BumpeiShimada/345e3c8e2119fcd5f5d4e1c36a7d6450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@AllArgsConstructor(onConstructor = @__(@Autowired)) | |
public class ValidatorFactory { | |
// All concrete classes of an interface can be asserted like this in Spring. | |
// If you want to know more, see: https://dzone.com/articles/load-all-implementors | |
private List<BaseValidator> validators; | |
/** | |
* Filter out all unnecessary validation classes by checking event types | |
* and returns only needed ones. | |
* | |
* @param isExclusive: the boolean value indicate whether the event is the exclusive one or not | |
* @return All necessary validation methods | |
*/ | |
List<BaseValidator> get(boolean isExclusive) { | |
EnumSet<ValidateType> eventTypes = ValidateType.getEventTypes(isExclusive); | |
return validators.stream().filter(v -> eventTypes.contains(v.getValidateType())).collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment