NotMatchExpression.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. var ListOfMatchExpression = require("./ListOfMatchExpression"),
  3. ErrorCodes = require("../../Errors").ErrorCodes;
  4. var NotMatchExpression = module.exports = function NotMatchExpression(){
  5. base.call(this);
  6. this._matchType = "NOT";
  7. }, klass = NotMatchExpression, base = ListOfMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); //jshint ignore:line
  8. proto._exp = undefined;
  9. /**
  10. *
  11. * Writes a debug string for this object
  12. * @method debugString
  13. * @param level
  14. *
  15. */
  16. proto.debugString = function debugString(level) {
  17. return this._debugAddSpace(level) +
  18. "$not\n" +
  19. this._exp._debugString(level + 1);
  20. };
  21. /**
  22. *
  23. * checks if this expression is == to the other
  24. * @method equivalent
  25. * @param other
  26. *
  27. */
  28. proto.equivalent = function equivalent(other) {
  29. return other._matchType === "NOT" && this._exp.equivalent(other.getChild(0));
  30. };
  31. /**
  32. *
  33. * Return the reset child
  34. * @method resetChild
  35. *
  36. */
  37. proto.resetChild = function resetChild(newChild) {
  38. this._exp.reset(newChild);
  39. };
  40. /**
  41. *
  42. * Initialize the necessary items
  43. * @method init
  44. * @param exp
  45. *
  46. */
  47. proto.init = function init(exp) {
  48. this._exp = exp;
  49. return {"code":ErrorCodes.OK};
  50. };
  51. /**
  52. *
  53. * matches checks the input doc against the internal element path to see if it is a match
  54. * @method matches
  55. * @param doc
  56. * @param details
  57. *
  58. */
  59. proto.matches = function matches(doc, details) {
  60. return ! this._exp.matches(doc, null);
  61. };
  62. /**
  63. *
  64. * Check if the input element matches
  65. * @method matchesSingleElement
  66. * @param e
  67. *
  68. */
  69. proto.matchesSingleElement = function matchesSingleElement(e) {
  70. return ! this._exp.matchesSingleElement( e );
  71. };
  72. /**
  73. *
  74. * Return the number of children contained by this expression
  75. * @method numChildren
  76. * @param
  77. *
  78. */
  79. proto.numChildren = function numChildren(){
  80. return 1;
  81. };
  82. /**
  83. *
  84. * clone this instance to a new one
  85. * @method shallowClone
  86. *
  87. */
  88. proto.shallowClone = function shallowClone(){
  89. var e = new NotMatchExpression();
  90. e.init(this._exp.shallowClone());
  91. if ( this.getTag() ) {
  92. e.setTag(this.getTag().clone());
  93. }
  94. return e;
  95. };