MCPcopy Create free account
hub / github.com/SWI-Prolog/packages-jpl / allSolutions

Method allSolutions

src/main/java/org/jpl7/Query.java:670–685  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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

Callers 15

testArrayToList1Method · 0.95
testArrayToList2Method · 0.95
testArrayToList3Method · 0.95
testStringToListMethod · 0.95
testGenerate1Method · 0.95
testMap2Method · 0.95
testBerhhard1Method · 0.95
runMethod · 0.95
test_4Method · 0.95
test_5Method · 0.95
test_6Method · 0.95

Calls 2

hasNextMethod · 0.95
nextMethod · 0.95

Tested by 15

testArrayToList1Method · 0.76
testArrayToList2Method · 0.76
testArrayToList3Method · 0.76
testStringToListMethod · 0.76
testGenerate1Method · 0.76
testMap2Method · 0.76
testBerhhard1Method · 0.76
runMethod · 0.76
test_4Method · 0.76
test_5Method · 0.76
test_6Method · 0.76