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.jlog;
23
24 import ubc.cs.JLog.Foundation.jEquivalenceMapping;
25 import ubc.cs.JLog.Foundation.jUnifiedVector;
26 import ubc.cs.JLog.Foundation.jVariableRegistry;
27 import ubc.cs.JLog.Foundation.jVariableVector;
28 import ubc.cs.JLog.Terms.iPredicate;
29 import ubc.cs.JLog.Terms.jInteger;
30 import ubc.cs.JLog.Terms.jReal;
31 import ubc.cs.JLog.Terms.jTerm;
32 import ubc.cs.JLog.Terms.jVariable;
33
34
35
36
37
38
39 final class jLong extends jTerm {
40
41 private long value;
42
43 jLong(long v) {
44 value = v;
45 type = TYPE_INTEGER;
46 }
47
48 @Override
49 public String getName() {
50 return String.valueOf(value);
51 }
52
53 public long getIntegerValue() {
54 return value;
55 }
56
57 protected int compare(jTerm term, boolean firstCall, boolean varEqual) {
58 jTerm t = term.getTerm();
59
60 if (t instanceof jVariable)
61 return GREATER_THAN;
62
63 if (t instanceof jReal)
64 return GREATER_THAN;
65
66 if (t instanceof jFloat)
67 return GREATER_THAN;
68
69 if (t instanceof jDouble)
70 return GREATER_THAN;
71
72 if (t instanceof jInteger) {
73 int i = ((jInteger) t).getIntegerValue();
74
75 if (value < i)
76 return LESS_THAN;
77 else if (value > i)
78 return GREATER_THAN;
79 else
80 return EQUAL;
81 }
82
83 if (t instanceof iPredicate)
84 return LESS_THAN;
85
86 return (firstCall ? -t.compare(this, varEqual) : EQUAL);
87 }
88
89 public boolean equivalence(jTerm term, jEquivalenceMapping v) {
90 jTerm t = term.getTerm();
91
92
93 if (this == t)
94 return true;
95
96 if (type != t.type)
97 return false;
98
99
100
101
102 return (value == ((jLong) t).value);
103 }
104
105 public boolean unify(jTerm term, jUnifiedVector v) {
106
107 if (term.type == TYPE_VARIABLE)
108 return term.unify(this, v);
109
110
111 if (this == term)
112 return true;
113
114 if (type != term.type)
115 return false;
116
117
118
119
120 return (value == ((jLong) term).value);
121 }
122
123 public void registerVariables(jVariableVector v) {
124
125 }
126
127 public void enumerateVariables(jVariableVector v, boolean all) {
128
129 }
130
131 public jTerm duplicate(jVariable[] vars) {
132 return this;
133
134 }
135
136 public jTerm copy(jVariableRegistry vars) {
137 return this;
138
139 }
140
141 public String toString(boolean usename) {
142 return String.valueOf(value);
143 }
144 }