1<?php
2
3declare(strict_types=1);
4
5namespace Antlr\Antlr4\Runtime\Utils;
6
7use Antlr\Antlr4\Runtime\Comparison\Equality;
8use Antlr\Antlr4\Runtime\Comparison\Equatable;
9use Antlr\Antlr4\Runtime\Comparison\Hasher;
10
11final class Pair implements Equatable
12{
13    /** @var object|null */
14    public $a;
15
16    /** @var object|null */
17    public $b;
18
19    public function __construct(?object $a, ?object $b)
20    {
21        $this->a = $a;
22        $this->b = $b;
23    }
24
25    public function equals(object $other) : bool
26    {
27        if ($other === $this) {
28            return true;
29        }
30
31        return $other instanceof self
32            && Equality::equals($this->a, $other->a)
33            && Equality::equals($this->b, $other->b);
34    }
35
36    public function hashCode() : int
37    {
38        return Hasher::hash($this->a, $this->b);
39    }
40
41    public function __toString() : string
42    {
43        return \sprintf('%s, %s', (string) $this->a, (string) $this->b);
44    }
45}
46