Class AbstractConstraintBuilder<T extends AbstractConstraintBuilder<T,R>,R extends IConstraint>

java.lang.Object
dev.metaschema.core.model.constraint.AbstractConstraintBuilder<T,R>
Type Parameters:
T - the Java type of the implementing builder
R - the Java type of the resulting built object
Direct Known Subclasses:
AbstractConfigurableMessageConstraintBuilder, IAllowedValuesConstraint.Builder

public abstract class AbstractConstraintBuilder<T extends AbstractConstraintBuilder<T,R>,R extends IConstraint> extends Object
Provides builder methods for the core data elements of an IConstraint.

The base class of all constraint builders.

  • Constructor Details

    • AbstractConstraintBuilder

      public AbstractConstraintBuilder()
  • Method Details

    • getThis

      @NonNull protected abstract T getThis()
      Get the builder.

      Implementations of this method must return this.

      Returns:
      the builder instance
    • identifier

      @NonNull public T identifier(@NonNull String id)
      Set an identifier for the constraint.
      Parameters:
      id - the identifier to set
      Returns:
      this builder
    • formalName

      @NonNull public T formalName(@NonNull String name)
      Set a formal name for the constraint.
      Parameters:
      name - the formal name to set
      Returns:
      this builder
    • description

      @NonNull public T description(@NonNull MarkupLine description)
      Set a description for the constraint.
      Parameters:
      description - the description to set
      Returns:
      this builder
    • source

      @NonNull public T source(@NonNull ISource source)
      Set the source the constraint was parsed from.
      Parameters:
      source - the source to set
      Returns:
      this builder
    • level

      @NonNull public T level(@NonNull IConstraint.Level level)
      Set the severity level for when the constraint is violated.
      Parameters:
      level - the level to set
      Returns:
      this builder
    • target

      @NonNull public T target(@NonNull IMetapathExpression target)
      Set the Metapath expression used to get the target(s) of the constraint.
      Parameters:
      target - a Metapath expression, which will be evaluated relative to the definition it is declared on
      Returns:
      this builder
    • properties

      @NonNull public T properties(@NonNull Map<IAttributable.Key,Set<String>> properties)
      Set the collection of properties associated with the constraint.
      Parameters:
      properties - the properties to set
      Returns:
      this builder
    • property

      @NonNull public T property(@NonNull IAttributable.Key key, @NonNull String value)
      Set the values of the property with the provided name to the provided value.
      Parameters:
      key - the property's name
      value - the value to set
      Returns:
      this builder
    • property

      @NonNull public T property(@NonNull IAttributable.Key key, @NonNull Set<String> values)
      Set the values of the property with the provided name to the provided values.
      Parameters:
      key - the property's name
      values - the values to set
      Returns:
      this builder
    • remarks

      @NonNull public T remarks(@NonNull MarkupMultiline remarks)
      Set the provided remarks.
      Parameters:
      remarks - the remarks to set
      Returns:
      this builder
    • validate

      protected void validate()
      Validate the values provided to the builder.
      Throws:
      NullPointerException - if a required value is null
      ConstraintInitializationException - in other cases where the combination of values is inappropriate
    • newInstance

      @NonNull protected abstract R newInstance()
      Get a new instance of the built object.
      Returns:
      the built instance
    • build

      @NonNull public R build()
      Generate the built instance after validating the provided data.
      Returns:
      the built instance
      Throws:
      ConstraintInitializationException - if the underlying data is incomplete or invalid
    • getId

      @Nullable protected String getId()
      Get the constraint identifier provided to the builder.
      Returns:
      the identifier or null if no identifier has been set
    • getFormalName

      @Nullable protected String getFormalName()
      Get the constraint formal name provided to the builder.
      Returns:
      the formal name or null if no formal name has been set
    • getDescription

      @Nullable protected MarkupLine getDescription()
      Get the constraint description provided to the builder.
      Returns:
      the description or null if no description has been set
    • getSource

      @Nullable protected ISource getSource()
      Get the constraint source provided to the builder.
      Returns:
      the source or null if no source has been set
    • getLevel

      @NonNull protected IConstraint.Level getLevel()
      Get the constraint severity level provided to the builder.
      Returns:
      the severity level
    • getTarget

      @NonNull protected IMetapathExpression getTarget()
      Get the Metapath expression, provided to the builder, used to get the target(s) of the constraint.
      Returns:
      the target Metapath expression
    • getProperties

      @NonNull protected Map<IAttributable.Key,Set<String>> getProperties()
      Get the constraint properties provided to the builder.
      Returns:
      the properties or an empty Map if no properties are set
    • getRemarks

      @Nullable protected MarkupMultiline getRemarks()
      Get the remarks provided to the builder.
      Returns:
      the remarks