1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package jTrolog.terms;
23
24 import java.util.Iterator;
25
26 import jTrolog.engine.Prolog;
27 import jTrolog.parser.Parser;
28 @SuppressWarnings({ "serial" })
29 public class StructAtom extends Struct {
30
31 public StructAtom(String name) {
32 super(name, new Term[0]);
33 type = Term.ATOM;
34 }
35
36 public boolean equals(Object t) {
37 return t instanceof StructAtom && name == ((StructAtom) t).name;
38 }
39
40 public String toString() {
41 if (name.isEmpty()) {
42 return "''";
43 } else if (!Parser.isAtom(name) && !isOperator(name) && !name.equals("[]")) {
44 return "'" + name + "'";
45 }
46 return name;
47 }
48
49 public String toStringSmall() {
50 return toString();
51 }
52
53 private boolean isOperator(String name) {
54 Prolog engine = Prolog.defaultMachine;
55 Iterator<?> i = engine.getCurrentOperators();
56 while (i.hasNext()) {
57 Object object = i.next();
58 if (object instanceof Struct) {
59 Struct o = (Struct) object;
60 String n = ((StructAtom) o.getArg(2)).name;
61 if (name.equals(n)) {
62 return true;
63 }
64 }
65 }
66 return false;
67 }
68
69 }