Skip to content

Commit

Permalink
Renamed get1() and get2() methods - Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ssardina committed Oct 6, 2018
1 parent 512b4f2 commit fba077f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/java/org/jpl7/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public boolean hasNext() {
// iterator
open();
}
return get1();
return fetchNextSolution();
}

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ public final boolean hasMoreSolutions() {
if (!open) {
open();
}
return get1();
return fetchNextSolution();
}

/**
Expand Down Expand Up @@ -339,7 +339,14 @@ public final void open() {
open = true;
}

private final boolean get1() { // try to get the next solution; if none,
/**
* Tell Prolog engine to fetch the next solution for the current active query (like hitting ;)
* If there are no more solutions, then just close the query
*
* @return whether a new solutions was found or there are no more solutions
* @throws PrologException with the term of the error from Prolog (e.g., syntax error in query or non existence of predicates)
*/
private final boolean fetchNextSolution() { // try to get the next solution; if none,
// close the query;
if (Prolog.next_solution(qid)) {
return true;
Expand Down Expand Up @@ -392,8 +399,8 @@ public final Map<String, Term> getSolution() {
// oughta check: thread has query's engine
if (!open) {
throw new JPLException("Query is not open");
} else if (get1()) {
return get2();
} else if (fetchNextSolution()) {
return getCurrentSolutionBindings();
} else {
return null;
}
Expand All @@ -403,7 +410,7 @@ public final Map<String, Term> getSubstWithNameVars() {
// oughta check: thread has query's engine
if (!open) {
throw new JPLException("Query is not open");
} else if (get1()) {
} else if (fetchNextSolution()) {
return get2WithNameVars();
} else {
return null;
Expand Down Expand Up @@ -442,10 +449,10 @@ public final Map<String, Term> getSubstWithNameVars() {
* @return A Map representing a substitution.
*/
public final Map<String, Term> nextSolution() {
return get2();
return getCurrentSolutionBindings();
}

private final Map<String, Term> get2() {
private final Map<String, Term> getCurrentSolutionBindings() {
if (!open) {
throw new JPLException("Query is not open");
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/java/org/jpl7/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ protected void getSubst(Map<String, Term> varnames_to_Terms, Map<term_t, Variabl
* Just calls computeSubstitution for each Term in the array.
*
* @param varnames_to_Terms
* a Map from variable names to Terms
* a Map from variable names to Terms (what each variable string is to be replaced by)
* @param vars_to_Vars
* a Map from Prolog variables to JPL Variables
* a Map from Prolog variables (which may be bounded in the engine) to JPL Variables (which are Java objects)
* @param args
* an array of Terms
* an array of Terms to which the substitution is to be applied
*/
protected static void getSubsts(Map<String, Term> varnames_to_Terms, Map<term_t, Variable> vars_to_Vars,
Term[] args) {
Expand Down

0 comments on commit fba077f

Please sign in to comment.