package tc.oc.pgm.features; import java.util.Arrays; import java.util.Collection; import java.util.stream.Stream; import javax.annotation.Nullable; import tc.oc.pgm.xml.Node; import tc.oc.pgm.xml.validate.Validation; import tc.oc.pgm.xml.validate.ValidationContext; public interface FeatureValidationContext extends ValidationContext { /** * Register a validation to run on the given feature or reference in the post-parse phase. * The feature must be registered with this context, but does not need to be defined yet * i.e. may be a reference. * * The given source node will be the location reported with the error if the validation fails. * It should be the source of the validation, rather than the source of the feature itself. */ T validate(T feature, @Nullable Node source, Stream> validations); default T validate(T feature, Validation... validations) { return validate(feature, null, validations); } default T validate(T feature, @Nullable Node source, Validation... validations) { return validate(feature, source, Arrays.asList(validations)); } default T validate(T feature, @Nullable Node source, Collection> validations) { return validate(feature, source, validations.stream()); } }