/** * Copyright© 2016, Oracle and/or its affiliates. All rights reserved. */ /** * Class that represents a collection of MobileObjects returned by a custom code API. * @constructor * @global */ function MobileObjectCollection(endpoint, uri) { MobileResource.call(this, endpoint, uri); this._type = SyncResourceType.item; var _objects = []; this.initialize = function (objects) { for(var idx in objects){ if(objects.hasOwnProperty(idx)){ var object = objects[idx]; // TODO: check if we need load from cache _objects.push(object); } } return this; }; /** * The count of items in the collection * @type {number} * @readonly */ this.getLength = function(){ return _objects.length; }; /** * Return specific object from collection. * @param idx {number} item position in collection. * @return {MobileResource} */ this.getItem = function (idx){ return _objects[idx]; }; /** * Return all objects from collection. * @return {Array<MobileResource>} */ this.all = function (){ return _objects; }; /** * Run method per item * @param method {Function} method to run on item. */ this.forEach = function(method){ _objects.forEach(method); } } MobileObjectCollection.prototype = Object.create(MobileResource.prototype); MobileObjectCollection.prototype.constructor = MobileObjectCollection;