Class QueryResult


  • public final class QueryResult
    extends java.lang.Object
    Represents an executing query.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean evaluate()  
      java.lang.String getAtomName​(java.lang.String variableId)
      Returns the name of the atom instantiated to the variable with the specified id.
      double getDouble​(java.lang.String variableId)
      Returns the double value instantiated to the variable with the specified id.
      long getLong​(java.lang.String variableId)
      Returns the long value instantiated to the variable with the specified id.
      Term getTerm​(java.lang.String variableId)
      Returns the term instantiated to the variable with the specified id.
      java.util.Set<java.lang.String> getVariableIds()
      Returns id's of all variables defined in the query this object represents.
      boolean isExhausted()
      Returns true if it is known that all possible solutions have been found, else false.
      boolean next()
      Attempts to evaluate the query this object represents.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • predicate

        private final Predicate predicate
      • variables

        private final java.util.Map<java.lang.String,​Variable> variables
      • hasBeenEvaluated

        private boolean hasBeenEvaluated
      • hasFailed

        private boolean hasFailed
    • Constructor Detail

      • QueryResult

        QueryResult​(PredicateFactory predicateFactory,
                    Term query,
                    java.util.Map<java.lang.String,​Variable> variables)
        Evaluates a query.
        Parameters:
        PredicateFactory - the PredicateFactory that will be used to evaluate the query
        query - represents the query statement being evaluated
        variables - collection of variables contained in the query (keyed by variable id)
        See Also:
        QueryStatement.executeQuery()
    • Method Detail

      • next

        public boolean next()
        Attempts to evaluate the query this object represents.

        Subsequent calls of the next() method attempt to reevaluate the query, and because it returns false when the are no more results, it can be used in a while loop to iterate through all the results.

        Returns:
        true if the query was (re)evaluated successfully or false if there are no more results. Once false has been returned by next() the next() method should no longer be called on that object.
        Throws:
        ProjogException - if an error occurs while evaluating the query
      • evaluate

        private boolean evaluate()
      • isExhausted

        public boolean isExhausted()
        Returns true if it is known that all possible solutions have been found, else false.
        Returns:
        true if it is known that all possible solutions have been found, else false.
        See Also:
        Predicate.couldReevaluationSucceed()
      • getAtomName

        public java.lang.String getAtomName​(java.lang.String variableId)
        Returns the name of the atom instantiated to the variable with the specified id.
        Parameters:
        variableId - the id of the variable from which to return the instantiated term
        Returns:
        the name of the atom instantiated to the variable with the specified id
        Throws:
        ProjogException - if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not an atom
        See Also:
        getTerm(String)
      • getDouble

        public double getDouble​(java.lang.String variableId)
        Returns the double value instantiated to the variable with the specified id.
        Parameters:
        variableId - the id of the variable from which to return the instantiated term
        Returns:
        the name of the atom instantiated to the variable with the specified id
        Throws:
        ProjogException - if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not a number
        See Also:
        getTerm(String)
      • getLong

        public long getLong​(java.lang.String variableId)
        Returns the long value instantiated to the variable with the specified id.
        Parameters:
        variableId - the id of the variable from which to return the instantiated term
        Returns:
        the value instantiated to the variable with the specified id
        Throws:
        ProjogException - if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not a number
        See Also:
        getTerm(String)
      • getTerm

        public Term getTerm​(java.lang.String variableId)
        Returns the term instantiated to the variable with the specified id.

        next() must be called before this method.

        Parameters:
        variableId - the id of the variable from which to return the instantiated term
        Returns:
        the term instantiated to the variable with the specified id (or the Variable of representing the variable if it is uninstantiated)
        Throws:
        ProjogException - if no variable with the specified id exists in the query this object represents
        See Also:
        getAtomName(String), getDouble(String), getLong(String)
      • getVariableIds

        public java.util.Set<java.lang.String> getVariableIds()
        Returns id's of all variables defined in the query this object represents.
        Returns:
        id's of all variables defined in the query this object represents