Returns the first solution, if any, as a (possibly empty) Map of variablename-to-term bindings, else null. This method will throw a JPLException if this Query is already open (and the Query will remain open as before). Otherwise, upon return, the Query will be closed. @return the first solution, i
()
| 865 | * no solutions. |
| 866 | */ |
| 867 | public final Map<String, Term> oneSolution() { |
| 868 | if (open) { |
| 869 | throw new JPLException("Query is already open"); |
| 870 | } else { |
| 871 | Map<String, Term> solution; |
| 872 | if (hasMoreSolutions()) { |
| 873 | solution = nextSolution(); |
| 874 | close(); // safe, whether or not this is the only solution |
| 875 | } else { |
| 876 | solution = null; |
| 877 | } |
| 878 | return solution; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * This static method creates a Query (whose goal is the specified Term) and |