1<?php
2/**
3 * Noticeboard Plugin
4 *
5 * @author  Zaruba Tomas <zatomik@gmail.com>
6 */
7
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14/**
15 * ArrayList class
16 *
17 * @author Mike Lang - icurtain.co.uk
18 */
19class helper_plugin_noticeboard_ArrayList{
20  //Copyright Mike Lang - icurtain.co.uk - please retain this header and give credit if used.
21 //This is a little class I've written to make my life easier and a little more like Java
22 //for those occasions when i just can't afford Java hosting
23 //It doesnt work the same as a Java arrayList.. it's just a high level aproximation of it
24 //if you have any comments or suggestions for improving or changing this class feel free to mail me
25 //mike [at] bluemedia dot co dot uk
26
27    //ARRAY LIST CLASS STARTS COUNTING AT 0!!!!!
28    private $arrayList = array();
29    private $pointer = 0;
30
31
32    public function getPointer(){
33       return $this->pointer;
34    }
35
36    public function setPointer($p){
37       $this->pointer = $p;
38    }
39
40    public function setArrayList($array){
41        $this->arrayList = $array;
42    }
43
44    public function add($item){
45       //$this->arrayList[sizeof($this->arrayList)] = $item;
46       array_push($this->arrayList, $item);
47    }
48
49    public function addAtPos($position, $item){
50       if($position < count($this->arrayList) && $position >= 0)
51       {
52       $this->add($item);
53       $this->shift(count($this->arrayList)-1, $position);
54       }
55       else
56       {
57       throw new Exception('List out of bounds');
58       }
59    }
60
61    public function getList(){
62       return $this->arrayList;
63    }
64
65    public function hasValue(){
66       if(isset($this->arrayList[$this->pointer]))
67          {
68             return true;
69          }
70       else
71          {
72             return false;
73          }
74     }
75
76     public function hasNext(){
77       if($this->pointer <= count($this->arrayList)-1)
78          {
79             return true;
80          }
81       else
82          {
83             return false;
84          }
85     }
86
87
88    public function next(){
89       if(isset($this->arrayList[$this->pointer]))
90       {
91          //return $this->arrayList[($this->pointer++)-1] = $value;
92       $this->pointer++;
93          return($this->arrayList[$this->pointer-1]);
94       }
95       else
96       {
97          return null;
98       }
99       }
100
101
102
103
104
105    public function remove($item){
106       if(array_key_exists($item, $this->arrayList)){
107          unset($this->arrayList[$item]);
108       }
109       else
110       {
111       throw new Exception('key not found');
112       }
113    }
114
115    public function addArray($array){
116     foreach ($array as $item) {
117          $this->add($item);
118             }
119    }
120
121       public function size(){
122       return count($this->arrayList);
123    }
124
125
126
127    public function end(){
128       $this->pointer = count($this->arrayList) -1;
129    }
130
131 }
132
133?>
134