Package org.eclipse.viatra.addon.validation.core.api

## Interface IConstraint

- All Known Implementing Classes:
    `Constraint`

      public interface IConstraint

  Interface for a constraint.

  We differentiate between Constraint Specification that represents the validation rule and Constraint that represents the instantiation of a constraint specification on a validation engine.

  Each constraint stores:

  - its specification
  - validation engine

  It provides capabilities for:

  - listing the set of violations
  - registering listeners for notifications on the changes in the violation set and other
  events related to the life cycle of the constraint.

  For constraints specified by VIATRA Query patterns, the matcher is stored.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `addListener​(ConstraintListener listener)` | Adds the given listener to the list of listeners to be notified on specific events regarding the constraint.
    `boolean` | `addListener​(ConstraintListener listener, IViolationFilter filter)` | Adds the given listener to the list of listeners to be notified on specific events regarding the constraint.
    `java.util.Collection<ConstraintListener>` | `getListeners()` | Returns the listeners registered for the constraint.
    `IConstraintSpecification` | `getSpecification()` | Returns the constraint specification from which the constraint was instantiated on the validation engine.
    `java.util.Collection<IViolation>` | `getStoredViolations()` | Returns the violations stored by the constraint.
    `java.util.Collection<IViolation>` | `listViolations()` | Returns the violations retrieved from the validation engine on demand.
    `java.util.Collection<IViolation>` | `listViolations​(IViolationFilter filter)` | Returns the violations retrieved from the validation engine on demand and filtered by the provided violation filter.
    `boolean` | `removeListener​(ConstraintListener listener)` | Removes the given listener from the list of listeners to be notified on specific events regarding the constraint.

- - ### Method Detail

    - #### listViolations

          java.util.Collection<IViolation> listViolations()

      Returns the violations retrieved from the validation engine on demand.
      Returns:
        The Collection of violations.

    - #### listViolations

          java.util.Collection<IViolation> listViolations​(IViolationFilter filter)

      Returns the violations retrieved from the validation engine on demand and filtered by the provided violation filter.
      Parameters:
        `filter` - The violation filter instance to be used to filter the retrieved violations.
      Returns:
        The Collection of violations after applying the filter.

    - #### getStoredViolations

          java.util.Collection<IViolation> getStoredViolations()

      Returns the violations stored by the constraint.

      Violations are stored if they have at least one listener registered.

      Returns:
        The Collection of stored Violations.

    - #### getSpecification

          IConstraintSpecification getSpecification()

      Returns the constraint specification from which the constraint was instantiated on the validation engine.
      Returns:
        The constraint specification.

    - #### getListeners

          java.util.Collection<ConstraintListener> getListeners()

      Returns the listeners registered for the constraint.
      Returns:
        The Collection of listeners registered for the constraint.

    - #### addListener

          boolean addListener​(ConstraintListener listener)

      Adds the given listener to the list of listeners to be notified on specific events regarding the constraint.
      Parameters:
        `listener` - The listener to be registered.

    - #### addListener

          boolean addListener​(ConstraintListener listener,
                              IViolationFilter filter)

      Adds the given listener to the list of listeners to be notified on specific events regarding the constraint.
      Parameters:
        `listener` - The listener to be registered.
        `filter` -
      Returns:
        `true` if the listener was not registered before.

    - #### removeListener

          boolean removeListener​(ConstraintListener listener)

      Removes the given listener from the list of listeners to be notified on specific events regarding the constraint.
      Parameters:
        `listener` - The listener to be deregistered.
      Returns:
        `true` if the listener was in fact registered.