UNPKG

bugcore

Version:

bugcore is a JavaScript library that provides a foundational architecture for object oriented JS

129 lines (96 loc) 3.57 kB
/* * Copyright (c) 2016 airbug Inc. http://airbug.com * * bugcore may be freely distributed under the MIT license. */ //------------------------------------------------------------------------------- // Annotations //------------------------------------------------------------------------------- //@Export('WeightedListNode') //@Require('Class') //@Require('Obj') //------------------------------------------------------------------------------- // Context //------------------------------------------------------------------------------- require('bugpack').context("*", function(bugpack) { //------------------------------------------------------------------------------- // BugPack //------------------------------------------------------------------------------- var Class = bugpack.require('Class'); var Obj = bugpack.require('Obj'); //------------------------------------------------------------------------------- // Declare Class //------------------------------------------------------------------------------- /** * @class * @extends {Obj} */ var WeightedListNode = Class.extend(Obj, { _name: "WeightedListNode", //------------------------------------------------------------------------------- // Constructor //------------------------------------------------------------------------------- /** * @constructs * @param {*} value * @param {number} weight */ _constructor: function(value, weight) { this._super(); //------------------------------------------------------------------------------- // Private Properties //------------------------------------------------------------------------------- /** * @private * @type {*} */ this.value = value; /** * @private * @type {number} */ this.weight = weight; }, //------------------------------------------------------------------------------- // Getters and Setters //------------------------------------------------------------------------------- /** * @return {*} */ getValue: function() { return this.value; }, /** * @return {number} */ getWeight: function() { return this.weight; }, //------------------------------------------------------------------------------- // Obj Methods //------------------------------------------------------------------------------- /** * @param {*} value * @return {boolean} */ equals: function(value) { if (Class.doesExtend(value, WeightedListNode)) { return Obj.equals(value.getValue(), this.value); } return false; }, /** * @return {number} */ hashCode: function() { if (!this._hashCode) { this._hashCode = Obj.hashCode("[WeightedListNode]" + Obj.hashCode(this.value)); } return this._hashCode; } }); //------------------------------------------------------------------------------- // Exports //------------------------------------------------------------------------------- bugpack.export('WeightedListNode', WeightedListNode); });