Class QueryStatement

java.lang.Object
org.projog.api.QueryStatement

public final class QueryStatement extends Object
Represents a query.

single use, not multi-threaded

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Evaluate once the query represented by this statement.
    Returns a new QueryResult for the query represented by this object.
    Find all solutions generated by the query and return String representations of the atoms the single query variable was unified with.
    Find all solutions generated by the query and return the double values the single query variable was unified with.
    Find all solutions generated by the query and return the long values the single query variable was unified with.
    Find all solutions generated by the query and return the Term values the single query variable was unified with.
    Execute the query once and return a String representation of the atom the single query variable was unified with.
    double
    Execute the query once and return a double representation of the term the single query variable was unified with.
    long
    Execute the query once and return a long representation of the term the single query variable was unified with.
    Attempt to execute the query once and return a String representation of the atom the single query variable was unified with.
    Attempt to execute the query once and return a Double representation of the term the single query variable was unified with.
    Attempt to execute the query once and return a Long representation of the term the single query variable was unified with.
    Attempt to execute the query once and return a Term representation of the term the single query variable was unified with.
    Execute the query once and return the Term the single query variable was unified with.
    void
    setAtomName(String variableId, String atomName)
    Attempts to unify the specified String value as an Atom to the variable with the specified id.
    void
    setDouble(String variableId, double value)
    Attempts to unify the specified double as a DecimalFraction to the variable with the specified id.
    void
    setListOfAtomNames(String variableId, String... atomNames)
    Attempts to unify the specified String values as a Prolog list of atoms to the variable with the specified id.
    void
    setListOfAtomNames(String variableId, List<String> atomNames)
    Attempts to unify the specified String values as a Prolog list of atoms to the variable with the specified id.
    void
    setListOfDoubles(String variableId, double... doubles)
    Attempts to unify the specified double values as a Prolog list to the variable with the specified id.
    void
    setListOfDoubles(String variableId, List<Double> doubles)
    Attempts to unify the specified Double values as a Prolog list to the variable with the specified id.
    void
    setListOfLongs(String variableId, long... longs)
    Attempts to unify the specified long values as a Prolog list to the variable with the specified id.
    void
    setListOfLongs(String variableId, List<Long> longs)
    Attempts to unify the specified Long values as a Prolog list to the variable with the specified id.
    void
    setListOfTerms(String variableId, List<? extends Term> terms)
    Attempts to unify the specified Term values as a Prolog list to the variable with the specified id.
    void
    setListOfTerms(String variableId, Term... terms)
    Attempts to unify the specified Term values as a Prolog list to the variable with the specified id.
    void
    setLong(String variableId, long value)
    Attempts to unify the specified long as a IntegerNumber to the variable with the specified id.
    void
    setTerm(String variableId, Term term)
    Attempts to unify the specified term to the variable with the specified id.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setTerm

      public void setTerm(String variableId, Term term)
      Attempts to unify the specified term to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      term - the term to unify to the variable
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setAtomName

      public void setAtomName(String variableId, String atomName)
      Attempts to unify the specified String value as an Atom to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      atomName - the value to use as the name of the Atom that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setDouble

      public void setDouble(String variableId, double value)
      Attempts to unify the specified double as a DecimalFraction to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      value - the value to use as the name of the DecimalFraction that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setLong

      public void setLong(String variableId, long value)
      Attempts to unify the specified long as a IntegerNumber to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      value - the value to use as the name of the IntegerNumber that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfAtomNames

      public void setListOfAtomNames(String variableId, String... atomNames)
      Attempts to unify the specified String values as a Prolog list of atoms to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      atomNames - the values to use as atom elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfAtomNames

      public void setListOfAtomNames(String variableId, List<String> atomNames)
      Attempts to unify the specified String values as a Prolog list of atoms to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      atomNames - the values to use as atom elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfDoubles

      public void setListOfDoubles(String variableId, double... doubles)
      Attempts to unify the specified double values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      doubles - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfDoubles

      public void setListOfDoubles(String variableId, List<Double> doubles)
      Attempts to unify the specified Double values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      doubles - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfLongs

      public void setListOfLongs(String variableId, long... longs)
      Attempts to unify the specified long values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      longs - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfLongs

      public void setListOfLongs(String variableId, List<Long> longs)
      Attempts to unify the specified Long values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      longs - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfTerms

      public void setListOfTerms(String variableId, Term... terms)
      Attempts to unify the specified Term values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      terms - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • setListOfTerms

      public void setListOfTerms(String variableId, List<? extends Term> terms)
      Attempts to unify the specified Term values as a Prolog list to the variable with the specified id.
      Parameters:
      variableId - the id of the variable
      terms - the values to use as elements in the list that the variable will be unified with
      Throws:
      ProjogException - if no variable with the specified id exists in the query this object represents, or the given term cannot be unified with the variable
      See Also:
    • executeQuery

      public QueryResult executeQuery()
      Returns a new QueryResult for the query represented by this object.

      Note that the query is not evaluated as part of a call to executeQuery(). It is on the first call of QueryResult.next() that the first attempt to evaluate the query will be made.

      Returns:
      a new QueryResult for the query represented by this object.
    • executeOnce

      public void executeOnce()
      Evaluate once the query represented by this statement.

      The query will only be evaluated once, even if further solutions could of been found on backtracking.

      Throws:
      ProjogException - if no solution can be found
      See Also:
    • findFirstAsAtomName

      public String findFirstAsAtomName()
      Execute the query once and return a String representation of the atom the single query variable was unified with.
      Returns:
      the name of the atom the query variable has been unified with as a result of executing the query
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsDouble

      public double findFirstAsDouble()
      Execute the query once and return a double representation of the term the single query variable was unified with.
      Returns:
      the value the query variable has been unified with as a result of executing the query
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsLong

      public long findFirstAsLong()
      Execute the query once and return a long representation of the term the single query variable was unified with.
      Returns:
      the value query variable has been unified with as a result of executing the query
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsTerm

      public Term findFirstAsTerm()
      Execute the query once and return the Term the single query variable was unified with.
      Returns:
      the value query variable has been unified with as a result of executing the query
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsOptionalAtomName

      public Optional<String> findFirstAsOptionalAtomName()
      Attempt to execute the query once and return a String representation of the atom the single query variable was unified with.
      Returns:
      the name of the atom the query variable has been unified with, or an empty optional if the query was not successfully evaluated
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsOptionalDouble

      public Optional<Double> findFirstAsOptionalDouble()
      Attempt to execute the query once and return a Double representation of the term the single query variable was unified with.
      Returns:
      the value the query variable has been unified with, or an empty optional if the query was not successfully evaluated
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsOptionalLong

      public Optional<Long> findFirstAsOptionalLong()
      Attempt to execute the query once and return a Long representation of the term the single query variable was unified with.
      Returns:
      the value the query variable has been unified with, or an empty optional if the query was not successfully evaluated
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findFirstAsOptionalTerm

      public Optional<Term> findFirstAsOptionalTerm()
      Attempt to execute the query once and return a Term representation of the term the single query variable was unified with.
      Returns:
      the value the query variable has been unified with, or an empty optional if the query was not successfully evaluated
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findAllAsAtomName

      public List<String> findAllAsAtomName()
      Find all solutions generated by the query and return String representations of the atoms the single query variable was unified with.
      Returns:
      list of atom names the query variable was been unified with as a result of executing the query until no more solutions were found
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findAllAsDouble

      public List<Double> findAllAsDouble()
      Find all solutions generated by the query and return the double values the single query variable was unified with.
      Returns:
      list of values the query variable was been unified with as a result of executing the query until no more solutions were found
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findAllAsLong

      public List<Long> findAllAsLong()
      Find all solutions generated by the query and return the long values the single query variable was unified with.
      Returns:
      list of values the query variable was been unified with as a result of executing the query until no more solutions were found
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents
    • findAllAsTerm

      public List<Term> findAllAsTerm()
      Find all solutions generated by the query and return the Term values the single query variable was unified with.
      Returns:
      list of values the query variable was been unified with as a result of executing the query until no more solutions were found
      Throws:
      ProjogException - if the query could not be evaluated successfully
      ProjogException - of there is not exactly one named variable in the query this statement represents