GraphComponent.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. export default class GraphComponent {
  2. constructor() {
  3. GraphComponent.constructor_.apply(this, arguments)
  4. }
  5. static constructor_() {
  6. this._isMarked = false
  7. this._isVisited = false
  8. this._data = null
  9. }
  10. static getComponentWithVisitedState(i, visitedState) {
  11. while (i.hasNext()) {
  12. const comp = i.next()
  13. if (comp.isVisited() === visitedState) return comp
  14. }
  15. return null
  16. }
  17. static setVisited(i, visited) {
  18. while (i.hasNext()) {
  19. const comp = i.next()
  20. comp.setVisited(visited)
  21. }
  22. }
  23. static setMarked(i, marked) {
  24. while (i.hasNext()) {
  25. const comp = i.next()
  26. comp.setMarked(marked)
  27. }
  28. }
  29. setVisited(isVisited) {
  30. this._isVisited = isVisited
  31. }
  32. isMarked() {
  33. return this._isMarked
  34. }
  35. setData(data) {
  36. this._data = data
  37. }
  38. getData() {
  39. return this._data
  40. }
  41. setMarked(isMarked) {
  42. this._isMarked = isMarked
  43. }
  44. getContext() {
  45. return this._data
  46. }
  47. isVisited() {
  48. return this._isVisited
  49. }
  50. setContext(data) {
  51. this._data = data
  52. }
  53. }