-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capacity.php
52 lines (45 loc) · 982 Bytes
/
Capacity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace ziguss\petrinet;
/**
* Capacity Function.
*
* @author ziguss <yudoujia@163.com>
*/
class Capacity
{
protected $places;
public function __construct()
{
$this->places = new \SplObjectStorage();
}
/**
* @param Place $place
*
* @return int
*/
public function getCapacity(Place $place)
{
if ($this->places->contains($place)) {
return $this->places[$place];
} else {
return PHP_INT_MAX;
}
}
/**
* @param Place $place
* @param int $capacity
*
* @return $this
*/
public function setCapacity(Place $place, $capacity)
{
$capacity = (int) $capacity;
if ($capacity <= 0) {
throw new \InvalidArgumentException('The capacity must be a positive integer.');
}
if ($capacity !== PHP_INT_MAX) {
$this->places[$place] = $capacity;
}
return $this;
}
}