calls the Query's goal to exhaustion and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found). @return an array of zero or more Maps of zero or more variablename-to-term bindings (each Map
()
| 668 | * type being just a concrete syntax for terms (and hence queries). |
| 669 | */ |
| 670 | public final Map<String, Term>[] allSolutions() { |
| 671 | if (open) { |
| 672 | throw new JPLException("Query is already open"); |
| 673 | } else { // get a vector of solutions, then turn it into an array |
| 674 | // First, collect all solutions in a (dynamic) list of substitution mappings |
| 675 | List<Map<String, Term>> l = new ArrayList<Map<String, Term>>(); |
| 676 | while (hasNext()) { |
| 677 | l.add(next()); |
| 678 | } |
| 679 | |
| 680 | // Second, convert the list into an array of Mappings (0 solutions -> Map[0]) |
| 681 | @SuppressWarnings("unchecked") //https://stackoverflow.com/questions/1129795/what-is-suppresswarnings-unchecked-in-java |
| 682 | Map<String, Term>[] t = (Map<String, Term>[]) new HashMap[0]; |
| 683 | return l.toArray(t); // https://codeahoy.com/java/How-To-Convery-ArrayList-To-Array/ |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * This static method creates a Query whose goal is the given Term, calls it |