Class ConstrainedExecutable

  • All Implemented Interfaces:
    Iterable<MetaConstraint<?>>, ConstrainedElement

    public class ConstrainedExecutable
    extends AbstractConstrainedElement
    Represents a method or constructor of a Java type and all its associated meta-data relevant in the context of bean validation, for instance the constraints at its parameters or return value.
    Author:
    Gunnar Morling, Guillaume Smet
    • Constructor Detail

      • ConstrainedExecutable

        public ConstrainedExecutable​(ConfigurationSource source,
                                     Callable callable,
                                     Set<MetaConstraint<?>> returnValueConstraints,
                                     Set<MetaConstraint<?>> typeArgumentConstraints,
                                     CascadingMetaDataBuilder cascadingMetaDataBuilder)
        Creates a new executable meta data object for a parameter-less executable.
        Parameters:
        source - The source of meta data.
        callable - The represented executable.
        returnValueConstraints - Type arguments constraints, if any.
        typeArgumentConstraints - The type argument constraints on the return value of the represented executable, if any.
        cascadingMetaDataBuilder - The cascaded validation metadata for this element and its container elements.
      • ConstrainedExecutable

        public ConstrainedExecutable​(ConfigurationSource source,
                                     Callable callable,
                                     List<ConstrainedParameter> parameterMetaData,
                                     Set<MetaConstraint<?>> crossParameterConstraints,
                                     Set<MetaConstraint<?>> returnValueConstraints,
                                     Set<MetaConstraint<?>> typeArgumentConstraints,
                                     CascadingMetaDataBuilder cascadingMetaDataBuilder)
        Creates a new executable meta data object.
        Parameters:
        source - The source of meta data.
        callable - The represented executable.
        parameterMetaData - A list with parameter meta data. The length must correspond with the number of parameters of the represented executable. So this list may be empty (in case of a parameterless executable), but never null.
        crossParameterConstraints - the cross parameter constraints
        returnValueConstraints - The return value constraints of the represented executable, if any.
        typeArgumentConstraints - The type argument constraints on the return value of the represented executable, if any.
        cascadingMetaDataBuilder - The cascaded validation metadata for this element and its container elements.
    • Method Detail

      • getParameterMetaData

        public ConstrainedParameter getParameterMetaData​(int parameterIndex)
        Constraint meta data for the specified parameter.
        Parameters:
        parameterIndex - The index in this executable's parameter array of the parameter of interest.
        Returns:
        Meta data for the specified parameter. Will never be null.
        Throws:
        IllegalArgumentException - In case this executable doesn't have a parameter with the specified index.
      • getAllParameterMetaData

        public List<ConstrainedParameter> getAllParameterMetaData()
        Returns meta data for all parameters of the represented executable.
        Returns:
        A list with parameter meta data. The length corresponds to the number of parameters of the executable represented by this meta data object, so an empty list may be returned (in case of a parameterless executable), but never null.
      • getCrossParameterConstraints

        public Set<MetaConstraint<?>> getCrossParameterConstraints()
      • isConstrained

        public boolean isConstrained()
        Whether the represented executable is constrained or not. This is the case if it has at least one constrained parameter, at least one parameter marked for cascaded validation, at least one cross-parameter constraint, at least one return value constraint or if the return value is marked for cascaded validation.
        Specified by:
        isConstrained in interface ConstrainedElement
        Overrides:
        isConstrained in class AbstractConstrainedElement
        Returns:
        True if this executable is constrained by any means, false otherwise.
      • hasParameterConstraints

        public boolean hasParameterConstraints()
        Whether this executable has at least one cascaded parameter or at least one parameter with constraints or at least one cross-parameter constraint.
        Returns:
        True, if this executable is parameter-constrained by any means, false otherwise.
      • getCallable

        public Callable getCallable()
      • isEquallyParameterConstrained

        public boolean isEquallyParameterConstrained​(ConstrainedExecutable other)
        Whether this and the given other executable have the same parameter constraints.
        Parameters:
        other - The other executable to check.
        Returns:
        True if this and the other executable have the same parameter constraints (including cross- parameter constraints and parameter cascades), false otherwise.
      • merge

        public ConstrainedExecutable merge​(ConstrainedExecutable other)
        Creates a new constrained executable object by merging this and the given other executable. Both executables must have the same location, i.e. represent the same executable on the same type.
        Parameters:
        other - The executable to merge.
        Returns:
        A merged executable.