1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint.impl;
7   
8   import java.util.Map;
9   import java.util.Set;
10  
11  import dev.metaschema.core.datatype.markup.MarkupLine;
12  import dev.metaschema.core.datatype.markup.MarkupMultiline;
13  import dev.metaschema.core.metapath.IMetapathExpression;
14  import dev.metaschema.core.metapath.item.atomic.IBooleanItem;
15  import dev.metaschema.core.model.IAttributable;
16  import dev.metaschema.core.model.ISource;
17  import dev.metaschema.core.model.constraint.IExpectConstraint;
18  import edu.umd.cs.findbugs.annotations.NonNull;
19  import edu.umd.cs.findbugs.annotations.Nullable;
20  
21  /**
22   * Represents an expect constraint.
23   * <p>
24   * Requires that the associated test evaluates to {@link IBooleanItem#TRUE}
25   * against the target.
26   */
27  public final class DefaultExpectConstraint
28      extends AbstractConfigurableMessageConstraint
29      implements IExpectConstraint {
30    @NonNull
31    private final IMetapathExpression test;
32  
33    /**
34     * Construct a new expect constraint.
35     *
36     * @param id
37     *          the optional identifier for the constraint
38     * @param formalName
39     *          the constraint's formal name or {@code null} if not provided
40     * @param description
41     *          the constraint's semantic description or {@code null} if not
42     *          provided
43     * @param source
44     *          information about the constraint source
45     * @param level
46     *          the significance of a violation of this constraint
47     * @param target
48     *          the Metapath expression identifying the nodes the constraint targets
49     * @param properties
50     *          a collection of associated properties
51     * @param test
52     *          a Metapath expression that is evaluated against the target node to
53     *          determine if the constraint passes
54     * @param message
55     *          an optional message to emit when the constraint is violated
56     * @param remarks
57     *          optional remarks describing the intent of the constraint
58     */
59    @SuppressWarnings("PMD.ExcessiveParameterList")
60    public DefaultExpectConstraint(
61        @Nullable String id,
62        @Nullable String formalName,
63        @Nullable MarkupLine description,
64        @NonNull ISource source,
65        @NonNull Level level,
66        @NonNull IMetapathExpression target,
67        @NonNull Map<IAttributable.Key, Set<String>> properties,
68        @NonNull IMetapathExpression test,
69        @Nullable String message,
70        @Nullable MarkupMultiline remarks) {
71      super(id, formalName, description, source, level, target, properties, message, remarks);
72      this.test = test;
73    }
74  
75    @Override
76    public IMetapathExpression getTest() {
77      return test;
78    }
79  }