| @@ 5-55 (lines=51) @@ | ||
| 2 | ||
| 3 | namespace Jobles\Core\Job; |
|
| 4 | ||
| 5 | class JobCollection implements \IteratorAggregate, \Countable |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var array |
|
| 9 | */ |
|
| 10 | private $jobs = []; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var int |
|
| 14 | */ |
|
| 15 | private $size = 0; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param Job $job |
|
| 19 | */ |
|
| 20 | public function addJob(Job $job) |
|
| 21 | { |
|
| 22 | $this->jobs[] = $job; |
|
| 23 | $this->size++; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param $position |
|
| 28 | * @return Job |
|
| 29 | * @throws \LengthException |
|
| 30 | */ |
|
| 31 | public function pick($position) |
|
| 32 | { |
|
| 33 | if (isset($this->jobs[$position])) { |
|
| 34 | return $this->jobs[$position]; |
|
| 35 | } |
|
| 36 | ||
| 37 | throw new \LengthException('Invalid job position: ' . $position); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @inheritDoc |
|
| 42 | */ |
|
| 43 | public function count() |
|
| 44 | { |
|
| 45 | return $this->size; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @inheritDoc |
|
| 50 | */ |
|
| 51 | public function getIterator() |
|
| 52 | { |
|
| 53 | return new JobIterator($this); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 5-55 (lines=51) @@ | ||
| 2 | ||
| 3 | namespace Jobles\Core\Location; |
|
| 4 | ||
| 5 | class LocationCollection implements \IteratorAggregate, \Countable |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var array |
|
| 9 | */ |
|
| 10 | private $locations = []; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var int |
|
| 14 | */ |
|
| 15 | private $size = 0; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param Location $location |
|
| 19 | */ |
|
| 20 | public function addLocation(Location $location) |
|
| 21 | { |
|
| 22 | $this->locations[] = $location; |
|
| 23 | $this->size++; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param $position |
|
| 28 | * @return LocationInterface |
|
| 29 | * @throws \LengthException |
|
| 30 | */ |
|
| 31 | public function pick($position) |
|
| 32 | { |
|
| 33 | if (isset($this->locations[$position])) { |
|
| 34 | return $this->locations[$position]; |
|
| 35 | } |
|
| 36 | ||
| 37 | throw new \LengthException('Invalid location position: ' . $position); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @inheritDoc |
|
| 42 | */ |
|
| 43 | public function count() |
|
| 44 | { |
|
| 45 | return $this->size; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @inheritDoc |
|
| 50 | */ |
|
| 51 | public function getIterator() |
|
| 52 | { |
|
| 53 | return new LocationIterator($this); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||