node.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Generic immutable node object to be used in collections.
  16. *
  17. */
  18. goog.provide('goog.structs.Node');
  19. /**
  20. * A generic immutable node. This can be used in various collections that
  21. * require a node object for its item (such as a heap).
  22. * @param {K} key Key.
  23. * @param {V} value Value.
  24. * @constructor
  25. * @template K, V
  26. */
  27. goog.structs.Node = function(key, value) {
  28. /**
  29. * The key.
  30. * @private {K}
  31. */
  32. this.key_ = key;
  33. /**
  34. * The value.
  35. * @private {V}
  36. */
  37. this.value_ = value;
  38. };
  39. /**
  40. * Gets the key.
  41. * @return {K} The key.
  42. */
  43. goog.structs.Node.prototype.getKey = function() {
  44. return this.key_;
  45. };
  46. /**
  47. * Gets the value.
  48. * @return {V} The value.
  49. */
  50. goog.structs.Node.prototype.getValue = function() {
  51. return this.value_;
  52. };
  53. /**
  54. * Clones a node and returns a new node.
  55. * @return {!goog.structs.Node<K, V>} A new goog.structs.Node with the same
  56. * key value pair.
  57. */
  58. goog.structs.Node.prototype.clone = function() {
  59. return new goog.structs.Node(this.key_, this.value_);
  60. };