_hiddenSource_ class QueryArray { // ----------------------------------------------------- //Instance Variables (Ivars) //this.elements -- a fixed array holding the elements // ----------------------------------------------------- //Constructors /** Static factory methods that returns new QueryArray using the passed fixed array "array" */ static from(array) { //Call traditional constructor return new this(array); } /** Traditional constructor -- set ivar elements to passed array */ constructor(array) { this.elements = array; } // ----------------------------------------------------- //Instance Methods /** Returns nice display string */ toString() { return this.elements.toString(); } forEach(actionFct) { for (let nextElem of this.elements) actionFct(nextElem); } /** Prints all elements to console (with newline after each */ printAll(listLabel) { println(listLabel); this.forEach(nextElem => println(nextElem.toString())); } } //Try It //fixed array and query array var farray, qarray; //Example data (list of cities) farray = City.newSampleSet1(); //Construct QueryArray qarray = QueryArray.from(farray ); //Print It qarray.printAll(); _hiddenSource_ _br_ _br_forEach(actionFct) { for (let nextElem of this.elements) actionFct(nextElem); } /** Prints all elements to console (with newline after each */ printAll(listLabel) { println(listLabel); this.forEach(nextElem => println(nextElem.toString())); }