2727
2828use doganoo \PHPAlgorithms \Common \Interfaces \Comparable ;
2929use doganoo \PHPAlgorithms \Common \Interfaces \INode ;
30- use doganoo \PHPAlgorithms \Common \Util \Comparator ;
3130use doganoo \PHPAlgorithms \Datastructure \Lists \ArrayLists \ArrayList ;
3231
3332/**
3635 * @package doganoo\PHPAlgorithms\Graph
3736 */
3837class Node implements Comparable, INode {
38+ /** @var mixed $value */
3939 private $ value ;
40+ /** @var ArrayList|null $adjacent */
4041 private $ adjacent = null ;
42+ /** @var int $inbound */
43+ private $ inbound = 0 ;
4144
45+
46+ /**
47+ * Node constructor.
48+ *
49+ * @param $value
50+ */
4251 public function __construct ($ value ) {
4352 $ this ->value = $ value ;
4453 $ this ->adjacent = new ArrayList ();
54+ $ this ->inbound = 0 ;
4555 }
4656
57+ /**
58+ * @param Node $node
59+ * @return bool
60+ */
4761 public function addAdjacent (Node $ node ): bool {
4862 return $ this ->adjacent ->add ($ node );
4963 }
5064
65+ /**
66+ * @return void
67+ */
68+ public function incrementInbound (): void {
69+ $ this ->inbound ++;
70+ }
71+
72+ /**
73+ * @return void
74+ */
75+ public function decrementInbound (): void {
76+ $ this ->inbound --;
77+ }
78+
79+ /**
80+ * @param Node $node
81+ * @return bool
82+ */
5183 public function hasAdjacent (Node $ node ) {
5284 /**
5385 * @var $key
@@ -61,16 +93,19 @@ public function hasAdjacent(Node $node) {
6193 return false ;
6294 }
6395
96+ /**
97+ * @return mixed
98+ */
6499 public function getValue () {
65100 return $ this ->value ;
66101 }
67102
103+ /**
104+ * @param Node $node
105+ * @return bool
106+ */
68107 public function equals (Node $ node ): bool {
69- return Comparator::equals ($ this ->value , $ node ->getValue ());
70- }
71-
72- public function getAdjacents (): ?ArrayList {
73- return $ this ->adjacent ;
108+ return $ this ->compareTo ($ node ) === 0 ;
74109 }
75110
76111 /**
@@ -92,4 +127,18 @@ public function compareTo($object): int {
92127 }
93128 return -1 ;
94129 }
130+
131+ /**
132+ * @return ArrayList|null
133+ */
134+ public function getAdjacents (): ?ArrayList {
135+ return $ this ->adjacent ;
136+ }
137+
138+ /**
139+ * @return int
140+ */
141+ public function countInbound (): int {
142+ return $ this ->inbound ;
143+ }
95144}
0 commit comments