Skip to content

Instantly share code, notes, and snippets.

@BumpeiShimada
Last active November 16, 2018 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BumpeiShimada/345e3c8e2119fcd5f5d4e1c36a7d6450 to your computer and use it in GitHub Desktop.
Save BumpeiShimada/345e3c8e2119fcd5f5d4e1c36a7d6450 to your computer and use it in GitHub Desktop.
@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