PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/elevatorphp/class/Floor.php

http://umple.googlecode.com/
PHP | 410 lines | 344 code | 48 blank | 18 comment | 74 complexity | 64b285f30c164d3ad233a52aa38e2647 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /*PLEASE DO NOT EDIT THIS CODE*/
  3. /*This code was generated using the UMPLE 1.12.0.352 modeling language!*/
  4. class Floor
  5. {
  6. //------------------------
  7. // STATIC VARIABLES
  8. //------------------------
  9. private static $nextNumber = 1;
  10. //------------------------
  11. // MEMBER VARIABLES
  12. //------------------------
  13. //Autounique Attributes
  14. private $number;
  15. //Floor Associations
  16. private $waitingPersons;
  17. private $elevatorOnThisFloor;
  18. public $upRequest; //until PHP 5.3 (setAccessible)
  19. public $downRequest; //until PHP 5.3 (setAccessible)
  20. private $building;
  21. private $onItsWayTo;
  22. private $exitAtPersons;
  23. //------------------------
  24. // CONSTRUCTOR
  25. //------------------------
  26. public function __construct($aBuilding)
  27. {
  28. $this->number = self::$nextNumber++;
  29. $this->waitingPersons = array();
  30. $didAddBuilding = $this->setBuilding($aBuilding);
  31. if (!$didAddBuilding)
  32. {
  33. throw new Exception("Unable to create floor due to building");
  34. }
  35. $this->exitAtPersons = array();
  36. }
  37. //------------------------
  38. // INTERFACE
  39. //------------------------
  40. public function getNumber()
  41. {
  42. return $this->number;
  43. }
  44. public function getWaitingPerson($index)
  45. {
  46. $aWaitingPerson = $this->waitingPersons[$index];
  47. return $aWaitingPerson;
  48. }
  49. public function getWaitingPersons()
  50. {
  51. $newWaitingPersons = $this->waitingPersons;
  52. return $newWaitingPersons;
  53. }
  54. public function numberOfWaitingPersons()
  55. {
  56. $number = count($this->waitingPersons);
  57. return $number;
  58. }
  59. public function hasWaitingPersons()
  60. {
  61. $has = $this->numberOfWaitingPersons() > 0;
  62. return $has;
  63. }
  64. public function indexOfWaitingPerson($aWaitingPerson)
  65. {
  66. $wasFound = false;
  67. $index = 0;
  68. foreach($this->waitingPersons as $waitingPerson)
  69. {
  70. if ($waitingPerson->equals($aWaitingPerson))
  71. {
  72. $wasFound = true;
  73. break;
  74. }
  75. $index += 1;
  76. }
  77. $index = $wasFound ? $index : -1;
  78. return $index;
  79. }
  80. public function getElevatorOnThisFloor()
  81. {
  82. return $this->elevatorOnThisFloor;
  83. }
  84. public function getUpRequest()
  85. {
  86. return $this->upRequest;
  87. }
  88. public function getDownRequest()
  89. {
  90. return $this->downRequest;
  91. }
  92. public function getBuilding()
  93. {
  94. return $this->building;
  95. }
  96. public function getOnItsWayTo()
  97. {
  98. return $this->onItsWayTo;
  99. }
  100. public function getExitAtPerson($index)
  101. {
  102. $aExitAtPerson = $this->exitAtPersons[$index];
  103. return $aExitAtPerson;
  104. }
  105. public function getExitAtPersons()
  106. {
  107. $newExitAtPersons = $this->exitAtPersons;
  108. return $newExitAtPersons;
  109. }
  110. public function numberOfExitAtPersons()
  111. {
  112. $number = count($this->exitAtPersons);
  113. return $number;
  114. }
  115. public function hasExitAtPersons()
  116. {
  117. $has = $this->numberOfExitAtPersons() > 0;
  118. return $has;
  119. }
  120. public function indexOfExitAtPerson($aExitAtPerson)
  121. {
  122. $wasFound = false;
  123. $index = 0;
  124. foreach($this->exitAtPersons as $exitAtPerson)
  125. {
  126. if ($exitAtPerson->equals($aExitAtPerson))
  127. {
  128. $wasFound = true;
  129. break;
  130. }
  131. $index += 1;
  132. }
  133. $index = $wasFound ? $index : -1;
  134. return $index;
  135. }
  136. public static function minimumNumberOfWaitingPersons()
  137. {
  138. return 0;
  139. }
  140. public function addWaitingPerson($aWaitingPerson)
  141. {
  142. $wasAdded = false;
  143. if ($this->indexOfWaitingPerson($aWaitingPerson) !== -1) { return false; }
  144. $existingFloor = $aWaitingPerson->getFloor();
  145. if ($existingFloor == null)
  146. {
  147. $aWaitingPerson->setFloor($this);
  148. }
  149. elseif ($this !== $existingFloor)
  150. {
  151. $existingFloor->removeWaitingPerson($aWaitingPerson);
  152. $this->addWaitingPerson($aWaitingPerson);
  153. }
  154. else
  155. {
  156. $this->waitingPersons[] = $aWaitingPerson;
  157. }
  158. $wasAdded = true;
  159. return $wasAdded;
  160. }
  161. public function removeWaitingPerson($aWaitingPerson)
  162. {
  163. $wasRemoved = false;
  164. if ($this->indexOfWaitingPerson($aWaitingPerson) != -1)
  165. {
  166. unset($this->waitingPersons[$this->indexOfWaitingPerson($aWaitingPerson)]);
  167. $this->waitingPersons = array_values($this->waitingPersons);
  168. if ($this === $aWaitingPerson->getFloor())
  169. {
  170. $aWaitingPerson->setFloor(null);
  171. }
  172. $wasRemoved = true;
  173. }
  174. return $wasRemoved;
  175. }
  176. public function setElevatorOnThisFloor($newElevatorOnThisFloor)
  177. {
  178. $wasSet = false;
  179. if ($newElevatorOnThisFloor == null)
  180. {
  181. $existingElevatorOnThisFloor = $this->elevatorOnThisFloor;
  182. $this->elevatorOnThisFloor = null;
  183. if ($existingElevatorOnThisFloor != null && $existingElevatorOnThisFloor->getFloor() != null)
  184. {
  185. $existingElevatorOnThisFloor->setFloor(null);
  186. }
  187. $wasSet = true;
  188. return $wasSet;
  189. }
  190. $currentElevatorOnThisFloor = $this->getElevatorOnThisFloor();
  191. if ($currentElevatorOnThisFloor != null && $currentElevatorOnThisFloor != $newElevatorOnThisFloor)
  192. {
  193. $currentElevatorOnThisFloor->setFloor(null);
  194. }
  195. $this->elevatorOnThisFloor = $newElevatorOnThisFloor;
  196. $existingFloor = $newElevatorOnThisFloor->getFloor();
  197. if ($this != $existingFloor)
  198. {
  199. $newElevatorOnThisFloor->setFloor($this);
  200. }
  201. $wasSet = true;
  202. return $wasSet;
  203. }
  204. public function setUpRequest($newUpRequest)
  205. {
  206. $wasSet = false;
  207. if ($this->upRequest != null && $this->upRequest != $newUpRequest && $this == $this->upRequest->getFloor())
  208. {
  209. //Unable to setUpRequest, as existing upRequest would become an orphan
  210. return $wasSet;
  211. }
  212. $this->upRequest = $newUpRequest;
  213. $oldFloor = $newUpRequest != null ? $newUpRequest->getFloor() : null;
  214. if ($this != $oldFloor)
  215. {
  216. if ($oldFloor != null)
  217. {
  218. $oldFloor->upRequest = null;
  219. }
  220. if ($this->upRequest != null)
  221. {
  222. $this->upRequest->setFloor($this);
  223. }
  224. }
  225. $wasSet = true;
  226. return $wasSet;
  227. }
  228. public function setDownRequest($newDownRequest)
  229. {
  230. $wasSet = false;
  231. if ($this->downRequest != null && $this->downRequest != $newDownRequest && $this == $this->downRequest->getFloor())
  232. {
  233. //Unable to setDownRequest, as existing downRequest would become an orphan
  234. return $wasSet;
  235. }
  236. $this->downRequest = $newDownRequest;
  237. $oldFloor = $newDownRequest != null ? $newDownRequest->getFloor() : null;
  238. if ($this != $oldFloor)
  239. {
  240. if ($oldFloor != null)
  241. {
  242. $oldFloor->downRequest = null;
  243. }
  244. if ($this->downRequest != null)
  245. {
  246. $this->downRequest->setFloor($this);
  247. }
  248. }
  249. $wasSet = true;
  250. return $wasSet;
  251. }
  252. public function setBuilding($aBuilding)
  253. {
  254. $wasSet = false;
  255. if ($aBuilding == null)
  256. {
  257. return $wasSet;
  258. }
  259. $existingBuilding = $this->building;
  260. $this->building = $aBuilding;
  261. if ($existingBuilding != null && $existingBuilding != $aBuilding)
  262. {
  263. $existingBuilding->removeFloor($this);
  264. }
  265. $this->building->addFloor($this);
  266. $wasSet = true;
  267. return $wasSet;
  268. }
  269. public function setOnItsWayTo($aOnItsWayTo)
  270. {
  271. $wasSet = false;
  272. $existingOnItsWayTo = $this->onItsWayTo;
  273. $this->onItsWayTo = $aOnItsWayTo;
  274. if ($existingOnItsWayTo != null && $existingOnItsWayTo !== $aOnItsWayTo)
  275. {
  276. $existingOnItsWayTo->removeRequestedFloor($this);
  277. }
  278. if ($aOnItsWayTo != null && $aOnItsWayTo !== $existingOnItsWayTo)
  279. {
  280. $aOnItsWayTo->addRequestedFloor($this);
  281. }
  282. $wasSet = true;
  283. return $wasSet;
  284. }
  285. public static function minimumNumberOfExitAtPersons()
  286. {
  287. return 0;
  288. }
  289. public function addExitAtPerson($aExitAtPerson)
  290. {
  291. $wasAdded = false;
  292. if ($this->indexOfExitAtPerson($aExitAtPerson) !== -1) { return false; }
  293. $existingDesiredFloor = $aExitAtPerson->getDesiredFloor();
  294. if ($existingDesiredFloor == null)
  295. {
  296. $aExitAtPerson->setDesiredFloor($this);
  297. }
  298. elseif ($this !== $existingDesiredFloor)
  299. {
  300. $existingDesiredFloor->removeExitAtPerson($aExitAtPerson);
  301. $this->addExitAtPerson($aExitAtPerson);
  302. }
  303. else
  304. {
  305. $this->exitAtPersons[] = $aExitAtPerson;
  306. }
  307. $wasAdded = true;
  308. return $wasAdded;
  309. }
  310. public function removeExitAtPerson($aExitAtPerson)
  311. {
  312. $wasRemoved = false;
  313. if ($this->indexOfExitAtPerson($aExitAtPerson) != -1)
  314. {
  315. unset($this->exitAtPersons[$this->indexOfExitAtPerson($aExitAtPerson)]);
  316. $this->exitAtPersons = array_values($this->exitAtPersons);
  317. if ($this === $aExitAtPerson->getDesiredFloor())
  318. {
  319. $aExitAtPerson->setDesiredFloor(null);
  320. }
  321. $wasRemoved = true;
  322. }
  323. return $wasRemoved;
  324. }
  325. public function equals($compareTo)
  326. {
  327. return $this == $compareTo;
  328. }
  329. public function delete()
  330. {
  331. foreach ($this->waitingPersons as $aWaitingPerson)
  332. {
  333. $aWaitingPerson->setFloor(null);
  334. }
  335. if ($this->elevatorOnThisFloor != null)
  336. {
  337. $this->elevatorOnThisFloor->setFloor(null);
  338. }
  339. $existingUpRequest = $this->upRequest;
  340. $this->upRequest = null;
  341. if ($existingUpRequest != null)
  342. {
  343. $existingUpRequest->delete();
  344. }
  345. $existingDownRequest = $this->downRequest;
  346. $this->downRequest = null;
  347. if ($existingDownRequest != null)
  348. {
  349. $existingDownRequest->delete();
  350. }
  351. $this->building->removeFloor($this);
  352. if ($this->onItsWayTo != null)
  353. {
  354. $this->onItsWayTo->removeRequestedFloor($this);
  355. }
  356. foreach ($this->exitAtPersons as $aExitAtPerson)
  357. {
  358. $aExitAtPerson->setDesiredFloor(null);
  359. }
  360. }
  361. }
  362. ?>