API Docs for:
Show:

File: model\Path.js

  1. /*
  2. * BGPlay.js #9660
  3. * A web-based service for the visualization of the Internet routing
  4. *
  5. * Copyright (c) 2012 Roma Tre University and RIPE NCC
  6. *
  7. * See the file LICENSE.txt for copying permission.
  8. */
  9.  
  10. /**
  11. * A path is an ordered set of nodes.
  12. * @class Path
  13. * @module model
  14. */
  15. var Path=Backbone.Model.extend({
  16.  
  17. /**
  18. * The initialization method of this object.
  19. * @method initialize
  20. * @param {Map} A map of parameters
  21. */
  22. initialize:function(){
  23. this.fastSearchNodes={};
  24. this.attributes.nodes=new Array();
  25. },
  26.  
  27. /**
  28. * Adds a node to this path.
  29. * @method addNode
  30. * @param {Object} An instance of Node
  31. */
  32. addNode:function(node){
  33. this.get("nodes").push(node);
  34. },
  35.  
  36. /**
  37. * Checks if this path contains a given node.
  38. * @method contains
  39. * @param {Object} An instance of Node
  40. * @return {Boolean} True if the path contains the given node.
  41. */
  42. contains:function(element){
  43. //check execution time here:
  44. // http://jsperf.com/indexof-vs-loop/2
  45. // http://jsperf.com/various-loop
  46.  
  47. var nodes=this.attributes.nodes;
  48. var length=nodes.length;
  49. for (var i=length;i--;){
  50. if (nodes[i].id==element.id)
  51. return true;
  52. }
  53. return false;
  54. },
  55.  
  56. /**
  57. * The validation method of this object.
  58. * This method is used to check the initialization parameters.
  59. * @method validate
  60. * @param {Map} A map of parameters
  61. * @return {Array} An array of {String} errors
  62. */
  63. validate:function(attrs){
  64. var err=new Array();
  65.  
  66. if (err.length>0)
  67. return err;
  68. },
  69.  
  70. /**
  71. * Returns a string representing this object.
  72. * @method toString
  73. * @return {String} A string representing this object
  74. */
  75. toString:function(){
  76. var out="";
  77. var nodes=this.attributes.nodes;
  78. if (nodes.length>0){
  79. for (var n=0;n<nodes.length-1;n++){
  80. out+=nodes[n].get("id")+", ";
  81. }
  82. out+=nodes[nodes.length-1].get("id");
  83. }
  84. return out;
  85. }
  86. });
  87.  
  88.