| @@ 263-283 (lines=21) @@ | ||
| 260 | * @throws \AppserverIo\Collections\InvalidKeyException Is thrown if the passed key is NOT an object |
|
| 261 | * @throws \AppserverIo\Collections\IndexOutOfBoundsException Is thrown if no element with the passed key exists in the Dictionary |
|
| 262 | */ |
|
| 263 | public function remove($key) |
|
| 264 | { |
|
| 265 | if (is_null($key)) { |
|
| 266 | throw new NullPointerException('Passed key is null'); |
|
| 267 | } |
|
| 268 | if (!is_object($key)) { |
|
| 269 | throw new InvalidKeyException('Passed key has to be an object'); |
|
| 270 | } |
|
| 271 | // run over all keys and check if one is equal to the passed one |
|
| 272 | foreach ($this->keys as $id => $value) { |
|
| 273 | // if the actual is equal to the passed key .. |
|
| 274 | if ($key == $value) { |
|
| 275 | // unset the elements |
|
| 276 | unset($this->items[$id]); |
|
| 277 | unset($this->keys[$id]); |
|
| 278 | return; |
|
| 279 | } |
|
| 280 | } |
|
| 281 | // throw an exception if key is not found in internal array |
|
| 282 | throw new IndexOutOfBoundsException('Index out of bounds'); |
|
| 283 | } |
|
| 284 | ||
| 285 | /** |
|
| 286 | * This method appends all elements of the |
|
| @@ 52-72 (lines=21) @@ | ||
| 49 | * @throws \AppserverIo\Lang\NullPointerException Is thrown if the passed key OR value are NULL |
|
| 50 | * @throws \AppserverIo\Collections\IndexOutOfBoundsException Is thrown if no element with the passed key exists in the Dictionary |
|
| 51 | */ |
|
| 52 | public function get($key) |
|
| 53 | { |
|
| 54 | if (is_null($key)) { |
|
| 55 | throw new NullPointerException('Passed key is null'); |
|
| 56 | } |
|
| 57 | if (!is_object($key)) { |
|
| 58 | throw new InvalidKeyException('Passed key has to be an object'); |
|
| 59 | } |
|
| 60 | // run over all keys and check if one is equal to the passed one |
|
| 61 | foreach ($this->keys as $id => $value) { |
|
| 62 | // if the actual is equal to the passed key .. |
|
| 63 | if ($key === $value) { |
|
| 64 | // return the item with the passed key |
|
| 65 | if (array_key_exists($id, $this->items)) { |
|
| 66 | return $this->items[$id]; |
|
| 67 | } |
|
| 68 | } |
|
| 69 | } |
|
| 70 | // if no value is found throw an exception |
|
| 71 | throw new IndexOutOfBoundsException('Index out of bounds'); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * This method checks if the element that has the passed |
|
| @@ 117-137 (lines=21) @@ | ||
| 114 | * @throws \AppserverIo\Lang\NullPointerException Is thrown if the passed key is NULL |
|
| 115 | * @throws \AppserverIo\Collections\IndexOutOfBoundsException Is thrown if no element with the passed key exists in the Dictionary |
|
| 116 | */ |
|
| 117 | public function remove($key) |
|
| 118 | { |
|
| 119 | if (is_null($key)) { |
|
| 120 | throw new NullPointerException('Passed key is null'); |
|
| 121 | } |
|
| 122 | if (! is_object($key)) { |
|
| 123 | throw new InvalidKeyException('Passed key has to be an object'); |
|
| 124 | } |
|
| 125 | // run over all keys and check if one is a reference of the passed one |
|
| 126 | foreach ($this->keys as $id => $value) { |
|
| 127 | // if the actual is equal to the passed key .. |
|
| 128 | if ($key === $value) { |
|
| 129 | // unset the elements |
|
| 130 | unset($this->items[$id]); |
|
| 131 | unset($this->keys[$id]); |
|
| 132 | return; |
|
| 133 | } |
|
| 134 | } |
|
| 135 | // throw an exception if key is not found in internal array |
|
| 136 | throw new IndexOutOfBoundsException('Index out of bounds'); |
|
| 137 | } |
|
| 138 | } |
|
| 139 | ||