ExistsMatchExpression.js 1.6 KB

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