123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import common from './common.js'
- class IndexedCollection {
- constructor() {
- this.list = []
- this.index = {}
- Object.defineProperty(this, 'length', {
- get: function () {
- return this.list.length
- },
- })
- if (typeof this.getIndex != 'function') {
- throw new Error('IndexedCollection.getIndex not implemented in subclass.')
- }
- }
- forEach(e) {
- this.list.forEach(e)
- }
- add(pano) {
- this.list.push(pano)
- this.index[this.getIndex(pano)] = pano
- }
- extend(e) {
- for (var t = 0; t < e.length; t++) this.add(e[t])
- }
- get(panoId) {
- return this.index[panoId]
- }
- first() {
- return this.list[0]
- }
- last() {
- return this.list[this.list.length - 1]
- }
- reIndex() {
- this.index = {}
- var e = this
- this.forEach(function (t) {
- e.index[e.getIndex(t)] = t
- })
- }
- filter(e) {
- var t = this.list.filter(e)
- return this.reIndex(), t
- }
- reduce(e, t) {
- return this.list.reduce(e, t)
- }
- sort(e) {
- return this.list.sort(e)
- }
- indexOf(e) {
- for (var t = 0; t < this.list.length; ++t) if (this.list[t] === e) return t
- return -1
- }
- clone() {
- //xzw add
- var newobj = new this.constructor()
- newobj.extend(this.list)
- return newobj
- }
- }
- export default IndexedCollection
|