calls the Query's goal to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found). @param n the number of solutions to cover @return an arra
(long n)
| 769 | * type being just a concrete syntax for terms (and hence queries). |
| 770 | */ |
| 771 | public final Map<String, Term>[] nSolutions(long n) { |
| 772 | if (open) { |
| 773 | throw new JPLException("Query is already open"); |
| 774 | } else { // get a vector of solutions, then turn it into an array |
| 775 | // Vector<Map<String, Term>> v = new Vector<Map<String, Term>>(); |
| 776 | // for (long i = 0; i++ < n && hasMoreSolutions();) { |
| 777 | // v.addElement(nextSolution()); |
| 778 | // } |
| 779 | // @SuppressWarnings("unchecked") |
| 780 | // Map<String, Term> solutions[] = (Map<String, Term>[]) new |
| 781 | // Map[v.size()]; // 0 solutions -> Map[0] |
| 782 | // v.copyInto(solutions); |
| 783 | // return solutions; |
| 784 | List<Map<String, Term>> l = new ArrayList<Map<String, Term>>(); |
| 785 | for (long i = 0; i++ < n && hasMoreSolutions();) { |
| 786 | l.add(next()); |
| 787 | } |
| 788 | @SuppressWarnings("unchecked") // https://stackoverflow.com/questions/1129795/what-is-suppresswarnings-unchecked-in-java |
| 789 | Map<String, Term> t[] = (Map<String, Term>[]) new HashMap[0]; |
| 790 | return l.toArray(t); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * This static method creates a Query whose goal is the given Term, calls it |