Class ExistsConstraint

java.lang.Object
io.fluxcapacitor.common.api.search.constraints.PathConstraint
io.fluxcapacitor.common.api.search.constraints.ExistsConstraint
All Implemented Interfaces:
Constraint

public class ExistsConstraint extends PathConstraint
A Constraint that checks whether one or more paths exist in a document.

This constraint matches any document that contains a non-null value at the specified path(s).

If multiple paths are provided, the constraint will match if any of them are present (i.e. this behaves as an AnyConstraint).

Optionally, sub-paths can be included using a glob-style match with /**.

Examples


 // Matches documents where "person/firstName" exists (is non-null)
 Constraint c1 = ExistsConstraint.exists("person/firstName");

 // Matches if any of the specified paths or their children exist
 Constraint c2 = ExistsConstraint.exists(true, "address", "email");
 
  • Constructor Details

    • ExistsConstraint

      public ExistsConstraint()
  • Method Details

    • exists

      public static Constraint exists(String... paths)
      Creates a constraint that checks for the presence of any of the given paths. Sub-paths will be included.
      Parameters:
      paths - the paths to check for existence
      Returns:
      a constraint that matches if any of the given paths (or their sub-paths) exist
    • matches

      protected boolean matches(Document.Entry entry)
      Description copied from class: PathConstraint
      Evaluates whether the specified document entry satisfies the condition defined by this method's implementation.
      Specified by:
      matches in class PathConstraint
      Parameters:
      entry - the document entry to evaluate
      Returns:
      true if the entry satisfies the condition; false otherwise
    • withPaths

      public Constraint withPaths(List<String> paths)
      Specified by:
      withPaths in class PathConstraint