1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package jTrolog.engine;
23
24 import jTrolog.terms.Term;
25
26 import java.util.HashMap;
27 import java.util.Iterator;
28
29
30
31
32 @SuppressWarnings({ "rawtypes" })
33 public class Solution {
34
35 private static final HashMap emptyMap = new HashMap();
36
37 HashMap bindings;
38 Term solution;
39
40 public Solution(Term solution) {
41 this.bindings = emptyMap;
42 this.solution = solution;
43 }
44
45 public Solution(HashMap bindings, Term solution) {
46 this.bindings = bindings;
47 this.solution = solution;
48 }
49
50
51
52
53 public boolean success() {
54 return solution != null;
55 }
56
57
58
59
60 public Term getSolution() {
61 return solution;
62 }
63
64
65
66
67
68
69 public Term getBinding(String varName) {
70 return (Term) bindings.get(varName);
71 }
72
73 public String toString() {
74 return solution == null ? "no" : solution.toString();
75 }
76
77 public String bindingsToString() {
78 StringBuffer buffy = new StringBuffer();
79 for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
80 String variable = (String) it.next();
81 Term binding = (Term) bindings.get(variable);
82 buffy.append(variable).append(": ").append(binding).append("\n");
83 }
84 return buffy.toString();
85 }
86 }