| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | 
							- "use strict";
 
- var ElemMatchValueMatchExpression = module.exports = function ElemMatchValueMatchExpression(){
 
- 	base.call(this);
 
- 	this._matchType = "ELEM_MATCH_VALUE";
 
- 	this._subs = [];
 
- }, klass = ElemMatchValueMatchExpression, base = require("./ArrayMatchingMatchExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); //jshint ignore:line
 
- var errors = require("../errors"),
 
- 	ErrorCodes = errors.ErrorCodes;
 
- proto._subs = undefined;
 
- /**
 
-  *
 
-  * Check if the input element matches all items in the array
 
-  * @method _arrayElementMatchesAll
 
-  * @param element
 
-  *
 
-  */
 
- proto._arrayElementMatchesAll = function _arrayElementMatchesAll(element){
 
- 	for (var i = 0; i < this._subs.length; i++ ) {
 
- 		if (!this._subs[i].matchesSingleElement(element))
 
- 			return false;
 
- 	}
 
- 	return true;
 
- };
 
- /**
 
-  *
 
-  * push an item onto the internal array
 
-  * @method add
 
-  * @param sub
 
-  *
 
-  */
 
- proto.add = function add(sub){
 
- 	if (!sub) throw new Error(sub + " ElemMatchValueMatchExpression:36");
 
- 	this._subs.push(sub);
 
- };
 
- /**
 
-  *
 
-  * Writes a debug string for this object
 
-  * @method debugString
 
-  * @param level
 
-  *
 
-  */
 
- proto.debugString = function debugString(level){
 
- 	var debug = this._debugAddSpace(level) +
 
- 		this.path() + " $elemMatch (value)" +
 
- 		(this.getTag() ? this.getTag().debugString() : "") +
 
- 		"\n";
 
- 	for (var i = 0; i < this._subs.length; i++) {
 
- 		debug += this._subs[i].debugString(level + 1);
 
- 	}
 
- 	return debug;
 
- };
 
- /**
 
-  *
 
-  * Get the given child in the internal array
 
-  * @method getChild
 
-  * @param i
 
-  *
 
-  */
 
- proto.getChild = function getChild(i){
 
- 	return this._subs[i];
 
- };
 
- /**
 
-  *
 
-  * Initialize the necessary items
 
-  * @method init
 
-  * @param path
 
-  * @param sub
 
-  *
 
-  */
 
- proto.init = function init(path, sub){
 
- 	this.initPath(path);
 
- 	if (sub)
 
- 		this.add(sub);
 
- 	return {code:ErrorCodes.OK};
 
- };
 
- /**
 
-  *
 
-  * Check if one of the items in the input array matches everything in the internal array
 
-  * @method matchesArray
 
-  * @param anArray
 
-  * @param details
 
-  *
 
-  */
 
- proto.matchesArray = function matchesArray(anArray, details){
 
- 	for (var i in anArray) { //jshint ignore:line
 
- 		var inner = anArray[i];
 
- 		if (this._arrayElementMatchesAll(inner)) {
 
- 			if (details && details.needRecord()) {
 
- 				details.setElemMatchKey(i);
 
- 			}
 
- 			return true;
 
- 		}
 
- 	}
 
- 	return false;
 
- };
 
- /**
 
-  *
 
-  * Return the number of items in the internal array
 
-  * @method numChildren
 
-  *
 
-  */
 
- proto.numChildren = function numChildren(){
 
- 	return this._subs.length;
 
- };
 
- /**
 
-  *
 
-  * clone this instance to a new one
 
-  * @method shallowClone
 
-  *
 
-  */
 
- proto.shallowClone = function shallowClone(){
 
- 	var element = new ElemMatchValueMatchExpression();
 
- 	element.init(this.path());
 
- 	for (var i = 0; i < this._subs.length; ++i) {
 
- 		element.add(this._subs[i].shallowClone());
 
- 	}
 
- 	var td = this.getTag();
 
- 	if (td) {
 
- 		element.setTag(td.clone());
 
- 	}
 
- 	return element;
 
- };
 
 
  |