1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package io.github.prolobjectlink.prolog.jtrolog;
23
24 import static io.github.prolobjectlink.prolog.PrologTermType.VARIABLE_TYPE;
25
26 import io.github.prolobjectlink.prolog.ArityError;
27 import io.github.prolobjectlink.prolog.FunctorError;
28 import io.github.prolobjectlink.prolog.PrologProvider;
29 import io.github.prolobjectlink.prolog.PrologTerm;
30 import io.github.prolobjectlink.prolog.PrologVariable;
31 import jTrolog.terms.Term;
32 import jTrolog.terms.Var;
33
34
35
36
37
38
39 class JTrologVariable extends JTrologTerm implements PrologVariable {
40
41 private String name;
42
43 JTrologVariable(PrologProvider provider, int n) {
44 this(provider, "_", n);
45 this.name = "_";
46 }
47
48 JTrologVariable(PrologProvider provider, String name, int n) {
49 super(VARIABLE_TYPE, provider, name, n);
50 this.name = name;
51 }
52
53 JTrologVariable(int type, PrologProvider provider) {
54 super(type, provider);
55 }
56
57 JTrologVariable(int type, PrologProvider provider, String name, int n) {
58 super(type, provider, name, n);
59 this.name = name;
60 }
61
62 JTrologVariable(int type, PrologProvider provider, Term var) {
63 super(type, provider, var);
64 }
65
66 public boolean isAnonymous() {
67 return ((Var) value).isAnonymous();
68 }
69
70 public String getName() {
71 return name;
72 }
73
74 public void setName(String name) {
75 this.name = name;
76 }
77
78 public PrologTerm[] getArguments() {
79 return new JTrologVariable[0];
80 }
81
82 public int getArity() {
83 throw new ArityError(this);
84 }
85
86 public String getFunctor() {
87 throw new FunctorError(this);
88 }
89
90 public int getPosition() {
91 return vIndex;
92 }
93
94 @Override
95 public int hashCode() {
96 final int prime = 31;
97 int result = super.hashCode();
98 result = prime * result + ((name == null) ? 0 : name.hashCode());
99 return result;
100 }
101
102 @Override
103 public boolean equals(Object obj) {
104 if (this == obj)
105 return true;
106 if (obj == null)
107 return false;
108 if (getClass() != obj.getClass())
109 return false;
110 JTrologVariable other = (JTrologVariable) obj;
111 if (name == null) {
112 if (other.name != null)
113 return false;
114 } else if (!name.equals(other.name)) {
115 return false;
116 }
117 return true;
118 }
119
120 }