sql-synergy
Version:
Synergy Wave TA
122 lines (121 loc) • 4.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeL = exports.WaveList = void 0;
class WaveList {
// If the list is empty, the value is null.
get(sWaveName) {
if (sWaveName == null)
console.error("FATAL: WaveList.get sWaveName is NULL");
let runner = this.head;
while (runner != null) {
if (sWaveName === runner.oItem.getName())
return runner.oItem;
runner = runner.next; // Move on to the next node.
}
return null;
}
delete(sWaveName) {
if (this.head == null)
return false;
if (sWaveName === this.head.oItem.getName()) {
this.head = this.head.next;
return true;
}
// The string, if it occurs at all, is somewhere beyond the
// first element of the list. Search the list.
var runner = this.head.next; // Start by looking at the SECOND list node.
var previous = null; // Always points to the node preceding runner.
previous = this.head;
if (runner != null)
console.log(">>> COMPARING ", runner.oItem.toString(), " with ", sWaveName);
while (runner != null && runner.oItem.getName().localeCompare(sWaveName) < 0) {
previous = runner;
runner = runner.next;
}
if (runner != null && sWaveName === runner.oItem.getName()) {
previous.next = runner.next;
return true;
}
return false;
}
insert(oWave) {
this.delete(oWave.getName());
let newNode = new NodeL();
newNode.oItem = oWave; // (N.B. newNode.next is null.)
if (this.head == null) {
this.head = newNode;
}
else if (this.head.oItem.getName().localeCompare(oWave.getName()) >= 0) // NOT TESTED the prototype of compareTo
{
newNode.next = this.head;
this.head = newNode;
}
else {
let runner = this.head.next; // Start by looking at the SECOND position.
let previous = this.head;
// console.log(runner.oItem) ;
while (runner != null && runner.oItem.getName().localeCompare(oWave.getName()) < 0) {
previous = runner;
runner = runner.next;
}
newNode.next = runner; // Insert newNode after previous.
previous.next = newNode;
}
// print ( ) ;
}
printWaves() {
let runner = this.head;
while (runner != null) {
console.log(runner.oItem);
runner = runner.next;
}
}
getWavesString() {
let runner = this.head;
let vElements = new Array();
while (runner != null) {
vElements.push(runner.oItem.getName());
runner = runner.next;
}
return vElements;
}
getWaveList() {
let runner = this.head;
let vElements = new Array();
while (runner != null) {
vElements.push(runner.oItem);
runner = runner.next;
}
//console.error ( "T : " + vElements.size ( ) ) ;
return vElements;
}
getLastWave() {
let oIW = this.getWaveList();
if (oIW.length == 0)
return null;
return oIW[oIW.length - 1];
}
getWaves(sWaveStartName) {
let aWaves = this.getWavesString();
let v = new Array();
let n = aWaves.length;
for (var i = 0; i < n; i++) {
if (aWaves[i].startsWith(sWaveStartName)) {
if (aWaves[i].length == sWaveStartName.length + 1 ||
aWaves[i].length == sWaveStartName.length)
v.push(aWaves[i]);
}
}
return v;
}
print() {
let aS = this.getWavesString();
console.log("All Waves");
for (var i = 0; i < aS.length; i++)
console.log(aS[i]);
}
}
exports.WaveList = WaveList;
class NodeL {
}
exports.NodeL = NodeL;