ExistsMatchExpression.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression');
  3. // File: expression_leaf.cpp
  4. var ExistsMatchExpression = module.exports = function ExistsMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'EXISTS';
  7. }, klass = ExistsMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. /**
  9. *
  10. * Writes a debug string for this object
  11. * @method debugString
  12. * @param level
  13. *
  14. */
  15. proto.debugString = function debugString(level) {
  16. return this._debugAddSpace( level ) + this.path() + " exists" + (this.getTag() ? " " + this.getTag().debugString() : "") + "\n";
  17. };
  18. /**
  19. *
  20. * checks if this expression is == to the other
  21. * @method equivalent
  22. * @param other
  23. *
  24. */
  25. proto.equivalent = function equivalent(other) {
  26. if(this._matchType !== other._matchType) {
  27. return false;
  28. }
  29. return this.path() == other.path();
  30. };
  31. /**
  32. *
  33. * Initialize the necessary items
  34. * @method init
  35. * @param path
  36. * @param type
  37. *
  38. */
  39. proto.init = function init(path) {
  40. return this.initPath( path );
  41. };
  42. /**
  43. *
  44. * Check if the input element matches
  45. * @method matchesSingleElement
  46. * @param e
  47. *
  48. */
  49. proto.matchesSingleElement = function matchesSingleElement(e) {
  50. if(typeof(e) === 'undefined')
  51. return false;
  52. if(e === null)
  53. return true;
  54. if(typeof(e) === 'object')
  55. return (Object.keys(e).length > 0);
  56. else
  57. return true;
  58. };
  59. /**
  60. *
  61. * clone this instance to a new one
  62. * @method shallowClone
  63. *
  64. */
  65. proto.shallowClone = function shallowClone(){
  66. var e = new ExistsMatchExpression();
  67. e.init(this.path());
  68. if (this.getTag())
  69. e.setTag(this.getTag().clone());
  70. return e;
  71. };