1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint;
7   
8   import java.util.List;
9   import java.util.Map;
10  
11  import dev.metaschema.core.model.ISource;
12  import dev.metaschema.core.qname.IEnhancedQName;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * Represents a container of rules constraining the effective model of a
17   * Metaschema field or flag data instance.
18   */
19  public interface IValueConstrained {
20    /**
21     * Get information about the resource the constraints were loaded from.
22     *
23     * @return the source information
24     */
25    @NonNull
26    ISource getSource();
27  
28    /**
29     * Retrieve the ordered collection of constraints.
30     *
31     * @return the constraints or an empty list
32     */
33    @NonNull
34    List<? extends IConstraint> getConstraints();
35  
36    /**
37     * Get the collection of let expressions, if any.
38     *
39     * @return the constraints or an empty list
40     */
41    @NonNull
42    Map<IEnhancedQName, ILet> getLetExpressions();
43  
44    /**
45     * Get the collection of allowed value constraints, if any.
46     *
47     * @return the constraints or an empty list
48     */
49    @NonNull
50    List<? extends IAllowedValuesConstraint> getAllowedValuesConstraints();
51  
52    /**
53     * Get the collection of matches constraints, if any.
54     *
55     * @return the constraints or an empty list
56     */
57    @NonNull
58    List<? extends IMatchesConstraint> getMatchesConstraints();
59  
60    /**
61     * Get the collection of index key reference constraints, if any.
62     *
63     * @return the constraints or an empty list
64     */
65    @NonNull
66    List<? extends IIndexHasKeyConstraint> getIndexHasKeyConstraints();
67  
68    /**
69     * Get the collection of expect constraints, if any.
70     *
71     * @return the constraints or an empty list
72     */
73    @NonNull
74    List<? extends IExpectConstraint> getExpectConstraints();
75  
76    /**
77     * Get the collection of report constraints, if any.
78     *
79     * @return the constraints or an empty list
80     */
81    @NonNull
82    List<? extends IReportConstraint> getReportConstraints();
83  
84    /**
85     * Add a new let expression.
86     *
87     * @param let
88     *          the let statement to add
89     * @return the original let with the same name or {@code null} if no let existed
90     *         with the same name
91     */
92    ILet addLetExpression(@NonNull ILet let);
93  
94    /**
95     * Add a new constraint.
96     *
97     * @param constraint
98     *          the constraint to add
99     */
100   void addConstraint(@NonNull IAllowedValuesConstraint constraint);
101 
102   /**
103    * Add a new constraint.
104    *
105    * @param constraint
106    *          the constraint to add
107    */
108   void addConstraint(@NonNull IMatchesConstraint constraint);
109 
110   /**
111    * Add a new constraint.
112    *
113    * @param constraint
114    *          the constraint to add
115    */
116   void addConstraint(@NonNull IIndexHasKeyConstraint constraint);
117 
118   /**
119    * Add a new constraint.
120    *
121    * @param constraint
122    *          the constraint to add
123    */
124   void addConstraint(@NonNull IExpectConstraint constraint);
125 
126   /**
127    * Add a new constraint.
128    *
129    * @param constraint
130    *          the constraint to add
131    */
132   void addConstraint(@NonNull IReportConstraint constraint);
133 }