1 | <?php |
||
10 | abstract class BasePartitionAlgorithm implements PartitionAlgorithmInterface { |
||
11 | |||
12 | /** |
||
13 | * The original data. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $data; |
||
18 | |||
19 | /** |
||
20 | * A single partition containing the original data in the right format. |
||
21 | * |
||
22 | * @var Partition |
||
23 | */ |
||
24 | protected $dataPartition; |
||
25 | |||
26 | /** |
||
27 | * The partition container. |
||
28 | * |
||
29 | * @var PartitionContainer |
||
30 | */ |
||
31 | protected $partitionContainer; |
||
32 | |||
33 | /** |
||
34 | * The function used to compute the value of an item. |
||
35 | * |
||
36 | * @var callable |
||
37 | */ |
||
38 | protected $itemAccessCallback; |
||
39 | |||
40 | /** |
||
41 | * BasePartitionAlgorithm constructor. |
||
42 | */ |
||
43 | 14 | public function __construct() { |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 14 | public function setData(array $data = array()) { |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 14 | public function getData() { |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 14 | public function setDataPartition(Partition $partition) { |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 14 | public function getDataPartition() { |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 14 | public function generateDataPartition(array $items = array()) { |
|
81 | 14 | $partition = new Partition(); |
|
82 | |||
83 | 14 | $partition->addItems( |
|
84 | 14 | array_map(function ($item) { |
|
85 | 14 | if ($item instanceof PartitionItemInterface) { |
|
86 | 4 | return $item; |
|
87 | } |
||
88 | 14 | return new PartitionItem( |
|
89 | $item, |
||
90 | 14 | $this->getItemAccessCallback() |
|
91 | ); |
||
92 | 14 | }, $items) |
|
93 | ); |
||
94 | |||
95 | 14 | return $partition; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 14 | public function setSize($size) { |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 14 | public function getSize() { |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 4 | public function setItemAccessCallback(callable $callable = NULL) { |
|
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | 14 | public function getItemAccessCallback() { |
|
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | 14 | public function getPartitionContainer() { |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 6 | public function getResult() { |
|
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | 11 | public function getPartitionWeight(Partition $partition) { |
|
149 | |||
150 | } |
||
151 |