1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.testsupport.builder;
7   
8   import java.util.function.Consumer;
9   
10  import dev.metaschema.core.model.constraint.AbstractConstraintBuilder;
11  import dev.metaschema.core.model.constraint.IConstraint;
12  import edu.umd.cs.findbugs.annotations.NonNull;
13  
14  /**
15   * A builder for creating constraint contexts within a constraint set.
16   * <p>
17   * A context defines a metapath expression that targets specific elements, and
18   * the constraints that apply to those targets.
19   */
20  public interface IContextBuilder {
21  
22    /**
23     * Set the metapath expression that defines what this context targets.
24     *
25     * @param target
26     *          the metapath expression
27     * @return this builder
28     */
29    @NonNull
30    IContextBuilder metapath(@NonNull String target);
31  
32    /**
33     * Add a constraint to this context using a constraint builder.
34     * <p>
35     * The builder's {@code build()} method will be called to create the constraint.
36     *
37     * @param constraintBuilder
38     *          the constraint builder
39     * @return this builder
40     */
41    @NonNull
42    IContextBuilder constraint(
43        @NonNull AbstractConstraintBuilder<?, ? extends IConstraint> constraintBuilder);
44  
45    /**
46     * Add a child context nested within this context.
47     *
48     * @param childConfigurer
49     *          a consumer that configures the child context
50     * @return this builder
51     */
52    @NonNull
53    IContextBuilder childContext(@NonNull Consumer<IContextBuilder> childConfigurer);
54  }