| @@ 50-69 (lines=20) @@ | ||
| 47 | * |
|
| 48 | * @throws \AppserverIo\Lang\ClassCastException Is thrown if the passed parameter is not of type array |
|
| 49 | */ |
|
| 50 | public function __construct($items = array()) |
|
| 51 | { |
|
| 52 | // parent constructor to ensure property preset |
|
| 53 | parent::__construct(); |
|
| 54 | ||
| 55 | // check if NULL is passed, is yes, to nothing |
|
| 56 | if (is_null($items)) { |
|
| 57 | return; |
|
| 58 | } |
|
| 59 | // check if an array is passed |
|
| 60 | if (is_array($items)) { |
|
| 61 | // initialize the HashMap with the values of the passed array |
|
| 62 | foreach ($items as $key => $item) { |
|
| 63 | $this->add($key, $item); |
|
| 64 | } |
|
| 65 | return; |
|
| 66 | } |
|
| 67 | // if not a array is passed throw an exception |
|
| 68 | throw new ClassCastException('Passed object is not an array'); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * This method adds the passed object with the passed key |
|
| @@ 61-82 (lines=22) @@ | ||
| 58 | * |
|
| 59 | * @throws \AppserverIo\Lang\ClassCastException Is thrown if the parameter items is not of type array |
|
| 60 | */ |
|
| 61 | public function __construct(ComparatorInterface $comparator = null, $items = array()) |
|
| 62 | { |
|
| 63 | // parent constructor to ensure property preset |
|
| 64 | parent::__construct(); |
|
| 65 | ||
| 66 | // set the comparator |
|
| 67 | $this->comparator = $comparator; |
|
| 68 | // check if NULL is passed, is yes, to nothing |
|
| 69 | if (is_null($items)) { |
|
| 70 | return; |
|
| 71 | } |
|
| 72 | // check if an array is passed |
|
| 73 | if (is_array($items)) { |
|
| 74 | // initialize the TreeMap with the values of the passed array |
|
| 75 | foreach ($items as $key => $item) { |
|
| 76 | $this->add($key, $item); |
|
| 77 | } |
|
| 78 | return; |
|
| 79 | } |
|
| 80 | // if not a array is passed throw an exception |
|
| 81 | throw new ClassCastException('Passed object is not an array'); |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * This method adds the passed object with the passed key |
|