-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1748 lines (1579 loc) · 71.9 KB
/
index.html
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<!-- This is a recreation, in HTML and JavaScript, of Davis Gries's FacultyApplet,
a Java applet which displays a list of Cornell Computer Science Department faculty members.
See the original at https://www.cs.cornell.edu/gries/facultyunix/first.html.
The motivation behind this rewrite is to support modern browsers; these days, browsers
won't run Java applets.
The original FacultyApplet was surprisingly elaborate, given its relatively simple purpose.
Presumably it was written to gain familiarity with Java, or as a demonstration of Java.
This version attempts to recreate the functionality and appearance of the original
as accurately as reasonably possible.
Much of the code here is a translation of the original Java code to JavaScript.
Several automated tools were used to aid in the conversion of the Java code to JavaScript,
including codeconvert.ai, blackbox.ai, www.stratacode.com/javaToJS/online.html, and
Github Copilot.
There was also a fair bit of manual coding.
Mark Riordan January 2024 [email protected]
Released under the MIT License.
This source code is at https://github.com/riordanmr/facultyapp/
and is deployed at https://riordanmr.github.io/facultyapp/
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="shortcut icon" href="favicon.ico" />
<title>FacultyApp</title>
<style>
.topfont {
font-family: Arial,sans-serif;
font-size: 10pt;
}
.topinstructions {
text-align: center;
width: 800px;
margin-bottom: 4px;
}
#canvasMain {
border: none;
padding: 0px;
margin: 0px;
}
#scrollbarvert {
border: none;
padding: 0px;
margin: 0px;
}
#scrollbarHorz {
border: none;
padding: 0px;
margin: 0px;
}
#dlgAbout {
background-color: #fafad2;
font-family: Arial, sans-serif;
}
/* The Close Button */
.close {
color: black;
position: absolute;
top: 0em;
right: 0.33em;
font-size: 1.5em;
font-weight: bold;
padding: 0px;
cursor: pointer;
}
.authorindent {
margin-left: 1em;
}
.author p {
margin: 0.4em 0;
}
.bigvertspace {
line-height: 150%;
}
.tablenopadding {
border-spacing: 0 !important;
border-collapse: collapse !important;
margin: 0 !important;
}
.cellnopadding {
border: none !important;
padding: 0 !important;
margin: 0 !important;
font-size: 0pt;
line-height: 0px;
}
</style>
<!-- This is the equivalent of the embedded resource faclist.txt.
Here is the original documentation for faclist.txt:
The faculty appear in faclist.txt in any
order. For each person, give the following information:
Name, with character '=' instead of a blank --the name may
not contain a blank.
Description of a period of service. (These descriptions must
Description of next period of service. appear in chronological
... order and have no overlap)
Description of last period of service.
A period "."
A description of a period of service consists of:
An optional leave thing: "SAB" for sabbatic and "LEA" for other leaves
A title: "L" for lecturer,
"SL" for senior lecturer,
"I" for instructor,
"A1" for assistant professor,
"A2" for associate professor,
"FP" for full professor,
"EP" for professor emeritus
"F" for a member of the Field of CS who is not a member
of the department
The first semester of the period (e.g. F 1989 or S 1965)
The last semester of the period (e.g. S 1989). If the last semester is
the current one and the person is expected to be on the faculty
in the next semester, use "present" for the last semester.
SEPARATE EACH PIECE OF DATA BY AT LEAST ONE BLANK OR BY AN END-OF-LINE.
-->
<script type="text/javascript" src="faclist.js"></script>
<!-- Class to implement scrollbars. -->
<script type="text/javascript" src="CSScrollbar.js"></script>
</head>
<body>
<!-- HTML text and controls -->
<div class="topfont topinstructions">CS FACULTY OVER THE YEARS! Choose a range of years and a sort key and
press OK.</div>
<div class="topfont"> </div>
<div class="topfont topinstructions">To sort on x with secondary keys y and z, first sort on z, then y, then x.
</div>
<div class="topfont"> </div>
<div class="topfont topinstructions">First: <select name="selfirst" id="selfirst">
</select>
Last: <select name="sellast" id="sellast">
</select>
Sort by:
<select name="selsortby" id="selsortby">
<option value="name">name</option>
<option value="first semester">first semester</option>
<option value="last semester">last semester</option>
<option value="time in dept.">time in dept.</option>
<option value="title">title</option>
</select>
<button id="btnok" onclick="onOK();">OK</button>
<button id="btnabout">About ...</button>
</div>
<dialog id="dlgAbout">
<div>
<span onclick="document.getElementById('dlgAbout').close()" class="close">×</span>
<div class="bigvertspace">Original version developed by</div>
<div class="authorindent bigvertspace">
David Gries<br/>
Computer Science, Upson Hall<br/>
Cornell University<br/>
Ithaca, NY 14853<br/>
</div>
<div class="bigvertspace">JavaScript version by</div>
<div class="authorindent bigvertspace">
Mark Riordan<br/>
</div>
<div class="bigvertspace">See
<a href="https://www.cs.cornell.edu/gries/facultyunix/first.html">https://www.cs.cornell.edu/gries/facultyunix/first.html</a><br/>
for information about the original applet.</div>
</div>
</dialog>
<!-- The canvas for the main display, plus canvases for the scrollbars -->
<table class="tablenopadding">
<tr>
<td class="cellnopadding"><canvas id="canvasMain" width="800" height="460"></canvas></td>
<td class="cellnopadding"><canvas id="scrollbarVert" width="15" height="460"></canvas></td>
</tr>
<tr>
<td class="cellnopadding"><canvas id="scrollbarHorz" width="800" height="15"></canvas></td>
<td class="cellnopadding"></td>
</tr>
</table>
<script>
// Constants to identify sort keys.
const BYNAME = 0;
const BYFIRSTSEMESTER = 1;
const BYLASTSEMESTER = 2;
const BYLENGTH = 3;
const BYTITLE = 4;
const LASTYEAR = 1998;
// Given a context, compute the number of pixels between consecutive lines of text,
// including any necessary leading.
// Thanks to https://stackoverflow.com/questions/1134586
function computeFontHeight(ctx) {
let metrics = ctx.measureText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ");
let fontHeight = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent;
let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
return 1.07 * actualHeight;
}
// Convert red, green, blue integers to an HTML color code.
function rgb(r, g, b) {
const toHex = n => n.toString(16).padStart(2, '0');
return '#' + toHex(r) + toHex(g) + toHex(b);
}
// Class to represent a pair of integer values x and y.
// Converted from Coordinates.java by blackbox.ai:
class Coordinates {
constructor(h, k) {
this.x = h;
this.y = k;
}
}
// A representation of a semester
// (e.g. Fall 1997 or Spring 1998)
// Converted from Semester.java by codeconvert.ai
class Semester {
// Constructor --the semester that is in month m and 4-digit year y.
// Months 0..5 are the spring semester; months 6..11, fall semester
constructor(m, y) {
this.yr = y;
if (m <= 5) this.sem = 0;
else this.sem = 1;
}
// Yield the semester, as a String "F" or "S"
semester() {
if (this.sem === 0) return "S";
return "F";
}
// Set the semester to t (which is "F" or "S")
setSemester(t) {
if (t === "S")
this.sem = 0;
else this.sem = 1;
}
// Yield the year
year() {
return this.yr;
}
// Set the year to i
setYear(i) {
this.yr = i;
}
// = Semester s1 comes before or is the same as Semester s2
static lesseq(s1, s2) {
if (s1.year() < s2.year()) return true;
if (s1.year() > s2.year()) return false;
return s1.sem <= s2.sem;
}
// = Semester s1 comes before Semester s2
static less(s1, s2) {
if (s1.year() < s2.year()) return true;
if (s1.year() > s2.year()) return false;
return s1.sem < s2.sem;
}
// = Semesters s1 and s2 are the same
static equals(s1, s2) {
return s1.yr === s2.yr && s1.sem === s2.sem;
}
// = the Semester following this Semester
next() {
let s = new Semester();
s.yr = this.yr;
s.sem = 1 - this.sem;
if (s.sem === 0)
s.yr = s.yr + 1;
return s;
}
// = the number of Semesters between Semesters s1 and s2 --i.e.
// the number of times s1.next() is to be executed to get to s2
// (Precondition: lesseq(s1, s2); otherwise, 0 is returned)
static difference(s1, s2) {
if (this.less(s2, s1)) return 0;
if (s1.sem === s2.sem)
return 2 * (s2.yr - s1.yr);
return 1 + 2 * (s2.yr - s1.next().yr);
}
// = the minimum of Semesters s1 and s2
static min(s1, s2) {
if (this.lesseq(s1, s2)) return s1;
return s2;
}
// = the maximum of Semesters s1 and s2
static max(s1, s2) {
if (this.lesseq(s1, s2)) return s2;
return s1;
}
// = a String version of this Semester
toString() {
if (this.sem === 0) return "S" + this.yr;
return "F" + this.yr;
}
}
// A node of a linked list (or class LinkedList)
class LinkedListNode {
constructor(value = null) {
this.value = value;
this.next = null;
}
}
// Class of the base of a linked list, with head/tail
// pointers, with objects that are owned by the list
class LinkedList {
// Constructor: a list with one node with value value
constructor(value = null) {
if (value === null) {
this.head = null;
this.tail = null;
} else {
this.head = new LinkedListNode(value);
this.tail = this.head;
}
this.sz = value === null ? 0 : 1;
}
// Prepend value to list
prepend(value) {
const newNode = new LinkedListNode(value);
newNode.next = this.head;
this.head = newNode;
if (this.tail === null) {
this.tail = newNode;
}
this.sz++;
}
// Change the value of the first entry of the
// nonempty list to value
change(value) {
if (this.head !== null) {
this.head.value = value;
}
}
// Append value to list
append(value) {
if (this.head === null) {
this.head = new LinkedListNode(value);
this.tail = this.head;
} else {
this.tail.next = new LinkedListNode(value);
this.tail = this.tail.next;
}
this.sz++;
}
// Remove first element of list and return it --return
// null if list is empty
remove() {
if (this.head === null) {
return null;
}
const value = this.head.value;
this.head = this.head.next;
this.sz--;
if (this.head === null) {
this.tail = null;
}
return value;
}
// = first element of list (or null if list is empty)
// It should not be changed, but only inspected
inspect() {
return this.head === null ? null : this.head.value;
}
// = element n of the list (or null if not possible)
// Precondition: 0<= n< this.size()
inspectAt(index) {
let current = this.head;
let i = 0;
while (i < index && current !== null) {
current = current.next;
i++;
}
return current === null ? null : current.value;
}
// = last element of list (or null if list is empty)
// The element should not be changed, but only inspected
inspectLast() {
return this.tail === null ? null : this.tail.value;
}
// = list is empty
isEmpty() {
return this.head === null;
}
// = size of list
size() {
return this.sz;
}
// Set the list to an empty list
clear() {
this.head = null;
this.tail = null;
this.sz = 0;
}
// Return the list but truncated to its first n elements
// Precondition: 0 <= n <= this.size()
truncate(n) {
if (n === 0) {
this.clear();
return this;
}
this.sz = n;
let current = this.head;
while (n !== 1) {
n--;
current = current.next;
}
this.tail = current;
this.tail.next = null;
return this;
}
// Remove and return last element of the list (return null
// if none). This method is inefficient, because of the
// list's structure.
removeLast() {
if (this.sz === 0) {
return null;
}
if (this.sz === 1) {
const value = this.head.value;
this.head = null;
this.tail = null;
this.sz--;
return value;
}
let current = this.head;
while (current.next !== this.tail) {
current = current.next;
}
const value = this.tail.value;
this.tail = current;
this.tail.next = null;
this.sz--;
return value;
}
// a printable version of the elements of this LinkedList
// --assuming that toString() works for its elements
toString() {
let current = this.head;
let str = "(";
let isFirst = true;
while (current !== null) {
if (!isFirst) {
str += ", ";
}
isFirst = false;
str += current.value;
current = current.next;
}
return str + ")";
}
}
// Provide methods for iterating over objects
// in a LinkedList list
class LinkedListIterator {
// Constructor: to iterate over list s
constructor(linkedList) {
// head of the list
this.head = linkedList.head;
// current node to be processed
// (null if none)
this.node = this.head;
// index of current node (first is 0)
this.index = 0;
}
// change the current node to the beginning of the list
reset() {
this.node = this.head;
this.index = 0;
}
// = "current node is non-null"
okay() {
return this.node !== null;
}
// = value of current node --call only if node is non-null
data() {
return this.node.value;
}
// = change the current node to the next one in the list
// (or null if there is no next one)
next() {
if (this.node !== null) {
this.node = this.node.next;
this.index++;
}
}
// = index of current element (0 if past end of list)
getIndex() {
return this.node !== null ? this.index : 0;
}
}
// A dynamic array of elements of class Faculty
// Converted from DynArray.java by codeconvert.ai
class DynArray {
// sort0, sort1, and sort2 are used to define a sorting order.
// Each is one of the values CSCanvas.BYNAME--CS_Canvas.BYTITLE
// When an array is to be sorted, these values are used: sort0 defines
// the first sort key, sort1 the second, and sort2 the third. These
// variables are static so that, when a copy is made of the array,
// the current values are used. They are changed in method sort.
static sort0 = BYNAME; // Initally, all say sort on name
static sort1 = BYNAME;
static sort2 = BYNAME;
// Constructor: an array of 0 elements but allocation 10
constructor() {
this.b = new Array(10);
this.sz = 0;
}
// Add element f to the array
add(f) {
if (this.sz === this.b.length) {
let bTemp = this.b;
this.b = new Array(this.b.length * 4);
if (this.sz > 0) {
bTemp.slice(0, this.sz).forEach((item, index) => {
this.b[index] = item;
});
}
}
this.b[this.sz] = f;
this.sz += 1;
}
// = element i of the array
// Precondition: 0<=i<sz
element(i) {
return this.b[i];
}
// = number of filled elements in the array (not the number allocated)
size() {
return this.sz;
}
// = String verson of elements of the array
toString() {
let s = '';
for (let i = 0; i < this.sz; i++) {
s += "\n" + this.b[i].toString();
}
return s;
}
// Swap b[i] and b[k]
swap(i, k) {
let temp = this.b[i];
this.b[i] = this.b[k];
this.b[k] = temp;
}
// Remove element i from the array (put the last element in its place)
// It is assumed that 0 <= i < this.size().
remove(i) {
this.b[i] = this.b[this.sz - 1];
this.sz -= 1;
}
// = "x came before y"
static cameBefore(x, y) {
return Semester.less(x.firstSemester(), y.firstSemester());
}
// = x left before y
static leftBefore(x, y) {
return Semester.less(x.lastSemester(), y.lastSemester());
}
// sort0,sort1,sort2:= sortChoice,sort0,sort1, where sortChoice is
// one of the values CSCanvas.BYNAME--CSCanvas.BYTITLE.
// Then sort this array based on sort0, sort1, sort2
sort(sortChoice) {
DynArray.sort2 = DynArray.sort1;
DynArray.sort1 = DynArray.sort0;
DynArray.sort0 = sortChoice;
this.quickSort();
}
// = a copy of the array
copy() {
let c = new DynArray();
for (let i = 0; i < this.sz; i++) {
c.add(this.b[i]);
}
return c;
}
// = the number of faculty in the array whose lastTitle field is tt
numTitle(tt) {
let n = 0;
for (let i = 0; i < this.sz; i++) {
if (this.element(i).lastTitle === tt) {
n += 1;
}
}
return n;
}
// 0 <= h < k-1 < this.size(). Let x some value in this[h..k-1]
// Permute this[h..k-1] and return a value p such that
// this[h..p-1] <= x = p <= this[p+1..k-1]
partition(h, k) {
// Permute this.h, this[(h+k)/2], this[k-1] so that b.h is the median
// (code still to be written)
let q = h + 1;
let p = k - 1;
// invariant: this.h=x, this[h+1..q-1]<=x, and this[p+1..k-1]>=x
while (q <= p) {
if (this.lessTest(q, h)) {
q += 1;
} else if (this.lessTest(h, p)) {
p -= 1;
} else {
this.swap(p, q);
q += 1;
p -= 1;
}
}
if (p + 2 === q) {
p += 1;
}
// Result: this.h=x, this[h+1..p]<=x, this[p+1..k-1]>=x
this.swap(h, p);
return p;
}
// Sort this array, inplace, using Quicksort, where based on globals s0 and s1
quickSort() {
let t = new LinkedList();
// Invariant: The array is sorted if each of the segments
// this[e.x .. e.y-1] are sorted for e an element of t
t.append(new Coordinates(0, this.size()));
while (t.size() !== 0) {
let co = t.remove();
let h = co.x;
let k = co.y;
if (k === h) { // Partition of size 0
// Do nothing
} else if (k - h <= 2) {
if (this.lessTest(k - 1, h)) { // Partition of size 1 or 2
this.swap(k - 1, h);
}
} else { // Partition of size > 2
let j = this.partition(h, k);
// this[h..j-1]<=this.j<=this[j+1..k-1]
// Place the larger of the two segments on t first, then the smaller
if (k - j - 1 > j - h) {
t.prepend(new Coordinates(j + 1, k));
t.prepend(new Coordinates(h, j));
} else {
t.prepend(new Coordinates(h, j));
t.prepend(new Coordinates(j + 1, k));
}
}
}
}
//= b[i]<b[j], where < is defined depending on s:
// 0=name,1=title,2=first sem, 3=last sem, 4=length of stay
less(i, j, s) {
switch (s) {
case BYNAME:
return this.b[i].name.localeCompare(this.b[j].name) < 0;
case BYTITLE:
return this.b[j].lastTitle < this.b[i].lastTitle;
case BYFIRSTSEMESTER:
return DynArray.cameBefore(this.b[i], this.b[j]);
case BYLASTSEMESTER:
return DynArray.leftBefore(this.b[j], this.b[i]);
case BYLENGTH:
return this.b[j].numSemesters() < this.b[i].numSemesters();
default:
return true;
}
}
// = b[i]<b[j], where < is defined depending on sort0, sort1, sort2 (see
// their definition)
lessTest(i, j) {
if (this.less(i, j, DynArray.sort0)) return true;
if (this.less(j, i, DynArray.sort0)) return false;
// b[i] = b[j] on first key
if (this.less(i, j, DynArray.sort1)) return true;
if (this.less(j, i, DynArray.sort1)) return false;
// b[i] = b[j] on second key
return this.less(i, j, DynArray.sort2);
}
}
// Given a string, break it into tokens and return them one at a time.
class Tokenizer {
constructor(str, delimiters) {
this.str = str;
this.index = 0;
this.delimiters = delimiters;
}
hasMoreTokens() {
// Skip delimiters.
while(this.index < this.str.length && this.delimiters.indexOf(this.str[this.index]) !== -1) {
this.index++;
}
return this.index < this.str.length;
}
nextToken() {
if (this.index >= this.str.length) {
return null;
}
// Skip to beg of next token.
while (this.index < this.str.length && this.delimiters.indexOf(this.str[this.index]) !== -1) {
this.index++;
}
let startIndex = this.index;
while (this.index < this.str.length && this.delimiters.indexOf(this.str[this.index]) === -1) {
this.index++;
}
let token = this.str.substring(startIndex, this.index);
if (token.length === 0) {
return null;
}
return token;
}
}
// A tokenizer that reads integers and "words", where a word
// is a sequence of non-whitespace characters.
class GriesTokenizer extends Tokenizer {
// Constructor --tokenize s
constructor(s) {
super(s, "\n\t\r ");
}
// return the next token as an integer
nextIntToken() {
const s = this.nextToken();
if (!this.isDigits(s)) return -1;
return parseInt(s);
}
// = s consists solely of digits 0..9
isDigits(s) {
for (let i = 0; i < s.length; i++) {
if (s.charCodeAt(i) < 48) return false;
if (s.charCodeAt(i) > 57) return false;
}
return true;
}
// return the next word --as explained above.
nextWord() {
const s = this.nextToken();
if (s.charAt(0) !== '"') return s;
// Word begins with ", so parse a real string
s = s.substring(1);
while (s.charAt(s.length - 1) !== '"') {
s = s + " " + this.nextToken();
}
return s.substring(0, s.length - 1);
}
}
// A period of time at a certain title
class TitleTime {
// Constants. All constants will always be in a contiguous range 1.. .
// Don't change ordering of these constants.
static FIELD = 1;
static LECTURER = 2;
static SRLECTURER = 3;
static INSTRUCTOR = 4;
static ASSTPROF = 5;
static ASSOCPROF = 6;
static FULLPROF = 7;
static EMERITUS = 8;
static numTitles = 8; // Number of different titles
// Leave status constants
static NOLEAVE = 1; // Not on leave during the period
static SABBATIC = 2; // On sabbatic during the period
static OTHERLEAVE = 3; // On other leave during the period
// Constructor: a time at title t, status st, beginning in semester s1
// and ending in semester s2. st is one of the constants NOLEAVE, SABBATIC,
// or OTHERLEAVE.
constructor(t, s1, s2, st = TitleTime.NOLEAVE) {
this.firstSemester = s1;
this.lastSemester = s2;
this.title = t; // One of the constants LECTURER--FIELD
this.status = st; // NOLEAVE, SABBATIC, or OTHERLEAVE
}
// a String version of title
static makeTitle(title) {
switch (title) {
case TitleTime.LECTURER: return "Lecturer";
case TitleTime.SRLECTURER: return "Sr. Lecturer";
case TitleTime.INSTRUCTOR: return "Instructor";
case TitleTime.ASSTPROF: return "Assis. Prof.";
case TitleTime.ASSOCPROF: return "Assoc. Prof.";
case TitleTime.FULLPROF: return "Full Prof.";
case TitleTime.EMERITUS: return "Prof. Emeritus";
case TitleTime.FIELD: return "Field Member";
default: return "Error. unknown";
}
}
// Set the leave status to st (one of the three status constants)
setStatus(st) {
this.status = st;
}
// a String version of the title of this TitleTime
makeTitle() {
return TitleTime.makeTitle(this.title);
}
// A String version of the status during this period
makeStatus() {
switch (this.status) {
case TitleTime.NOLEAVE: return "noleave";
case TitleTime.SABBATIC: return "sabbatic";
case TitleTime.OTHERLEAVE: return "leave";
default: return "Error: status " + this.status + " unknown";
}
}
// A String version of this TitleTime
toString() {
return `${this.makeTitle()} ${this.makeStatus()} ${this.firstSemester}--${this.lastSemester}`;
}
// = the Color for this title
titleColor() {
switch (this.title) {
case TitleTime.LECTURER: return rgb(52,236,2);
case TitleTime.SRLECTURER: return rgb(2,140,12);
case TitleTime.INSTRUCTOR: return rgb(56,50,247);
case TitleTime.ASSTPROF: return rgb(250,173,110);
case TitleTime.ASSOCPROF: return rgb(250,44,28);
case TitleTime.FULLPROF: return rgb(149,14,4);
case TitleTime.EMERITUS: return rgb(89,89,89);
case TitleTime.FIELD: return rgb(104,217,249);
default: return rgb(0,0,0);
}
}
// = the Color for title t (one of the above constants)
static titleColor(t) {
let temp = new TitleTime(t, null, null);
return temp.titleColor();
}
}
// Record of a faculty member:
// name and a list of time periods with titles.
// These must be in chronological order and must not overlap.
class Faculty {
// Constructor --a faculty member with name name, title t, leave-status st,
// first semester s1, and last Semester s2.). s1,s2 are Semester
// objects; t is one of the size constants of class TitleTime.
constructor(name, t, st, s1, s2) {
this.name = name;
// A linked list of periods of the faculty member. There
// is more than one element either because the member was in service at
// noncontiguous periods or because their title changed. Elements of
// the linked list are of type TitleTime.
this.periods = new LinkedList();
if (st !== null) {
this.periods.append(new TitleTime(t, s1, s2, st));
} else {
this.periods.append(new TitleTime(t, s1, s2));
}
// The last title for this faculty member in the
// range associated with the array in which it appears
this.lastTitle = t;
}
// Add a new period for this person --title t, status st, first semester s1, and
// second semester s2
addPeriod(t, st, s1, s2) {
this.periods.append(new TitleTime(t, s1, s2, st));
this.lastTitle = t;
}
// = String version of this faculty member
toString() {
var res= this.name;
let iter= new LinkedListIterator(this.periods);
while (iter.okay()) {
let tt= iter.data();
res= res + " " + tt.toString();
iter.next();
}
return res;
}
// First semester for this faculty member
firstSemester() {
return this.periods.inspect().firstSemester;
}
// Last semester for this faculty member
lastSemester() {
return this.periods.inspectLast().lastSemester;
}
// = Number of semesters at Cornell (Does not count non-sabbatical leaves)
numSemesters() {
var num = 0;
var iter = new LinkedListIterator(this.periods);
while (iter.okay()) {
var tt = iter.data();
if (tt.status !== TitleTime.OTHERLEAVE)
num = num + Semester.difference(tt.firstSemester, tt.lastSemester) + 1;
iter.next();
}
return num;
};
// = the last title for the faculty member that within the bounds of the currently
// displayed years
// Precondition: at least one semester of the faculty member is within the bounds
lastTitle() {
let ans = 0;
let iter = this.periods[Symbol.iterator]();
let result;
// Invariant and is the last title within bounds for the elements of periods
// looked at thus far (0 if none)
while (!(result = iter.next()).done) {
let tt = result.value;
if (CSCanvas.isWithin(tt)) {
ans = tt.title;
}
}
return ans;
}
}