AndMatchExpression.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. var AndMatchExpression = module.exports = function AndMatchExpression(){
  3. base.call(this);
  4. this._expressions = [];
  5. this._matchType = "AND";
  6. }, klass = AndMatchExpression, base = require("./ListOfMatchExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); //jshint ignore:line
  7. /**
  8. *
  9. * Writes a debug string for this object
  10. * @method debugString
  11. * @param level
  12. *
  13. */
  14. proto.debugString = function debugString( level ) { // StringBuilder& debug, int level
  15. // File: expression_tree.cpp lines: 85-88
  16. return this._debugAddSpace(level) + "$and\n" + this._debugList(level);
  17. };
  18. /**
  19. *
  20. * matches checks the input doc against the internal path to see if it is a match
  21. * @method matches
  22. * @param doc
  23. * @param details
  24. *
  25. */
  26. proto.matches = function matches(doc, details) { // const MatchableDocument* doc, MatchDetails* details
  27. // File: expression_tree.cpp lines: 64-72
  28. var tChild;
  29. for (var i = 0; i < this.numChildren(); i++) {
  30. tChild = this.getChild(i);
  31. if (!tChild.matches(doc, details)) {
  32. if (details) {
  33. details.resetOutput();
  34. }
  35. return false;
  36. }
  37. }
  38. return true;
  39. };
  40. /**
  41. *
  42. * Check if the input element matches
  43. * @method matchesSingleElement
  44. * @param e
  45. *
  46. */
  47. proto.matchesSingleElement = function matchesSingleElement( e ){ // const BSONElement& e
  48. // File: expression_tree.cpp lines: 75-81
  49. for (var i = 0; i < this.numChildren(); i++) {
  50. if (!this.getChild(i).matchesSingleElement(e)) {
  51. return false;
  52. }
  53. }
  54. return true;
  55. };
  56. /**
  57. *
  58. * clone this instance to a new one
  59. * @method shallowClone
  60. * @param
  61. *
  62. */
  63. proto.shallowClone = function shallowClone( /* */ ){
  64. // File: expression_tree.h lines: 67-72
  65. var e = new AndMatchExpression();
  66. for (var i = 0; i < this.numChildren(); i++) {
  67. e.add(this.getChild(i).shallowClone());
  68. }
  69. if (this.getTag()) {
  70. e.setTag(this.getTag().clone());
  71. }
  72. return e; // Return the shallow copy.
  73. };