-
Notifications
You must be signed in to change notification settings - Fork 0
/
CS.java
254 lines (217 loc) · 4.83 KB
/
CS.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
*
*/
package simulator;
import java.io.Serializable;
/**
* City University BSc Computing with Artificial Intelligence Project title:
* Building a TD Simulator for Real-Time Classical Conditioning
*
* @supervisor Dr. Eduardo Alonso
* @author Jonathan Gray
**/
public class CS implements Comparable, Serializable {
public static CS TOTAL = new CS("Total", 0, 0);
public static CS CS_TOTAL = new CS("CS_Total", 0, 0);
public static CS OMEGA = new CS("Omega", 0, 0);
public static CS US = new CS("US", 0, 0);
private static final long serialVersionUID = 1L;
/** String name. **/
private String name;
/** Which of this CS in the trial string is this? **/
private int hash;
/** Trial group number. **/
private int group;
/** Overall position in string. **/
private int stringPos;
/** Is this a probe CS? **/
private boolean isProbe;
/** Should it show primes? **/
private boolean showPrimes;
/** Trial string this CS belongs to. **/
private String trialString = "";
/**
*
*/
public CS(String name) {
this.name = name;
hash = super.hashCode();
group = 0;
isProbe = false;
showPrimes = false;
stringPos = 0;
}
public CS(String name, int hash, int group) {
this(name);
this.group = group;
this.hash = hash;
isProbe = false;
}
public CS(String name, int hash, int group, boolean probe) {
this(name, hash, group);
isProbe = probe;
}
public CS(String name, int hash, int group, boolean probe, int stringPos) {
this(name, hash, group, probe);
this.stringPos = stringPos;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Object arg0) {
CS other = (CS) arg0;
// Added a more rigorous compare to resolve misordering in duration
// treeset
if (!name.equals(other.getName())) {
return name.compareTo(other.getName());
} else if (group > other.getGroup()) {
return 1;
} else if (group < other.getGroup()) {
return -1;
} else if (hash > other.hashCode()) {
return 1;
} else if (hash < other.hashCode()) {
return -1;
} else if (stringPos > other.getStringPos()) {
return 1;
} else if (stringPos < other.getStringPos()) {
return -1;
}
return 0;
}
public CS copy() {
return new CS(name, hash, group, isProbe, stringPos);
}
@Override
public boolean equals(Object other) {
if (other instanceof CS) {
CS target = (CS) other;
if (!name.equals(target.getName())) {
return false;
} else if (target.hashCode() != hashCode()) {
return false;
} else if (target.getGroup() != group) {
return false;
} else if (target.getStringPos() != stringPos) {
return false;
} else {
return true;
}
}
// Fall back to string compare
return name.equals(other);
}
/**
* @return the group
*/
public int getGroup() {
return group;
}
public String getName() {
return name;
}
public String getProbeSymbol() {
int numPrimes = isShowPrimes() ? hash + 1 : 0;
String primes = new String(new char[numPrimes]).replace("\0", "'");
return getName() + primes;
}
/**
* @return the trialString
*/
public String getTrialString() {
return trialString;
}
@Override
public int hashCode() {
return hash;
}
/**
*
* @return true if this is a compound CS of any kind.
*/
public boolean isCompound() {
return this.name.length() > 1;
}
public boolean isConfigural() {
return !name.toUpperCase().equals(name) && name.length() == 1;
}
/**
* @return true if this is a probe CS
*/
public boolean isProbe() {
return isProbe;
}
public boolean isSerialConfigural() {
return false;
}
/**
* @return the showPrimes
*/
public boolean isShowPrimes() {
return showPrimes;
}
/**
* @param group
* the group to set
*/
public void setGroup(int group) {
this.group = group;
}
public void setHashCode(int code) {
hash = code;
}
public void setName(String newName) {
name = newName;
}
/**
* @param isProbe
* set to true if this is a probe CS.
*/
public void setProbe(boolean isProbe) {
this.isProbe = isProbe;
}
/**
* @param showPrimes
* the showPrimes to set
*/
public void setShowPrimes(boolean showPrimes) {
this.showPrimes = showPrimes;
}
/**
* @param trialString
* the trialString to set
*/
public void setTrialString(String trialString) {
this.trialString = trialString;
}
@Override
public String toString() {
return name;
}
/**
* @return the stringPos
*/
public int getStringPos() {
return stringPos;
}
/**
* @param stringPos the stringPos to set
*/
public void setStringPos(int stringPos) {
this.stringPos = stringPos;
}
public int getLocalStringPos() {
int pos = 0;
int count = -1;
while(pos < trialString.length() && count < hash) {
if(trialString.substring(pos, pos+1).equals(name)) {
count++;
}
pos++;
}
return pos;
}
}