1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package io.github.prolobjectlink.prolog.jpl7;
30
31 import static org.jpl7.JPL.JFALSE;
32 import static org.jpl7.JPL.JNULL;
33 import static org.jpl7.JPL.JTRUE;
34 import static org.jpl7.JPL.JVOID;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Map;
39
40 import org.jpl7.Term;
41 import org.jpl7.Util;
42
43 import io.github.prolobjectlink.prolog.AbstractProvider;
44 import io.github.prolobjectlink.prolog.PrologAtom;
45 import io.github.prolobjectlink.prolog.PrologConverter;
46 import io.github.prolobjectlink.prolog.PrologDouble;
47 import io.github.prolobjectlink.prolog.PrologFloat;
48 import io.github.prolobjectlink.prolog.PrologInteger;
49 import io.github.prolobjectlink.prolog.PrologJavaConverter;
50 import io.github.prolobjectlink.prolog.PrologList;
51 import io.github.prolobjectlink.prolog.PrologLogger;
52 import io.github.prolobjectlink.prolog.PrologLong;
53 import io.github.prolobjectlink.prolog.PrologProvider;
54 import io.github.prolobjectlink.prolog.PrologStructure;
55 import io.github.prolobjectlink.prolog.PrologTerm;
56 import io.github.prolobjectlink.prolog.PrologVariable;
57
58
59
60
61
62
63 public abstract class JplProvider extends AbstractProvider implements PrologProvider {
64
65 static final PrologLogger logger = new JplLogger();
66
67 protected JplProvider(PrologConverter<Term> adapter) {
68 super(adapter);
69 }
70
71 public final PrologTerm prologNil() {
72 return new JplNil(this);
73 }
74
75 public final PrologTerm prologCut() {
76 return new JplCut(this);
77 }
78
79 public final PrologTerm prologFail() {
80 return new JplFail(this);
81 }
82
83 public final PrologTerm prologTrue() {
84 return new JplTrue(this);
85 }
86
87 public final PrologTerm prologFalse() {
88 return new JplFalse(this);
89 }
90
91 public final PrologTerm prologEmpty() {
92 return new JplEmpty(this);
93 }
94
95 public final PrologTerm prologInclude(String file) {
96 return newStructure("consult", newAtom(file));
97 }
98
99 public final PrologTerm parseTerm(String term) {
100 return toTerm(Util.textToTerm(term), PrologTerm.class);
101 }
102
103 public final PrologTerm[] parseTerms(String stringTerms) {
104 PrologTerm[] a = new PrologTerm[0];
105 Term ptr = Util.textToTerm(stringTerms);
106 List<PrologTerm> terms = new ArrayList<PrologTerm>();
107 while (ptr.isCompound() && ptr.hasFunctor(",", 2)) {
108 terms.add(toTerm(ptr.arg(1), PrologTerm.class));
109 ptr = ptr.arg(2);
110 }
111 terms.add(toTerm(ptr, PrologTerm.class));
112 return terms.toArray(a);
113 }
114
115 public final PrologAtom newAtom(String functor) {
116 return new JplAtom(this, functor);
117 }
118
119 public final PrologFloat newFloat(Number value) {
120 return new JplFloat(this, value);
121 }
122
123 public final PrologDouble newDouble(Number value) {
124 return new JplDouble(this, value);
125 }
126
127 public final PrologInteger newInteger(Number value) {
128 return new JplInteger(this, value);
129 }
130
131 public final PrologLong newLong(Number value) {
132 return new JplLong(this, value);
133 }
134
135 public final PrologVariable newVariable(int position) {
136 return new JplVariable(this);
137 }
138
139 public final PrologVariable newVariable(String name, int position) {
140 return new JplVariable(this, name);
141 }
142
143 public final PrologList newList() {
144 return new JplList(this);
145 }
146
147 public final PrologList newList(PrologTerm[] arguments) {
148 return new JplList(this, arguments);
149 }
150
151 public final PrologList newList(PrologTerm head, PrologTerm tail) {
152 return new JplList(this, head, tail);
153 }
154
155 public final PrologList newList(PrologTerm[] arguments, PrologTerm tail) {
156 return new JplList(this, arguments, tail);
157 }
158
159 public final PrologStructure newStructure(String functor, PrologTerm... arguments) {
160 return new JplStructure(this, functor, arguments);
161 }
162
163 public final PrologTerm newStructure(PrologTerm left, String operator, PrologTerm right) {
164 return new JplStructure(this, left, operator, right);
165 }
166
167 public final PrologTerm newEntry(PrologTerm key, PrologTerm value) {
168 return new JplEntry(this, key, value);
169 }
170
171 public final PrologTerm newEntry(Object key, Object value) {
172 PrologJavaConverter transformer = getJavaConverter();
173 PrologTerm keyTerm = transformer.toTerm(key);
174 PrologTerm valueTerm = transformer.toTerm(value);
175 return new JplEntry(this, keyTerm, valueTerm);
176 }
177
178 public final PrologTerm newMap(Map<PrologTerm, PrologTerm> map) {
179 return new JplMap(this, map);
180 }
181
182 public final PrologTerm newMap(int initialCapacity) {
183 return new JplMap(this, initialCapacity);
184 }
185
186 public final PrologTerm newMap() {
187 return new JplMap(this);
188 }
189
190 public final PrologTerm newReference(Object reference) {
191 return new JplReference(this, reference);
192 }
193
194 public final PrologTerm falseReference() {
195 return new JplReference(this, JFALSE);
196 }
197
198 public final PrologTerm trueReference() {
199 return new JplReference(this, JTRUE);
200 }
201
202 public final PrologTerm nullReference() {
203 return new JplReference(this, JNULL);
204 }
205
206 public final PrologTerm voidReference() {
207 return new JplReference(this, JVOID);
208 }
209
210 public final PrologLogger getLogger() {
211 return logger;
212 }
213
214 }